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

Feature Idea: Forward and backward versions #148

Closed
justbur opened this issue May 17, 2016 · 6 comments
Closed

Feature Idea: Forward and backward versions #148

justbur opened this issue May 17, 2016 · 6 comments

Comments

@justbur
Copy link
Contributor

justbur commented May 17, 2016

I was wondering if you thought it would be useful to create forward and backward versions of some of the avy commands. The idea would be if I see a character ahead of my cursor I can cut down on the number of possibilities by roughly half using avy-forward-char (or something like that). It seems natural since most people are used to forward and backward search.

@abo-abo
Copy link
Owner

abo-abo commented May 17, 2016

I don't fully understand. Please give a simple example.

@justbur
Copy link
Contributor Author

justbur commented May 17, 2016

In vim, f and F are find char forward and backward in a line. I'd like to have something similar for finding characters forward and backward using avy (not restricted to a line) that I can bind in evil's normal mode. I saw that you can jump to lines above and below but I didn't see anything similar for characters. Does that make sense?

@abo-abo
Copy link
Owner

abo-abo commented May 17, 2016

Does that make sense?

Sounds to me like:

(progn (avy-goto-char) (forward-char 1))

and

(progn (avy-goto-char) (forward-char -1))

I think adding the above two as commands would only confuse the users. And having them as functions doesn't really serve a purpose.

In any case, try to implement what you have in mind. I'll try to accommodate what changes in avy.el your package would need.

@justbur
Copy link
Contributor Author

justbur commented May 17, 2016

Sorry, I thought it was clear, but I don't think I explained it well and I don't know the avy code well enough right now to give code. Say that you're in a buffer like this

(progn (avy-goto-char) (forward-char 1))

and[]

(progn (avy-goto-char) (forward-char -1))

where [] is the cursor. I look at the last forward-char and want to jump to the f say. If I use a char or word function from avy both forward-chars will be highlighted and I'll have to narrow down my selection (not a big deal in this case).

What I'm trying to say is that I almost always know ahead of time where the character I want to jump to is in relation to my cursor and it would be convenient if I could communicate that to avy through the command. If it's ahead of my cursor in the buffer and there is a lot of text on my screen then attaching overlays to the possibilities behind my cursor in the buffer is wasteful in some sense, and it would be more efficient if the overlays could be restricted to text after the point. I'm pretty sure that's not what you were suggesting with those examples.

@abo-abo
Copy link
Owner

abo-abo commented May 17, 2016

OK, I understand now. It's exactly the same as avy-goto-line-below.

Here's an implementation:

(defun avy-goto-char-below (char &optional arg)
  "Jump to the currently visible CHAR.
The window scope is determined by `avy-all-windows' (ARG negates it)."
  (interactive (list (read-char "char: " t)
                     current-prefix-arg))
  (avy-with avy-goto-char
    (avy--generic-jump
     (if (= 13 char)
         "\n"
       (regexp-quote (string char)))
     arg
     avy-style
     (point)
     (window-end (selected-window) t))))

You can compare it to avy-goto-char. Copy/paste the ones you need and PR.

@justbur
Copy link
Contributor Author

justbur commented May 17, 2016

Cool thanks and sorry for the confusion.

justbur added a commit to justbur/avy that referenced this issue May 17, 2016
avy.el (avy-goto-char-2-below): Add

These are versions of avy-goto-char-2 that are restricted to matches
before or after the point in the current window.

Fixes abo-abo#148
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

2 participants