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?

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.).

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

  • 1
    Thanks, but the question is about confining the avy search (e.g., avy-goto-char) to the current line or paragraph, not searching to a specific line. – Dodgie Jan 24 '18 at 19:20
  • Woops, so it is. Sorry about the confusion. – Basil Jan 24 '18 at 19:22
  • All is forgiven :) – Dodgie Jan 24 '18 at 19:23

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.