3

Is there a good way to do this? Much of the time I find myself using avy-mode I only want to jump somewhere within the current paragraph or line. With stock avy, this involves entering numerous keys to select a nearby location. How is this done? Or maybe my usage of avy here is flawed, and there is a better way to use it?

Dodgie
  • 462
  • 2
  • 14

2 Answers2

5

The avy commands like avy-goto-char run avy--generic-jump underneath, and that function takes a begin/end range. Here's a proof of concept modification to avy-goto-char that runs on the paragraph:

(defun avy-goto-char-in-paragraph (char)
  "Jump to the currently visible CHAR in current paragraph."
  (interactive (list (read-char "char: " t)))
  (let (beg end)
    (save-excursion
      (forward-paragraph)
      (setq end (point))
      (backward-paragraph)
      (setq beg (point)))
    (avy-with avy-goto-char
              (avy--generic-jump
               (regexp-quote (string char))
               nil
               avy-style
               beg
               end))))

You could make a version of the commands you want by modifying how beg/end are calculated (line vs paragraph vs defun etc.).

Dodgie
  • 462
  • 2
  • 14
amitp
  • 2,451
  • 12
  • 23
0

The avy package provides the command avy-goto-line for this:

avy-goto-line is an interactive autoloaded compiled Lisp function in
‘avy.el’.

(avy-goto-line &optional ARG)

Jump to a line start in current buffer.

When ARG is 1, jump to lines currently visible, with the option
to cancel to ‘goto-line’ by entering a number.

When ARG is 4, negate the window scope determined by
‘avy-all-windows’.

Otherwise, forward to ‘goto-line’ with ARG.

See also the project's README: https://github.com/abo-abo/avy#avy-goto-line

There are also the more restricted variants avy-goto-line-above and avy-goto-line-below which only consider lines above and below the current line, respectively.

There are no paragraph-specific commands as far as I'm aware; if you think this would be a useful addition you may consider suggesting it on the project's issue tracker: https://github.com/abo-abo/avy/issues

Basil
  • 12,019
  • 43
  • 69