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
ivy-set-default-action #363
Comments
You can't change the default action. However, you can modify all the other ones. See this code: (defun ivy-set-actions (cmd actions)
"Set CMD extra exit points to ACTIONS."
(setq ivy--actions-list
(plist-put ivy--actions-list cmd actions))) You'll have to let-bind |
Until now I am using three kind of definitions: the action command, the interactive function and a defadvice. An example: (defun action--vlc-snapshot (x)
(call-process "vlc" nil 0 nil "--snapshot-path" (f-dir x) x))
(defun counsel-locate-with-vlc ()
(interactive)
(counsel-locate "preconfigure a pattern .mp4"))
(defadvice vlc-actions (before counsel-locate-with-vlc-before activate)
(ivy-set-actions 'counsel-locate-with-vlc
`(("i" action--vlc-snapshot "vlc with snapshotconfig")))) I'll keep using the above. But just to make sure that I am using the optimal solution here let me continue with two more questions. In order to avoid defadvice. Is that what you suggested? (defun open-with-vlc ()
(interactive)
(let ((ivy--actions-list '()))
(setq ivy--actions-list
(plist-put ivy--actions-list
'counsel-locate
`(("i" action--one-of-many "vlc with snapshotconfig"))))
(counsel-locate "preconfigure a pattern .mp4"))) I am not quite sure why this would help. Actually I just want to have to use just one keybinding to call an action instead of having to use M-o and then i. Because in this case this is the only action that I decided to use before calling counsel-locate. Should and could I assign a keybinding to the action within the ivy-buffer to skip the one-custom-action-menu? |
Since the dispatch is on (defun open-with-vlc ()
(interactive)
(let ((ivy--actions-list '()))
(ivy-set-actions 'open-with-vlc
'(("i" action--one-of-many "vlc with snapshotconfig")))
(counsel-locate "preconfigure a pattern .mp4"))) However, with the new variable, you can code like this: (defun open-with-vlc ()
(interactive)
(let* ((ivy-inhibit-action t)
(file (counsel-locate "foo")))
(open-with-vlc file))) Now, all you get from Thanks for the request, by the way, I think it resulted in a nice improvement in the interface. |
Thanks a lot that's what I have been missing. |
If I put it in a let* block the default action doesn't seem to work. Meaning after selecting a search result and hitting enter no file-buffer appears. I think this is a new issue. #371 |
You have to bind it back: (defun counsel-locate-ag ()
(interactive)
(let* ((ivy-inhibit-action t)
(file (counsel-locate ""))
(ivy-inhibit-action nil))
(counsel-ag "" (f-dir file)))) |
Ah, ok I get it, thanks. |
After using ivy-set-actions for a while some lists of actions got too long.
Now I would like to try the other way around and set the default action within a wrapper function for a call to an ivy- or a counsel-command.
What would be the best way to do that?
The text was updated successfully, but these errors were encountered: