You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a question about using embark-around-action-hooks to run a function before running the default action. This is not an issue or bug with Embark, but I didn't see a discussions page so I'm posting here.
I often use Embark to run the default action but in a different window, for example to run bookmark-jump but then open the bookmark in another tab or split, or in a window specified by ace-window. I was previously defining custom actions for each category/embark keymap, but this doesn't work uniformly. For example, this kind of dispatch is unavailable when running org-roam-node-find, and when running Embark inside a diff in magit-status (to decide where to open the diff). Following the method listed in the wiki that uses embark-around-action-hooks, I switched to the following code instead:
;; Dummy function, will be overridden by running `embark-around-action-hooks'
(defunmy/embark-window-prefix-dummy () (interactive))
(setf (alist-get'my/embark-window-prefix-dummy embark-around-action-hooks)
'(my/embark--call-prefix-action))
(defvar-keymap my/window-prefix-map
:doc"Keymap for various window-prefix maps":suppress'nodigits"o"#'ace-window-prefix"0"#'ace-window-prefix"1"#'same-window-prefix"2"#'split-window-vertically"3"#'split-window-horizontally"4"#'other-window-prefix"5"#'other-frame-prefix"6"#'other-tab-prefix"t"#'other-tab-prefix)
;; Look up the key in `my/window-prefix-map' and call that function first.;; Then run the default embark action.
(cl-defunmy/embark--call-prefix-action (&restrest &keyruntype &allow-other-keys)
(when-let ((cmd (keymap-lookup
my/window-prefix-map
(key-description (this-command-keys-vector)))))
(funcall cmd))
(apply run :action (embark--default-action type) :type type rest))
(map-keymap (lambda (keycmd)
(keymap-set embark-general-map (key-description (make-vector1 key))
#'my/embark-window-prefix-dummy))
my/window-prefix-map)
This runs a *-window-prefix command right before calling the default action, so the display-buffer action that's the result of the default action is shown in the desired destination.
(Note: ace-window-prefix is like other-window-prefix but you can decide where you want to display the buffer just-in-time using an ace-window action, it's documented here.)
This works but has two issues:
For multi-category commands like consult-buffer, the default action is not run correctly. For example, pressing t when using embark-act with consult-buffer opens a new tab, but not the buffer/file in that tab. I'm not sure why. Single source commands all work as expected with this embark action.
It seems roundabout to have to define a dummy function (my/embark-window-prefix-dummy) and a hook that does the actual calling. Is there an easier way to define an embark action that runs some code followed by the default action? I looked into embark-pre-action-hooks but this requires about the same amount of indirection (or more, I'm not sure) to work.
The text was updated successfully, but these errors were encountered:
Hi @oantolin,
I have a question about using
embark-around-action-hooks
to run a function before running the default action. This is not an issue or bug with Embark, but I didn't see a discussions page so I'm posting here.I often use Embark to run the default action but in a different window, for example to run
bookmark-jump
but then open the bookmark in another tab or split, or in a window specified byace-window
. I was previously defining custom actions for each category/embark keymap, but this doesn't work uniformly. For example, this kind of dispatch is unavailable when runningorg-roam-node-find
, and when running Embark inside a diff inmagit-status
(to decide where to open the diff). Following the method listed in the wiki that usesembark-around-action-hooks
, I switched to the following code instead:This runs a
*-window-prefix
command right before calling the default action, so thedisplay-buffer
action that's the result of the default action is shown in the desired destination.(Note:
ace-window-prefix
is likeother-window-prefix
but you can decide where you want to display the buffer just-in-time using an ace-window action, it's documented here.)This works but has two issues:
For multi-category commands like
consult-buffer
, the default action is not run correctly. For example, pressingt
when usingembark-act
withconsult-buffer
opens a new tab, but not the buffer/file in that tab. I'm not sure why. Single source commands all work as expected with this embark action.It seems roundabout to have to define a dummy function (
my/embark-window-prefix-dummy
) and a hook that does the actual calling. Is there an easier way to define an embark action that runs some code followed by the default action? I looked intoembark-pre-action-hooks
but this requires about the same amount of indirection (or more, I'm not sure) to work.The text was updated successfully, but these errors were encountered: