abo-abo / avy

Jump to things in Emacs tree-style
1.73k stars 110 forks source link

avy-dispatch-alist to invoke "isearch-forward-symbol-at-point" on C-s #356

Open CDitzel opened 1 year ago

CDitzel commented 1 year ago

I bound avy-goto-char-timer to C-j. And now I want to bind "isearch-forward-symbol-at-point" to C-j C-s.

I tried to extend the list


(defun avy-highlight-symbol (pt)
(isearch-forward-symbol-at-point pt)
t)
(setf (alist-get ?\C-s avy-dispatch-alist) 'avy-highlight-symbol)

but that does not seem to work. Any ideas how to do that?

kevinfis commented 1 year ago

If you just want to set "C-s" as bind in avy, go to avy.el and to find function name: defcustom avy-dispatch-alist

You can find it's type is character: :key-type (choice (character :tag "Char") change it to string: :key-type (choice ( string :tag "Char") then eval function: defcustom` avy-dispatch-alist (by the way, this is not working with M-s, because the function:(char-to-string (car x)) of avy-show-dispatch-help only accept char type.)

I have tried with cmd: avy-action-kill-move ,it works with C-s. but for you function, it is not work, because i am not totally understand elisp ( i just know the type of alist recently), so maybe you need to reference the function of avy-action-copy in the avy.el to improve your 'avy-highlight-symbol' function, or someone familiar could help you.

kevinfis commented 1 year ago

update: after test, my previous post is bad idea, if someone want to use Meta or Ctrl key in avy-action(it might be helped to remember less key), you can refer this post:

  1. get character code, ex: (message "%s" ?\M-z) ;; 134217850

  2. redefine: avy-show-dispatch-help: (defun avy-show-dispatch-help () "Display action shortucts in echo area." (let ((len (length "avy-action-"))) (message "%s" (mapconcat (lambda (x) (format "%s: %s " (propertize ;; redefine =start= (if (or (> (car x) 4194304) (= (car x) 32)) (pcase (car x) (32 " ▆▆") (67108896 "C-▆▆") (134217847 "M-w") (134217774 "M-.") (134217850 "M-z") ) (char-to-string (car x)) ) ;; redefine =end= 'face 'aw-key-face) (substring (symbol-name (cdr x)) len))) avy-dispatch-alist " "))))

  3. redefine avy-dispatch-alist (setq avy-dispatch-alist '((?\ . avy-action-teleport) ;; SPC (?\C- . avy-action-mark) ;; C-SPC (?\M-w . avy-action-copy) (?\M-. . avy-action-yank-line) (?\M-z . avy-action-zap-to-char) (?x . avy-action-kill-move) (?X . avy-action-kill-stay) (?t . avy-action-teleport) (?y . avy-action-yank) (?Y . avy-action-yank-line) (?i . avy-action-ispell) ))