reddit / emacs
Newbie: I don't understand Avy binding instructions.
Status-Detective-783 · 2022-02-09 08:10
EDIT: Thanks for all the discussion! A lot of this just leads down a rabbit hole of information that's unnecessary for a beginner. I'm done with this question!
Just started learning emacs (macport) about 10 days ago, Avy is the first package I've installed. So I have some questions.
**FIRST QUESTION** Was there a particular reason for Oleh Krehel to suggest binding avy-goto-char to `C-:` instead of `C-;`? Since `C-;` doesn't require the shift key, that would be seem to be a preferred binding for frequent navigation. (Perhaps colon `C-;` conflicts with some other popular binding?)
**SECOND ISSUE** He suggests (from https://github.com/abo-abo/avy) possibly setting up default bindings using
> (avy-setup-default)
But that doesn't seem to work for me. `C-h b C-x o C-s avy` fails to find anything.
**THIRD ISSUE** [EDIT: ISSUE RESOLVED, THIS IS USED TO INTEGRATE AVY WITHIN AN ISEARCH.] Here's a snippet from the documentation, I don't understand this:
>(global-set-key (kbd "C-c C-j") 'avy-resume)
>
>It will bind, for example, avy-isearch to C-' in isearch-mode-map, so that you can select one of the currently visible isearch candidates using avy.
How does binding to `C-c C-j` do anything to `C-'`? And what is isearch-mode-map? That function doesn't seem to exist in my beginner level emacs. What does avy-resume do? I don't understand any of this.
**FYI** This is what I finally put into my .init.el file to get Avy to work:
;;; AVY BINDINGS https://github.com/abo-abo/avy
;; doesn't seem to work
;;(avy-setup-default)
;; not sure what this does
;;(global-set-key (kbd "C-c C-j") 'avy-resume)
;; Suggested bindings from avy github docs
(global-set-key (kbd "C-:") 'avy-goto-char)
(global-set-key (kbd "C-'") 'avy-goto-char-2)
(global-set-key (kbd "M-g f") 'avy-goto-line)
(global-set-key (kbd "M-g w") 'avy-goto-word-1)
(global-set-key (kbd "M-g e") 'avy-goto-word-0)
7890yuiop · 2022-02-09 08:53
> The latter, of course, doesn't require the shift key, so that would be preferred
My keyboard (using the US layout) has a key with `;` as the unshifted value, and `:` as the shifted value. It sounds like you have the opposite, which would explain your confusion.
> `(avy-setup-default)` ... doesn't seem to work for me. `C-h b C-x o C-s ivy` fail
You've searched for "ivy" rather than "avy"?
> What does `avy-resume` do? I don't understand that.
`C-h f avy-resume` is a little cryptic, but it appears to repeat the most recently-called avy command.
> FOURTH ISSUE This is what I finally put into my .init.el file to get Avy to work
Was that an issue?
Status-Detective-783 · 2022-02-09 15:37
Oops I had a couple typos in my post, now fixed:
>Was there a particular reason for Oleh Krehel to suggest binding avy-goto-char to `C-:` instead of `C-;`? Since `C-;` doesn't require the shift key, that would be seem to be a preferred binding for frequent navigation. (Perhaps colon `C-;` conflicts with some other popular binding?)
Secondly, typo fixed, I did in fact search for "avy", not "ivy":
> (avy-setup-default) ... doesn't seem to work for me. C-h b C-x o C-s avy fail
Third, I don't understand this:
> (global-set-key (kbd "C-c C-j") 'avy-resume)
>
> It will bind, for example, avy-isearch to C-' in isearch-mode-map, so that you can select one of the currently visible isearch candidates using avy.
How does binding to `C-c C-j` do anything to `C-'`? And what is isearch-mode-map? That function doesn't seem to exist in my beginner level emacs.
Thanks!
Tenn1518 · 2022-02-09 18:56
I think he means that avy-setup-bindings will set `C-``, not the global-set-key call.
isearch-mode-map is a keymap, not a function. `C-h v` should show it, and so should `M-x describe-keymap` if you’re on Emacs 28.
isearch-mode-map keybindings are active whenever you’re in the middle of an isearch (`C-s`/`C-r`) search.
Status-Detective-783 · 2022-02-09 19:10
Thanks!
7890yuiop · 2022-02-09 21:53
Yes, when https://github.com/abo-abo/avy#bindings says "It will bind, for example..." it's talking about the call to `avy-setup-default`. In fact, for the version of avy I'm using at least, that's the only thing it does:
(defun avy-setup-default ()
"Setup the default shortcuts."
(eval-after-load "isearch"
'(define-key isearch-mode-map (kbd "C-'") 'avy-isearch)))
7890yuiop · 2022-02-09 22:02
> Secondly, typo fixed, I did in fact search for "avy", not "ivy":
You should be seeing that `(global-set-key (kbd "C-c C-j") 'avy-resume)` binding at least, if you'd used that suggested set-up.
That aside, I guess you haven't bound any keys to any avy commands. I agree that the phrasing is a little unclear, but it's left to users to bind keys to the commands they're interested in using.
Refer to the example `global-set-key` code shown next to the description of each command. If you want to use that command, that's an example of how to bind it.
I can recommend `avy-goto-char-timer`. That's the only avy command I use, but it's very useful.
Status-Detective-783 · 2022-02-10 02:10
I see this same snippet in my avy.el. So evidently, it's not easily discoverable, but `C-h v isearch-mode-map` gives a listing which shows avy-isearch, and that function (hook?) is associated with a numerical reference which SOMEWHERE SOMEHOW resolves to `C-'` behind the scenes. It's not an end-user friendly discoverability.
Thanks again for your help. I'm just going to stop here at this rabbit hole, and get back to learning basics!
7890yuiop · 2022-02-10 03:16
Yes, the raw keymap values are for Emacs to read, not humans. https://stackoverflow.com/a/36994486 is a command you can use to see a human-readable format (if you're not using Emacs 28, which has its own command for this).
A lot of the time this information is provided just by looking at the help for a particular mode (as modes have keymaps and the mode docstrings typically (but not always) display that information).
In the specific case of `isearch-mode-map` there's an isearch keybinding to show it: `C-s C-h b`
7890yuiop · 2022-02-10 03:22
I highly recommend reading through this:
https://www.masteringemacs.org/article/mastering-key-bindings-emacs
Status-Detective-783 · 2022-02-10 05:11
It's there!
S-SPC isearch-printing-char
C-' avy-isearch
<f1> Prefix Command
[deleted] · 2022-02-10 09:22
[deleted]