branch: externals/embark
commit ba1762b7846301fec6c18bfb5ba2125db572a5db
Author: Omar Antolín Camarena <[email protected]>
Commit: Omar Antolín Camarena <[email protected]>

    Allow overriding default action per command (fix #484)
    
    Also, setup consult-find to use find-file as the default action.
---
 embark-consult.el |  5 ++++-
 embark.el         | 20 +++++++++++++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/embark-consult.el b/embark-consult.el
index 132b1f8a04..9b49bbe90c 100644
--- a/embark-consult.el
+++ b/embark-consult.el
@@ -220,7 +220,10 @@ This function is meant to be added to 
`embark-collect-mode-hook'."
 (setf (alist-get 'consult-grep embark-exporters-alist)
       #'embark-consult-export-grep)
 
-;;; Support for reverting export from consult-find
+;;; Support for consult-find
+
+(setf (alist-get '(file . consult-find) embark-default-action-overrides)
+      #'find-file)
 
 (defun embark-consult--wait-for-find ()
   (when (eq embark--command 'consult-find)
diff --git a/embark.el b/embark.el
index cd942b98c9..adb89cf232 100644
--- a/embark.el
+++ b/embark.el
@@ -378,8 +378,20 @@ completion candidates is `delete-file' itself.  You may 
prefer to
 make `find-file' the default action for all files, even if they
 wre obtained from a `delete-file' prompt.  In that case you can
 configure that by adding an entry to this variable pairing `file'
-with `find-file'."
-  :type '(alist :key-type symbol :value-type function))
+with `find-file'.
+
+In addition to target types, you can also use as keys in this
+alist, pairs of a target type and a command name.  Such a pair
+indicates that the override only applies if the target was
+obtained from minibuffer completion from that command.  For
+example adding an entry '((file . delete-file) . find-file) to
+this alist would indicate that for files at the prompt of the
+`delete-file' command, `find-file' should be used as the default
+action."
+  :type '(alist :key-type (choice (symbol :tag "Type")
+                                  (cons (symbol :tag "Type")
+                                        (symbol :tag "Command")))
+                :value-type (function :tag "Default action")))
 
 (make-obsolete-variable
    'embark-allow-edit-actions
@@ -1953,7 +1965,9 @@ For targets that do not come from minibuffer completion
 type is not listed in `embark-default-action-overrides', the
 default action is given by whatever binding RET has in the action
 keymap for the given type."
-  (or (alist-get type embark-default-action-overrides)
+  (or (alist-get (cons type embark--command) embark-default-action-overrides
+                 nil nil #'equal)
+      (alist-get type embark-default-action-overrides)
       (alist-get t embark-default-action-overrides)
       embark--command
       (lookup-key (symbol-value (or (alist-get type embark-keymap-alist)

Reply via email to