embark icon indicating copy to clipboard operation
embark copied to clipboard

Working around the absence of embark-around-action-hooks

Open DamienCassou opened this issue 2 years ago • 4 comments

embark--cd and embark--narrow-to-target have a very similar and, in my opinion, complex implementations. I think these implementations are complex because the code is trying to implement the concept of "around" in a code that is only executed before the command.

I suggest introducing an embark-around-action-hooks variable instead. This will not only simplify the implementation of the 2 functions but will also make it simpler for others to have around hooks.

I volunteer for implementing that if you want to.

DamienCassou avatar Jun 16 '22 14:06 DamienCassou

Maybe embark--confirm could be moved to the new hooks variable. This would avoid using an exception for what is normal behavior.

DamienCassou avatar Jun 16 '22 14:06 DamienCassou

I've actually been thinking about doing this for a while.

oantolin avatar Jun 16 '22 15:06 oantolin

I've just discovered I need that for my own package as well:

(cl-defun mpdel-embark-fake-selected-entities (&key target &allow-other-keys)
  (cl-labels ((fake-selected-entities
               ()
               (advice-remove 'mpdel-core-selected-entities #'fake-selected-entities)
               (list target)))
    (advice-add 'mpdel-core-selected-entities :override #'fake-selected-entities)))

(dolist (command mpdel-embark--commands)
  (setf (alist-get command embark-pre-action-hooks)
        (list #'mpdel-embark-fake-selected-entities)))

DamienCassou avatar Jul 06 '22 19:07 DamienCassou

Would you like a PR?

DamienCassou avatar Jul 23 '22 12:07 DamienCassou

Hi @DamienCassou! I wrote an around hook implementation in a separate branch called around-hooks. I'd greatly appreciate it if you could test it.

oantolin avatar Dec 09 '22 00:12 oantolin

I've switched to the new branch and will report any issue.

DamienCassou avatar Dec 09 '22 09:12 DamienCassou