emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/embark ee014d5f3c 3/3: Merge pull request #574 from oan


From: ELPA Syncer
Subject: [elpa] externals/embark ee014d5f3c 3/3: Merge pull request #574 from oantolin/around-hooks
Date: Sat, 24 Dec 2022 12:57:37 -0500 (EST)

branch: externals/embark
commit ee014d5f3c86eafae673a947b492fa03ffbacb4e
Merge: 589b057d00 5655c1415f
Author: Omar AntolĂ­n Camarena <omar.antolin@gmail.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #574 from oantolin/around-hooks
    
    Around hooks
---
 README.org        |  67 +++++++++++----------
 embark-consult.el |   2 +-
 embark.el         | 174 +++++++++++++++++++++++++++++++++++-------------------
 embark.texi       | 113 +++++++++++++++++++----------------
 4 files changed, 214 insertions(+), 142 deletions(-)

diff --git a/README.org b/README.org
index 8a94f9db97..e22c489b9b 100644
--- a/README.org
+++ b/README.org
@@ -545,21 +545,22 @@ for region targets, and it prompts you for a shell 
command; you
 typically do /not/ want the target, that is the contents of the region,
 to be entered at that prompt!
 
-** Running hooks before or after an action
+** Running hooks before, after or around an action
 
-Embark has two variables, =embark-pre-action-hooks= and
-=embark-post-action-hooks=, which are alists associating commands to
-hooks that should run before or after the command is used as an
-action. As with, =embark-target-injection-hooks=, there are two special keys
-for the alists: =t= designates the default hook to run when no specific
-hook is specified for a command; and the hook associated to =:always=
-runs regardless.
+Embark has three variables, =embark-pre-action-hooks=,
+=embark-post-action-hooks= and =embark-around-action-hooks=, which are
+alists associating commands to hooks that should run before or after
+or as around advice for the command when used as an action. As with
+=embark-target-injection-hooks=, there are two special keys for the
+alists: =t= designates the default hook to run when no specific hook is
+specified for a command; and the hook associated to =:always= runs
+regardless.
 
 The default values of those variables are fairly extensive, adding
 creature comforts to make running actions a smooth experience. Embark
 comes with several functions intended to be added to these hooks, and
-used in the default values of =embark-pre-action-hooks= and
-=embark-post-action-hooks=.
+used in the default values of =embark-pre-action-hooks=,
+=embark-post-action-hooks= and =embark-around-action-hooks=.
 
 For pre-action hooks:
 
@@ -568,16 +569,6 @@ For pre-action hooks:
   or, more accurately, hard to undo, such as =delete-file= and
   =kill-buffer=.
 
-- =embark--mark-target= :: Mark the target as an active region. Most
-  targets at point outside the minibuffer report which region of the
-  buffer they correspond to (this is the information used by
-  =embark-highlight-indicator= to know what portion of the buffer to
-  highlight); this function marks that region. It is useful as a pre
-  action hook for commands that expect a region to be marked, for
-  example, it is used by default for =indent-region= so that it works on
-  s-expression targets, or for =fill-region= so that it works on
-  paragraph targets.
-
 - =embark--unmark-target= :: Unmark the active region. Use this for
   commands you want to act on the region contents but without the
   region being active. The default configuration uses this function as
@@ -600,21 +591,11 @@ For pre-action hooks:
   on an s-expression from anywhere inside it and still use
   =eval-last-sexp= as an action.
 
-- =embark--narrow-to-target= :: Narrow buffer to current target. Use
-  this as a pre-action hook to localize the effect of actions that
-  don't already work on just the region. In the default configuration
-  it is used for =repunctuate-sentences=.
-
 - =embark--xref-push-markers= :: Push the current location on the xref
   marker stack. Use this for commands that take you somewhere and for
   which you'd like to be able to come back to where you were using
   =xref-pop-marker-stack=. This is used by default for =find-library=.
 
-- =embark--cd= :: Run the action with =default-directory= set to the
-  directory associated to the current target. The target should be of
-  type =file=, =buffer=, =bookmark= or =library=, and the associated directory
-  is what you'd expect in each case.
-
 For post-action hooks:
 
 - =embark--restart= :: Restart the command currently prompting in the
@@ -624,6 +605,32 @@ For post-action hooks:
   =embark-post-action-hooks= uses it for =delete-file=, =kill-buffer=,
   =rename-file=, =rename-buffer=, etc.
 
+For around-action hooks:
+
+- =embark--mark-target= :: Save existing mark and point location, mark
+  the target and run the action. Most targets at point outside the
+  minibuffer report which region of the buffer they correspond to
+  (this is the information used by =embark-highlight-indicator= to
+  know what portion of the buffer to highlight); this function marks
+  that region. It is useful as an around action hook for commands that
+  expect a region to be marked, for example, it is used by default for
+  =indent-region= so that it works on s-expression targets, or for
+  =fill-region= so that it works on paragraph targets.
+
+- =embark--cd= :: Run the action with =default-directory= set to the
+  directory associated to the current target. The target should be of
+  type =file=, =buffer=, =bookmark= or =library=, and the associated directory
+  is what you'd expect in each case.
+
+- =embark--narrow-to-target= :: Run the action with buffer narrowed to
+  current target. Use this as an around hook to localize the effect of
+  actions that don't already work on just the region. In the default
+  configuration it is used for =repunctuate-sentences=.
+
+- =embark--save-excursion= :: Run the action restoring point at the end.
+  The current default configuration doesn't use this but it is
+  available for users.
+
 ** Creating your own keymaps
 
 All internal keymaps are defined with a helper macro
diff --git a/embark-consult.el b/embark-consult.el
index b53192425a..38d71bd7bf 100644
--- a/embark-consult.el
+++ b/embark-consult.el
@@ -359,7 +359,7 @@ for any action that is a Consult async command."
 
 (map-keymap
  (lambda (_key cmd)
-   (cl-pushnew #'embark--cd (alist-get cmd embark-pre-action-hooks))
+   (cl-pushnew #'embark--cd (alist-get cmd embark-around-action-hooks))
    (cl-pushnew #'embark-consult--prep-async
                (alist-get cmd embark-target-injection-hooks)))
  embark-consult-async-search-map)
diff --git a/embark.el b/embark.el
index 3cdf157366..09b1ff6eb4 100644
--- a/embark.el
+++ b/embark.el
@@ -88,7 +88,7 @@
 ;; on candidate sets:
 
 ;; - The `embark-act-all' command runs the same action on each of the
-;;   current candidates. It is just like using `embark-act' on each
+;;   current candidates.  It is just like using `embark-act' on each
 ;;   candidate in turn.
 
 ;; - The `embark-collect' command produces a buffer listing all
@@ -305,9 +305,9 @@ configure that by adding an entry to this variable pairing 
`file'
 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
+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
+completion from that command.  For example adding an
 entry (cons (cons \\='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."
@@ -340,9 +340,9 @@ indicate that for files at the prompt of the `delete-file' 
command,
 For commands appearing as keys in this alist, run the
 corresponding value as a setup hook after injecting the target
 into in the minibuffer and before acting on it.  The hooks must
-accept arbitrary keyword argument. The :action symbol, the
+accept arbitrary keyword arguments.  The :action command, the
 :target string and target :type are always present.  For actions
-at point the target bounds are passed too.  The default pre-action
+at point the target :bounds are passed too.  The default pre-action
 hook is specified by the entry with key t.  Furthermore, hooks with
 the key :always are executed always."
   :type '(alist :key-type
@@ -369,25 +369,6 @@ the key :always are executed always."
     (forward-sentence embark--end-of-target)
     (backward-sentence embark--beginning-of-target)
     (backward-paragraph embark--beginning-of-target)
-    ;; region commands
-    (mark embark--mark-target)
-    (kill-region embark--mark-target)
-    (kill-ring-save embark--mark-target)
-    (indent-region embark--mark-target)
-    (ispell-region embark--mark-target)
-    (fill-region embark--mark-target)
-    (upcase-region embark--mark-target)
-    (downcase-region embark--mark-target)
-    (capitalize-region embark--mark-target)
-    (count-words-region embark--mark-target)
-    (shell-command-on-region embark--mark-target)
-    (delete-region embark--mark-target)
-    (format-encode-region embark--mark-target)
-    (format-decode-region embark--mark-target)
-    (write-region embark--mark-target)
-    (append-to-file embark--mark-target)
-    (shell-command-on-region embark--mark-target)
-    (embark-eval-replace embark--mark-target)
     ;; commands we want to be able to jump back from
     ;; (embark-find-definition achieves this by calling
     ;; xref-find-definitions which pushes the markers itself)
@@ -405,11 +386,11 @@ the key :always are executed always."
     (occur embark--unmark-target)
     (query-replace embark--beginning-of-target embark--unmark-target)
     (query-replace-regexp embark--beginning-of-target embark--unmark-target)
-    ;; narrow to target for duration of action
-    (repunctuate-sentences embark--narrow-to-target)
-    ;; use directory of target as default-directory
-    (shell embark--cd embark--universal-argument)
-    (eshell embark--cd embark--universal-argument))
+    ;; mark pseudo-action
+    (mark embark--mark-target)
+    ;; shells in new buffers
+    (shell embark--universal-argument)
+    (eshell embark--universal-argument))
   "Alist associating commands with pre-action hooks.
 The hooks are run right before an action is embarked upon.  See
 `embark-target-injection-hooks' for information about the hook
@@ -446,6 +427,46 @@ arguments and more details."
                         (const :tag "Always" :always))
                 :value-type hook))
 
+(defcustom embark-around-action-hooks
+  '(;; use directory of target as default-directory
+    (shell embark--cd)
+    (eshell embark--cd)
+    ;; narrow to target for duration of action
+    (repunctuate-sentences embark--narrow-to-target)
+    ;; mark the target preserving point and previous mark
+    (kill-region embark--mark-target)
+    (kill-ring-save embark--mark-target)
+    (indent-region embark--mark-target)
+    (ispell-region embark--mark-target)
+    (fill-region embark--mark-target)
+    (upcase-region embark--mark-target)
+    (downcase-region embark--mark-target)
+    (capitalize-region embark--mark-target)
+    (count-words-region embark--mark-target)
+    (count-words embark--mark-target)
+    (shell-command-on-region embark--mark-target)
+    (delete-region embark--mark-target)
+    (format-encode-region embark--mark-target)
+    (format-decode-region embark--mark-target)
+    (write-region embark--mark-target)
+    (append-to-file embark--mark-target)
+    (shell-command-on-region embark--mark-target)
+    (embark-eval-replace embark--mark-target))
+  "Alist associating commands with post-action hooks.
+The hooks are run instead of the embarked upon action.  The hook
+can decide whethether or not to run the action or it can run it
+in some special environment, like inside a let-binding or inside
+`save-excursion'.  Each hook is called with keyword argument :run
+providing a function encapsulating the following around hooks and
+the action; the hook additionally recieves the keyword arguments
+used for other types of action hooks, for more details see
+`embark-target-injection-hooks'."
+  :type '(alist :key-type
+                (choice symbol
+                        (const :tag "Default" t)
+                        (const :tag "Always" :always))
+                :value-type hook))
+
 (defcustom embark-multitarget-actions '(embark-insert embark-copy-as-kill)
   "Commands for which `embark-act-all' should pass a list of targets.
 Normally `embark-act-all' runs the same action on each candiate
@@ -1786,6 +1807,27 @@ arguments are passed to the hooks as keyword arguments."
   (mapc (lambda (h) (apply h :action action :quit quit target))
         (alist-get :always hooks)))
 
+(defun embark--run-around-action-hooks (action target quit)
+  "Run the `embark-around-action-hooks' for ACTION.
+All the applicable around hooks are composed in the order they
+are present in `embark-around-action-hooks'.  The keys t and
+:always in `embark-around-action-hooks' are treated specially.
+The :always hooks are executed always (outermost) and the t hooks
+are the default hooks, for when there are no command-specific
+hooks for ACTION.  The QUIT, ACTION and TARGET arguments are
+passed to the hooks as keyword arguments."
+  (apply
+   (seq-reduce
+    (lambda (fn hook)
+      (lambda (&rest args) (apply hook (plist-put args :run fn))))
+    (let ((hooks embark-around-action-hooks))
+      (reverse
+       (append (or (alist-get action hooks) (alist-get t hooks))
+               (alist-get :always hooks))))
+    (lambda (&rest args)
+      (command-execute (plist-get args :action))))
+   :action action :quit quit target))
+
 (defun embark--act (action target &optional quit)
   "Perform ACTION injecting the TARGET.
 If called from a minibuffer with non-nil QUIT, quit the
@@ -1797,7 +1839,7 @@ minibuffer before executing the action."
                      embark-act-all))
       (progn
         (embark--run-action-hooks embark-pre-action-hooks action target quit)
-        (unwind-protect (command-execute action)
+        (unwind-protect (embark--run-around-action-hooks action target quit)
           (embark--run-action-hooks embark-post-action-hooks
                                     action target quit)))
     (let* ((command embark--command)
@@ -1847,7 +1889,8 @@ minibuffer before executing the action."
                                      (string last-command-event)
                                    (kbd "RET"))))
                               (setq this-command action)
-                              (command-execute action)))
+                              (embark--run-around-action-hooks
+                               action target quit)))
                           (setq final-window (selected-window)))
                       (embark--run-action-hooks embark-post-action-hooks
                                                 action target quit)
@@ -2772,7 +2815,7 @@ Chosen to be extremely unlikely to appear in a 
candidate.")
   "List of candidates to be acted on.
 The command `embark-act' is bound `embark-collect-mode-map', but
 you might prefer to change the key binding to match your other
-key binding for it. Or alternatively you might want to enable the
+key binding for it.  Or alternatively you might want to enable the
 embark collect direct action minor mode by adding the function
 `embark-collect-direct-action-minor-mode' to
 `embark-collect-mode-hook'.
@@ -3108,7 +3151,7 @@ The parameter KIND should be either `embark-export' or 
`embark-collect'."
   (interactive)
   (if embark--rerun-function
       (funcall embark--rerun-function)
-    (user-error "No function to rerun collect or export found.")))
+    (user-error "No function to rerun collect or export found.?")))
 
 ;;;###autoload
 (defun embark-export ()
@@ -3477,7 +3520,7 @@ When called with a prefix argument OTHER-WINDOW, open 
Dired in other window."
 
 (defun embark--read-from-history (prompt candidates &optional category)
   "Read with completion from list of history CANDIDATES of CATEGORY.
-Sorting and history are disabled. PROMPT is the prompt message."
+Sorting and history are disabled.  PROMPT is the prompt message."
   (completing-read prompt
                    (embark--with-category category candidates)
                    nil t nil t))
@@ -3825,30 +3868,36 @@ and leaves the point to the left of it."
   (when bounds
     (goto-char (cdr bounds))))
 
-(cl-defun embark--mark-target (&key bounds &allow-other-keys)
-  "Mark the target if its BOUNDS are known."
-  (when bounds
+(cl-defun embark--mark-target (&rest rest &key run bounds &allow-other-keys)
+  "Mark the target if its BOUNDS are known.
+After marking the target, this calls RUN with the REST of its arguments."
+  (cond
+   ((and bounds run)
+    (save-mark-and-excursion
+      (set-mark (cdr bounds))
+      (goto-char (car bounds))
+      (apply run :bounds bounds rest)))
+   (bounds ;; used as pre- or post-action hook
     (set-mark (cdr bounds))
-    (goto-char (car bounds))))
+    (goto-char (car bounds)))
+   (run (apply run rest))))
 
 (cl-defun embark--unmark-target (&rest _)
   "Deactivate the region target."
   (deactivate-mark t))
 
-(cl-defun embark--narrow-to-target (&key action bounds &allow-other-keys)
+(cl-defun embark--narrow-to-target (&rest rest &key run bounds 
&allow-other-keys)
   "Narrow buffer to target if its BOUNDS are known.
-Intended for use as an Embark pre-action hook.  This function
-advises ACTION to narrow to the given BOUNDS prior to running.
-The advice is self-removing so it only affects ACTION once."
-  (when (and (consp bounds) (symbolp action))
-    (cl-labels ((with-restriction (fn &rest args)
-                  (save-excursion
-                    (save-restriction
-                      (narrow-to-region (car bounds) (cdr bounds))
-                      (goto-char (car bounds))
-                      (unwind-protect (apply fn args)
-                        (advice-remove action #'with-restriction))))))
-      (advice-add action :around #'with-restriction))))
+Intended for use as an Embark around-action hook.  This function
+runs RUN with the buffer narrowed to given BOUNDS passing along
+the REST of the arguments."
+  (if bounds
+    (save-excursion
+      (save-restriction
+        (narrow-to-region (car bounds) (cdr bounds))
+        (goto-char (car bounds))
+        (apply run :bounds bounds rest)))
+    (apply run rest)))
 
 (defun embark--allow-edit (&rest _)
   "Allow editing the target."
@@ -3888,17 +3937,20 @@ library, which have an obvious notion of associated 
directory."
      (file-name-directory (locate-library target)))))
 
 (autoload 'bookmark-location "bookmark")
-(cl-defun embark--cd (&key action target type &allow-other-keys)
-  "Run ACTION with `default-directory' set to the directory of TARGET.
+(cl-defun embark--cd (&rest rest &key run target type &allow-other-keys)
+  "Run action with `default-directory' set to the directory of TARGET.
 The supported values of TYPE are file, buffer, bookmark and
-library, which have an obvious notion of associated directory."
-  (when-let (((symbolp action))
-             (directory (embark--associated-directory target type)))
-    (cl-labels ((in-directory (fn &rest args)
-                  (advice-remove action #'in-directory)
-                  (let ((default-directory directory))
-                    (apply fn args))))
-      (advice-add action :around #'in-directory))))
+library, which have an obvious notion of associated directory.
+The REST of the arguments are also passed to RUN."
+  (let ((default-directory
+          (or (embark--associated-directory target type) default-directory)))
+    (apply run :target target :type type rest)))
+
+(cl-defun embark--save-excursion (&rest rest &key run &allow-other-keys)
+  "Run action without moving point.
+This simply calls RUN with the REST of its arguments inside
+`save-excursion'."
+  (save-excursion (apply run rest)))
 
 (defun embark--universal-argument (&rest _)
   "Run action with a universal prefix argument."
diff --git a/embark.texi b/embark.texi
index 780969bb0e..5d355139bf 100644
--- a/embark.texi
+++ b/embark.texi
@@ -54,7 +54,7 @@ Advanced configuration
 * Selecting commands via completions instead of key bindings::
 * Quitting the minibuffer after an action::
 * Running some setup after injecting the target::
-* Running hooks before or after an action::
+* Running hooks before, after or around an action: Running hooks before after 
or around an action. 
 * Creating your own keymaps::
 * Defining actions for new categories of targets::
 
@@ -312,14 +312,14 @@ and are bound to @samp{A}, @samp{S} (for ``snapshot''), 
and @samp{E}, respective
 key bindings for these (although you can, of course!), just a key
 binding for @samp{embark-act}.
 
-Reverting an Embark Collect or Embark Export buffer has slightly
-unusual behavior if the buffer was obtained by running @samp{embark-collect}
-or @samp{embark-export} from within a minibuffer completion session. In that
-case reverting just restarts the completion session, that is, the
-command that opened the minibuffer is run again and the minibuffer
-contents restored. You can then interact normally with the command,
-perhaps editing the minibuffer contents, and, if you wish, you can
-rerun @samp{embark-collect} or @samp{embark-export} to get an updated buffer.
+In Embark Collect or Embark Export buffers that were obtained by
+running @samp{embark-collect} or @samp{embark-export} from within a minibuffer
+completion session, @samp{g} is bound to a command that restarts the
+completion session, that is, the command that opened the minibuffer is
+run again and the minibuffer contents restored. You can then interact
+normally with the command, perhaps editing the minibuffer contents,
+and, if you wish, you can rerun @samp{embark-collect} or @samp{embark-export} 
to get
+an updated buffer.
 
 @menu
 * @samp{embark-live} a live-updating variant of @samp{embark-collect}::
@@ -489,7 +489,7 @@ integration despite this.)
 * Selecting commands via completions instead of key bindings::
 * Quitting the minibuffer after an action::
 * Running some setup after injecting the target::
-* Running hooks before or after an action::
+* Running hooks before, after or around an action: Running hooks before after 
or around an action. 
 * Creating your own keymaps::
 * Defining actions for new categories of targets::
 @end menu
@@ -684,22 +684,23 @@ for region targets, and it prompts you for a shell 
command; you
 typically do @emph{not} want the target, that is the contents of the region,
 to be entered at that prompt!
 
-@node Running hooks before or after an action
-@section Running hooks before or after an action
+@node Running hooks before after or around an action
+@section Running hooks before, after or around an action
 
-Embark has two variables, @samp{embark-pre-action-hooks} and
-@samp{embark-post-action-hooks}, which are alists associating commands to
-hooks that should run before or after the command is used as an
-action. As with, @samp{embark-target-injection-hooks}, there are two special 
keys
-for the alists: @samp{t} designates the default hook to run when no specific
-hook is specified for a command; and the hook associated to @samp{:always}
-runs regardless.
+Embark has three variables, @samp{embark-pre-action-hooks},
+@samp{embark-post-action-hooks} and @samp{embark-around-action-hooks}, which 
are
+alists associating commands to hooks that should run before or after
+or as around advice for the command when used as an action. As with
+@samp{embark-target-injection-hooks}, there are two special keys for the
+alists: @samp{t} designates the default hook to run when no specific hook is
+specified for a command; and the hook associated to @samp{:always} runs
+regardless.
 
 The default values of those variables are fairly extensive, adding
 creature comforts to make running actions a smooth experience. Embark
 comes with several functions intended to be added to these hooks, and
-used in the default values of @samp{embark-pre-action-hooks} and
-@samp{embark-post-action-hooks}.
+used in the default values of @samp{embark-pre-action-hooks},
+@samp{embark-post-action-hooks} and @samp{embark-around-action-hooks}.
 
 For pre-action hooks:
 
@@ -710,17 +711,6 @@ the action. This is used be default for commands deemed 
``dangerous'',
 or, more accurately, hard to undo, such as @samp{delete-file} and
 @samp{kill-buffer}.
 
-@item @samp{embark--mark-target}
-Mark the target as an active region. Most
-targets at point outside the minibuffer report which region of the
-buffer they correspond to (this is the information used by
-@samp{embark-highlight-indicator} to know what portion of the buffer to
-highlight); this function marks that region. It is useful as a pre
-action hook for commands that expect a region to be marked, for
-example, it is used by default for @samp{indent-region} so that it works on
-s-expression targets, or for @samp{fill-region} so that it works on
-paragraph targets.
-
 @item @samp{embark--unmark-target}
 Unmark the active region. Use this for
 commands you want to act on the region contents but without the
@@ -746,23 +736,11 @@ on the last s-expression like @samp{eval-last-sexp}. This 
allow you to act
 on an s-expression from anywhere inside it and still use
 @samp{eval-last-sexp} as an action.
 
-@item @samp{embark--narrow-to-target}
-Narrow buffer to current target. Use
-this as a pre-action hook to localize the effect of actions that
-don't already work on just the region. In the default configuration
-it is used for @samp{repunctuate-sentences}.
-
 @item @samp{embark--xref-push-markers}
 Push the current location on the xref
 marker stack. Use this for commands that take you somewhere and for
 which you'd like to be able to come back to where you were using
 @samp{xref-pop-marker-stack}. This is used by default for @samp{find-library}.
-
-@item @samp{embark--cd}
-Run the action with @samp{default-directory} set to the
-directory associated to the current target. The target should be of
-type @samp{file}, @samp{buffer}, @samp{bookmark} or @samp{library}, and the 
associated directory
-is what you'd expect in each case.
 @end table
 
 For post-action hooks:
@@ -777,6 +755,38 @@ rename a completion candidate; for example the default 
value of
 @samp{rename-file}, @samp{rename-buffer}, etc.
 @end table
 
+For around-action hooks:
+
+@table @asis
+@item @samp{embark--mark-target}
+Save existing mark and point location, mark
+the target and run the action. Most targets at point outside the
+minibuffer report which region of the buffer they correspond to
+(this is the information used by @samp{embark-highlight-indicator} to
+know what portion of the buffer to highlight); this function marks
+that region. It is useful as an around action hook for commands that
+expect a region to be marked, for example, it is used by default for
+@samp{indent-region} so that it works on s-expression targets, or for
+@samp{fill-region} so that it works on paragraph targets.
+
+@item @samp{embark--cd}
+Run the action with @samp{default-directory} set to the
+directory associated to the current target. The target should be of
+type @samp{file}, @samp{buffer}, @samp{bookmark} or @samp{library}, and the 
associated directory
+is what you'd expect in each case.
+
+@item @samp{embark--narrow-to-target}
+Run the action with buffer narrowed to
+current target. Use this as an around hook to localize the effect of
+actions that don't already work on just the region. In the default
+configuration it is used for @samp{repunctuate-sentences}.
+
+@item @samp{embark--save-excursion}
+Run the action restoring point at the end.
+The current default configuration doesn't use this but it is
+available for users.
+@end table
+
 @node Creating your own keymaps
 @section Creating your own keymaps
 
@@ -918,15 +928,18 @@ without confirmation is dangerous? You have a couple of 
options:
 @item
 You can keep using the @samp{tab-bar-close-tab-by-name} command, but have
 Embark ask you for confirmation:
+@end enumerate
 @lisp
 (push #'embark--confirm
       (alist-get 'tab-bar-close-tab-by-name
                  embark-pre-action-hooks))
 @end lisp
 
+@enumerate
 @item
 You can write your own command that prompts for confirmation and
 use that instead of @samp{tab-bar-close-tab-by-name} in the above keymap:
+@end enumerate
 @lisp
 (defun my-confirm-close-tab-by-name (tab)
   (interactive "sTab to close: ")
@@ -939,7 +952,6 @@ independently of Embark. Using it from @samp{M-x} leaves 
something to be
 desired, though, since you don't get completion for the tab names.
 You can fix this if you wish as described in the previous section.
 @end enumerate
-@end enumerate
 
 @node New target example in regular buffers - short Wikipedia links
 @subsection New target example in regular buffers - short Wikipedia links
@@ -1188,11 +1200,12 @@ to navigate among matches, and, if you install the 
@uref{http://github.com/mhaya
 you can use it to edit the matches in place.
 @end itemize
 
-In both cases, pressing @samp{g} to revert the exported buffer will rerun the
-Consult command you had exported from and re-enter the input you had
-typed. You can then proceed to re-export if that's what you want, but
-you can also edit the input changing the search terms or simply cancel
-if you see you are done with that search.
+In both cases, pressing @samp{g} will rerun the Consult command you had
+exported from and re-enter the input you had typed (which is similar
+to reverting but a little more flexible). You can then proceed to
+re-export if that's what you want, but you can also edit the input
+changing the search terms or simply cancel if you see you are done
+with that search.
 
 The @samp{embark-consult} also contains some candidates collectors that allow
 you to run @samp{embark-live} to get a live-updating table of contents for



reply via email to

[Prev in Thread] Current Thread [Next in Thread]