GithubHelp home page GithubHelp logo

Comments (6)

PythonNut avatar PythonNut commented on July 22, 2024

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

from avy.

abo-abo avatar abo-abo commented on July 22, 2024

Even simpler:

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

from avy.

tuhdo avatar tuhdo commented on July 22, 2024

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

from avy.

tuhdo avatar tuhdo commented on July 22, 2024

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.

from avy.

abo-abo avatar abo-abo commented on July 22, 2024

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

from avy.

tuhdo avatar tuhdo commented on July 22, 2024

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

from avy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.