abo-abo / avy

Jump to things in Emacs tree-style
1.71k stars 109 forks source link

Request: avy-goto-symbol-at-point or avy-goto-string #312

Open hmelman opened 3 years ago

hmelman commented 3 years ago

I'm finding the following useful:

(defun avy-goto-symbol-at-point (&optional arg)
  "Jump to a visible occurance of symbol-at-point.
The window scope is determined by `avy-all-windows' (ARG negates it)."
  (interactive "P")
  (let ((avy-all-windows (if arg
                             (not avy-all-windows)
                           avy-all-windows)))
    (avy-with avy-goto-symbol-at-point
      (avy-process 
       (avy--regex-candidates (regexp-quote (thing-at-point 'symbol t)))))))

While it could be used on its own, I'm using it with symbol-overlay which highlights all occurances of a symbol in a buffer and lets you navigate between them with next and previous and first and last functions. This allows jumping to a specific visible occurrence via avy which is very nice. The important point in this case is that it doesn't need user input the way avy-goto-char-timer does.

I suggested such a function to symbol-overlay but they understandably didn't want to add a dependency on avy. If avy offered such a command, another package could simply bind it to a keymap or call it if fboundp and not have a hard dependency.

I'm not sure of the best way to implement such a command. Perhaps it should be an avy-goto-string that takes the string as the argument (which would be useful when called from other packages). The default value when called interactively could be gotten from thing-at-point and enabled when using "future history" via M-n at the prompt. Here's a first approximation that doesn't deal with avy-all-windows.

(defun avy-goto-string (string)
  "Jump to a visible occurance of string."
  (interactive (list (read-from-minibuffer "String: " nil nil nil nil (thing-at-point 'symbol t))))
  (avy-with avy-goto-string
    (avy-process 
     (avy--regex-candidates (regexp-quote string)))))

I could see an avy-goto-regexp being useful too. I haven't put too much thought into it yet and wanted to know if such a thing was previously considered and rejected for some reason that isn't obvious to me.

claytonrcarter commented 1 year ago

I don't use or know about symbol-overlay, but the avy-goto-symbol-at-point function is 🔥 all by itself! Thank you!