Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to customize what to jump to with avy #55

Closed
tuhdo opened this issue May 31, 2015 · 6 comments
Closed

Allow users to customize what to jump to with avy #55

tuhdo opened this issue May 31, 2015 · 6 comments

Comments

@tuhdo
Copy link

tuhdo commented May 31, 2015

It would be useful for user to customize what to jump to. For example, a user can create an avy command to jump to all the if occurrences; similar while, for... so I can bind all of them under some prefix key like C-j and quickly jump to with a few key strokes with minimal screen disruption.

I got the idea from this issue: abo-abo/lispy#77

@PythonNut
Copy link

Would this be something that should be built into avy? You could achieve this yourself with a small snippet:

(defun avy-goto-while ()
  (interactive)
  (avy--goto
    (avy--process
      (mapcar
        (lambda (point)
          (cons (cons point point)
            (get-buffer-window)))
        (let ((points))
          (save-excursion
            (goto-char (window-start))
            (while
              (prog1
                (search-forward "while"
                  (min (point-max) (window-end))
                  t)
                ;; adjust target to beginning of match
                (push (- (point) 5) points)))
            points)))
      (avy--style-fn avy-style))))

@abo-abo
Copy link
Owner

abo-abo commented Jun 2, 2015

Even simpler:

(avy--generic-jump "while" nil 'pre)

@tuhdo
Copy link
Author

tuhdo commented Jun 3, 2015

@abo-abo Great to know that it's just that simple. Maybe you could provide a macro that wraps around avy--generic-jump: a user can use this macro to define his jump command to a particular regexp. For example, let's name this macro avy-def-jump. A user can use it like this:

(defvar avy-while-object '("while " nil 'pre))
(avy-def-jump global-map (kbd "C-j w") 'avy-while-object)

Then it generates appropriate binding for a particular keymap.

@tuhdo
Copy link
Author

tuhdo commented Jun 3, 2015

It's great that avy already accepts regexp. Now I can jump to any conditional sexp in Lisp with this simple snippet:

(avy--generic-jump "(if\\|(cond\\|(when\\|(unless" nil 'pre)

So now instead of thinking about jump to a character, I can think about jump to semantic units on screen!

I think this is a great feature that should be mentioned on avy homepage. Now we only need a macro for ease customization.

@abo-abo
Copy link
Owner

abo-abo commented Jun 3, 2015

Now we only need a macro for ease customization.

A macro unnecessarily restricts the things you can do:

  • naming
  • documenting
  • advising
  • re-using
  • calling by name

It's only worth it if the abstraction power is high, which it isn't in this case. This is much better in my opinion, and not much longer:

(global-set-key
 (kbd "C-j w")
 (defun avy-goto-while ()
   (interactive)
   (avy--generic-jump "while " nil 'pre)))

@tuhdo
Copy link
Author

tuhdo commented Jun 3, 2015

But then, new users will have to write boilerplate code like that. I am assuming avy users are non-Elisp programmers as well.

But that's look fine to me. I think this could be turned into a feature, and provide a few built-in commands for popular major modes i.e. C/C++, Python, Lisp

@abo-abo abo-abo closed this as completed in 6dfa445 Jun 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants