reddit / emacs

invoking a function from within avy

RepublicWorried · 2022-11-08 18:34
I have bound "avy-goto-char-timer" to C-j globally. But I want the key chord C-j C-s to invoke "isearch-forward-symbol-at-point" is that possible ?
CorysInTheHouse69 · 2022-11-08 20:21
Yes. You would need to add a `C-s` binding in the `avy-mode-map` bound to `isearch-forward-symbol`. (This is actually a good idea, I might steal this ;) )
RepublicWorried · 2022-11-08 20:40
had the same idea, but there is no avy-mode-map
CorysInTheHouse69 · 2022-11-08 21:41
Ahh i see. I believe you’d have to do something like this instead. `(setf (alist-get ?\C-s avy-dispatch-alist) 'isearch-forward-symbol)` You may need to write a function that cancels avy and calls isearch-forward-symbol if this doesn’t work and call that instead
AndreaSomePostfix · 2022-11-08 22:44
maybe relevant an amazing post on how to extend avy actions: [https://karthinks.com/software/avy-can-do-anything/](https://karthinks.com/software/avy-can-do-anything/). And one of mines that build over that idea to make actions repeatable: https://ag91.github.io/blog/2022/04/20/repeat-with-me-avy-actions-are-awesome/
RepublicWorried · 2022-11-09 06:32
thanks guys, but says here ​ Symbol’s value as variable is void: avy-dispatch-alistInvalid face reference: some-other-face
AndreaSomePostfix · 2022-11-09 13:39
what code did you load? some-other-face probably should be an existing face symbol in your Emacs context
RepublicWorried · 2022-11-10 04:37
sorry that was an unrelated issue. But nonetheless, those other avy commands (visible when pressing ? upon invoking avy) never have worked for me. am I missing something?
AndreaSomePostfix · 2022-11-10 14:19
the process is you type the start of your candidate, you see the overlayed red letters, then you can press ? to see what commands you have and/or you can just type the letter corresponding to the command, finally you type the red letter to apply the command to the position. It is a bit weird at the begin because you have to remember to "load" the command after you insert an hint for candidates but before you select the candidate. Note that you cannot apply the command if you specify a hint long enough to match a single candidate (because you don't see the red overlayed letters at that point)
oantolin · 2022-11-10 22:32
> Note that you cannot apply the command if you specify a hint long enough to match a single candidate (because you don't see the red overlayed letters at that point) The variable `avy-single-candidate-jump` controls this behavior, if you set it to nil then you get the red letters even for a single candidate. I keep going back and forth about which behavior I prefer.
AndreaSomePostfix · 2022-11-10 23:15
ooh! Thank you, I didn't know that. Maybe I could advice that function so that if I invoke avy-goto-char-timer with an universal arg, it sets temporarily avy-single-candidate-jump... Thanks anyway!
RepublicWorried · 2022-11-16 17:57
that never works for me. After getting the letter highlights, I am pressing ? and then e.g. X for delete, but nothing happens. I am using vanilla emacs with only avy
AndreaSomePostfix · 2022-11-16 19:26
Strange, X should delete the word at point. What about pressing K ? (Pressing "?" is not needed unless you want a reminder of the actions available)
RepublicWorried · 2022-11-16 20:27
ok I got it now. Did you guys really incorporate this into your workflow?
RepublicWorried · 2022-11-16 20:32
>(setf (alist-get ?\\C-s avy-dispatch-alist) 'isearch-forward-symbol) would you help me to do that please? so far I have a halfworking solution which still requires me to type in highligted letters to start isearch-forward-symbol-at-point (defun avy-highlight-symbol (pt) (isearch-forward-symbol-at-point pt) t) (setf (alist-get ?\C-s avy-dispatch-alist) 'avy-highlight-symbol)
AndreaSomePostfix · 2022-11-17 09:13
yup, I also modified them to be able to repeat an action: [https://ag91.github.io/blog/2022/04/20/repeat-with-me-avy-actions-are-awesome/](https://ag91.github.io/blog/2022/04/20/repeat-with-me-avy-actions-are-awesome/) For example, when I have to mark a bunch of task as DONE in my agenda, I can set the action and just type the shortcuts to mark them DONE.
RepublicWorried · 2022-11-17 10:13
you seem to be sort of an expert in lisp whereas I am not. ​ Would you mind helping me with the small function I tried to come up with above?
AndreaSomePostfix · 2022-11-17 17:13
can you try ?S instead of ?\\C-s and see if it works with that. The question mark is used for representing characters as far as I know and I am not sure if it works with keybinding combinations
RepublicWorried · 2022-11-17 20:21
thats not the reason. I think I need to modify the function itself