branch: externals/embark
commit fbdad2c469b3a2afdde26daf732f51e0fcd707a4
Author: Paul Nelson <[email protected]>
Commit: Paul Nelson <[email protected]>

    Add option to record Embark targets in minibuffer history
    
    Addresses #712.
    
    * embark.el (embark-record-minibuffer-history): New user option to
    control when acted-on minibuffer candidates are recorded in the
    minibuffer history.  Defaults to skipping certain actions, such as
    export, collect, and become.
    (embark--record-history-p, embark--record-target-in-history): New
    helper functions.
    (embark--act): Use them to record target in history.
    
    * README.org (Advanced configuration):
    * embark.texi (Advanced configuration): Document the new option.
---
 CHANGELOG.org |  4 ++++
 README.org    | 10 ++++++++++
 embark.el     | 35 +++++++++++++++++++++++++++++++++++
 embark.texi   | 15 ++++++++++++++-
 4 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index dac0d45334..45a963666a 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -1,6 +1,10 @@
 #+title: Embark changelog
 
 * Development
+- Acted-on minibuffer candidates now get recorded in the minibuffer
+  history.  You can configure which actions record history via the new
+  =embark-record-minibuffer-history= option; by default, we skip meta
+  commands such as =embark-export=, =embark-collect= and =embark-become=.
 - =embark-target-buffer-at-point=: New target finder for buffers at point in
   Ibuffer or Buffer-menu.
 - =embark-context-menu=: Bew function which can be added to
diff --git a/README.org b/README.org
index cece0f3c6c..57344dce39 100644
--- a/README.org
+++ b/README.org
@@ -617,6 +617,16 @@ non-quitting version as follows:
       (embark-act)))
 #+end_src
 
+** Recording acted-on minibuffer candidates in minibuffer history
+
+Confirming minibuffer input with =RET= records the selected candidate in
+the appropriate history list.  The user option
+=embark-record-minibuffer-history= controls how Embark records acted-on
+candidates.  This option accepts three kinds of values: =t= (always
+record), =nil= (never record), or =(skip ACTIONS...)= to record for
+everything except the listed actions.  The default is a =skip= form that
+excludes meta commands such as =embark-export=.
+
 ** Running some setup after injecting the target
 
 You can customize what happens after the target is inserted at the
diff --git a/embark.el b/embark.el
index c27bbe6844..e41e865d36 100644
--- a/embark.el
+++ b/embark.el
@@ -314,6 +314,21 @@ some uses of `embark-act-all', namely, for those actions 
whose
 entry in `embark-pre-action-hooks' includes `embark--confirm'."
   :type 'boolean)
 
+(defcustom embark-record-minibuffer-history
+  '(skip embark-export embark-collect embark-live embark-become
+         embark-act-all embark-toggle-quit)
+  "Control when acted-on minibuffer candidates go into history.
+The value takes one of the following forms:
+
+  t                  Record for every action.
+  nil                Never record.
+  (skip ACTIONS...)  Record for every action not in ACTIONS."
+  :type '(choice (const :tag "Record for all actions" t)
+                 (const :tag "Never record" nil)
+                 (cons :tag "Record except for listed actions"
+                       (const skip)
+                       (repeat (function :tag "Action to skip")))))
+
 (defcustom embark-default-action-overrides nil
   "Alist associating target types with overriding default actions.
 When the source of a target is minibuffer completion, the default
@@ -2070,10 +2085,30 @@ target as argument."
         (command-execute (plist-get args :action)))))
    :action action :quit quit target))
 
+(defun embark--record-history-p (action)
+  "Return non-nil if ACTION should push the current target to history."
+  (pcase embark-record-minibuffer-history
+    ('t t)
+    ('nil nil)
+    (`(skip . ,actions) (not (memq action actions)))
+    (_ nil)))
+
+(defun embark--record-target-in-history (action target)
+  "Record TARGET for ACTION in the current minibuffer history."
+  (when (and (minibufferp)
+             (embark--record-history-p action)
+             (not (eq minibuffer-history-variable t)))
+    (let ((raw (plist-get target :target)))
+      (when (stringp raw)
+        (add-to-history
+         minibuffer-history-variable
+         (substring-no-properties raw))))))
+
 (defun embark--act (action target &optional quit)
   "Perform ACTION injecting the TARGET.
 If called from a minibuffer with non-nil QUIT, quit the
 minibuffer before executing the action."
+  (embark--record-target-in-history action target)
   (if (memq action '(embark-become       ; these actions should run in
                      embark-collect      ; the current buffer, not the
                      embark-live         ; target buffer
diff --git a/embark.texi b/embark.texi
index e970e77ee0..f018050c95 100644
--- a/embark.texi
+++ b/embark.texi
@@ -55,6 +55,7 @@ Advanced configuration
 * Showing information about available targets and actions::
 * Selecting commands via completions instead of key bindings::
 * Quitting the minibuffer after an action::
+* Recording acted-on minibuffer candidates in minibuffer history::
 * Running some setup after injecting the target::
 * Running hooks before, after or around an action: Running hooks before after 
or around an action. 
 * Creating your own keymaps::
@@ -501,7 +502,7 @@ starting configuration:
   ;; (setq eldoc-documentation-strategy #'eldoc-documentation-compose-eagerly)
 
   ;; Add Embark to the mouse context menu. Also enable `context-menu-mode'.
-  ;; (context-menu 1)
+  ;; (context-menu-mode 1)
   ;; (add-hook 'context-menu-functions #'embark-context-menu 100)
 
   :config
@@ -575,6 +576,7 @@ integration despite this.)
 * Showing information about available targets and actions::
 * Selecting commands via completions instead of key bindings::
 * Quitting the minibuffer after an action::
+* Recording acted-on minibuffer candidates in minibuffer history::
 * Running some setup after injecting the target::
 * Running hooks before, after or around an action: Running hooks before after 
or around an action. 
 * Creating your own keymaps::
@@ -779,6 +781,17 @@ non-quitting version as follows:
     (embark-act)))
 @end lisp
 
+@node Recording acted-on minibuffer candidates in minibuffer history
+@section Recording acted-on minibuffer candidates in minibuffer history
+
+Confirming minibuffer input with @samp{RET} records the selected candidate in
+the appropriate history list.  The user option
+@samp{embark-record-minibuffer-history} controls how Embark records acted-on
+candidates.  This option accepts three kinds of values: @samp{t} (always
+record), @samp{nil} (never record), or @samp{(skip ACTIONS...)} to record for
+everything except the listed actions.  The default is a @samp{skip} form that
+excludes meta commands such as @samp{embark-export}.
+
 @node Running some setup after injecting the target
 @section Running some setup after injecting the target
 

Reply via email to