dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

README.org (60101B)


      1 #+TITLE: Embark: Emacs Mini-Buffer Actions Rooted in Keymaps
      2 #+OPTIONS: d:nil
      3 #+EXPORT_FILE_NAME: embark.texi
      4 #+TEXINFO_DIR_CATEGORY: Emacs misc features
      5 #+TEXINFO_DIR_TITLE: Embark: (embark).
      6 #+TEXINFO_DIR_DESC: Emacs Mini-Buffer Actions Rooted in Keymaps
      7 
      8 #+html: <a href="http://elpa.gnu.org/packages/embark.html"><img alt="GNU ELPA" src="https://elpa.gnu.org/packages/embark.svg"/></a>
      9 #+html: <a href="http://elpa.gnu.org/devel/embark.html"><img alt="GNU-devel ELPA" src="https://elpa.gnu.org/devel/embark.svg"/></a>
     10 #+html: <a href="https://melpa.org/#/embark"><img alt="MELPA" src="https://melpa.org/packages/embark-badge.svg"/></a>
     11 #+html: <a href="https://stable.melpa.org/#/embark"><img alt="MELPA Stable" src="https://stable.melpa.org/packages/embark-badge.svg"/></a>
     12 
     13 * Overview
     14 
     15 Embark makes it easy to choose a command to run based on what is near
     16 point, both during a minibuffer completion session (in a way familiar
     17 to Helm or Counsel users) and in normal buffers. Bind the command
     18 =embark-act= to a key and it acts like prefix-key for a keymap of
     19 /actions/ (commands) relevant to the /target/ around point. With point on
     20 an URL in a buffer you can open the URL in a browser or eww or
     21 download the file it points to. If while switching buffers you spot an
     22 old one, you can kill it right there and continue to select another.
     23 Embark comes preconfigured with over a hundred actions for common
     24 types of targets such as files, buffers, identifiers, s-expressions,
     25 sentences; and it is easy to add more actions and more target types.
     26 Embark can also collect all the candidates in a minibuffer to an
     27 occur-like buffer or export them to a buffer in a major-mode specific
     28 to the type of candidates, such as dired for a set of files, ibuffer
     29 for a set of buffers, or customize for a set of variables.
     30 
     31 ** Acting on targets
     32 
     33 You can think of =embark-act= as a keyboard-based version of a
     34 right-click contextual menu. The =embark-act= command (which you should
     35 bind to a convenient key), acts as a prefix for a keymap offering you
     36 relevant /actions/ to use on a /target/ determined by the context:
     37 
     38 - In the minibuffer, the target is the current top completion
     39   candidate.
     40 - In the =*Completions*= buffer the target is the completion at point.
     41 - In a regular buffer, the target is the region if active, or else the
     42   file, symbol, URL, s-expression or defun at point.
     43 
     44 Multiple targets can be present at the same location and you can cycle
     45 between them by repeating the =embark-act= key binding. The type of
     46 actions offered depend on the type of the target. Here is a sample of
     47 a few of the actions offered in the default configuration:
     48 
     49 - For files you get offered actions like deleting, copying,
     50   renaming, visiting in another window, running a shell command on the
     51   file, etc.
     52 - For buffers the actions include switching to or killing the buffer.
     53 - For package names the actions include installing, removing or
     54   visiting the homepage.
     55 - For Emacs Lisp symbols the actions include finding the definition,
     56   looking up documentation, evaluating (which for a variable
     57   immediately shows the value, but for a function lets you pass it
     58   some arguments first). There are some actions specific to variables,
     59   such as setting the value directly or though the customize system,
     60   and some actions specific to commands, such as binding it to a key.
     61 
     62 By default when you use =embark-act= if you don't immediately select an
     63 action, after a short delay Embark will pop up a buffer showing a list
     64 of actions and their corresponding key bindings. If you are using
     65 =embark-act= outside the minibuffer, Embark will also highlight the
     66 current target. These behaviors are configurable via the variable
     67 =embark-indicators=. Instead of selecting an action via its key binding,
     68 you can select it by name with completion by typing =C-h= after
     69 =embark-act=.
     70 
     71 Everything is easily configurable: determining the current target,
     72 classifying it, and deciding which actions are offered for each type
     73 in the classification. The above introduction just mentions part of
     74 the default configuration.
     75 
     76 Configuring which actions are offered for a type is particularly easy
     77 and requires no programming: the variable =embark-keymap-alist=
     78 associates target types with variables containing keymaps, and those
     79 keymaps containing bindings for the actions. (To examine the available
     80 categories and their associated keymaps, you can use =C-h v
     81 embark-keymap-alist= or customize that variable.) For example, in the
     82 default configuration the type =file= is associated with the symbol
     83 =embark-file-map=. That symbol names a keymap with single-letter key
     84 bindings for common Emacs file commands, for instance =c= is bound to
     85 =copy-file=. This means that if you are in the minibuffer after running
     86 a command that prompts for a file, such as =find-file= or =rename-file=,
     87 you can copy a file by running =embark-act= and then pressing =c=.
     88 
     89 These action keymaps are very convenient but not strictly necessary
     90 when using =embark-act=: you can use any command that reads from the
     91 minibuffer as an action and the target of the action will be inserted
     92 at the first minibuffer prompt. After running =embark-act= all of your
     93 key bindings and even =execute-extended-command= can be used to run a
     94 command. For example, if you want to replace all occurrences of the
     95 symbol at point, just use =M-%= as the action, there is no need to bind
     96 =query-replace= in one of Embark's keymaps. Also, those action keymaps
     97 are normal Emacs keymaps and you should feel free to bind in them
     98 whatever commands you find useful as actions and want to be available
     99 through convenient bindings.
    100 
    101 The actions in =embark-general-map= are available no matter what type
    102 of completion you are in the middle of. By default this includes
    103 bindings to save the current candidate in the kill ring and to insert
    104 the current candidate in the previously selected buffer (the buffer
    105 that was current when you executed a command that opened up the
    106 minibuffer).
    107 
    108 Emacs's minibuffer completion system includes metadata indicating the
    109 /category/ of what is being completed. For example, =find-file='s
    110 metadata indicates a category of =file= and =switch-to-buffer='s metadata
    111 indicates a category of =buffer=. Embark has the related notion of the
    112 /type/ of a target for actions, and by default when category metadata
    113 is present it is taken to be the type of minibuffer completion
    114 candidates when used as targets. Emacs commands often do not set
    115 useful category metadata so the [[https://github.com/minad/marginalia][Marginalia]] package, which supplies
    116 this missing metadata, is highly recommended for use with Embark.
    117 
    118 Embark's default configuration has actions for the following target
    119 types: files, buffers, symbols, packages, URLs, bookmarks, and as a
    120 somewhat special case, actions for when the region is active. You can
    121 read about the [[https://github.com/oantolin/embark/wiki/Default-Actions][default actions and their key bindings]] on the GitHub
    122 project wiki.
    123 
    124 ** The default action on a target
    125 
    126 Embark has a notion of default action for a target:
    127 
    128 - If the target is a minibuffer completion candidate, then the default
    129   action is whatever command opened the minibuffer in the first place.
    130   For example if you run =kill-buffer=, then the default action will be
    131   to kill buffers.
    132 - If the target comes from a regular buffer (i.e., not a minibuffer),
    133   then the default action is whatever is bound to =RET= in the keymap of
    134   actions for that type of target. For example, in Embark's default
    135   configuration for a URL found at point the default action is
    136   =browse-url=, because =RET= is bound to =browse-url= in the =embark-url-map=
    137   keymap.
    138 
    139 To run the default action you can press =RET= after running =embark-act=.
    140 Note that if there are several different targets at a given location,
    141 each has its own default action, so first cycle to the target you want
    142 and then press =RET= to run the corresponding default action.
    143 
    144 There is also =embark-dwim= which runs the default action for the first
    145 target found. It's pretty handy in non-minibuffer buffers: with
    146 Embark's default configuration it will:
    147 
    148 - Open the file at point.
    149 - Open the URL at point in a web browser (using the =browse-url=
    150   command).
    151 - Compose a new email to the email address at point.
    152 - In an Emacs Lisp buffer, if point is on an opening parenthesis or
    153   right after a closing one, it will evaluate the corresponding
    154   expression.
    155 - Go to the definition of an Emacs Lisp function, variable or macro at
    156   point.
    157 - Find the file corresponding to an Emacs Lisp library at point.
    158 
    159 ** Working with sets of possible targets
    160 
    161 Besides acting individually on targets, Embark lets you work
    162 collectively on a set of target /candidates/. For example, while you are
    163 in the minibuffer the candidates are simply the possible completions
    164 of your input. Embark provides three main commands to work on candidate
    165 sets:
    166 
    167 - The =embark-act-all= command runs the same action on each of the
    168   current candidates. It is just like using =embark-act= on each
    169   candidate in turn. (Because you can easily act on many more
    170   candidates than you meant to, by default Embark asks you to confirm
    171   uses of =embark-act-all=; you can turn this off by setting the user
    172   option =embark-confirm-act-all= to =nil=.)
    173 
    174 - The =embark-collect= command produces a buffer listing all the current
    175   candidates, for you to peruse and run actions on at your leisure.
    176   The candidates are displayed as a list showing additional
    177   annotations. If any of the candidates contain newlines, then
    178   horizontal lines are used to separate candidates.
    179 
    180   The Embark Collect buffer is somewhat "dired-like": you can select
    181   and deselect candidates through =embark-select= (available as an
    182   action in =embark-act=, bound to =SPC=; but you could also give it a
    183   global key binding). In an Embark Collect buffer =embark-act= is bound
    184   to =a= and =embark-act-all= is bound to =A=; =embark-act-all= will act on
    185   all currently marked candidates if there any, and will act on all
    186   candidates if none are marked. In particular, this means that =a SPC=
    187   will toggle whether the candidate at point is selected, and =A SPC=
    188   will select all candidates if none are selected, or deselect all
    189   selected candidates if there are some.
    190 
    191 - The =embark-export= command tries to open a buffer in an appropriate
    192   major mode for the set of candidates. If the candidates are files
    193   export produces a Dired buffer; if they are buffers, you get an
    194   Ibuffer buffer; and if they are packages you get a buffer in
    195   package menu mode.
    196 
    197   If you use the grepping commands from the [[https://github.com/minad/consult/][Consult]] package,
    198   =consult-grep=, =consult-git-grep= or =consult-ripgrep=, then you should
    199   install the =embark-consult= package, which adds support for exporting a
    200   list of grep results to an honest grep-mode buffer, on which you can
    201   even use [[https://github.com/mhayashi1120/Emacs-wgrep][wgrep]] if you wish.
    202 
    203 When in doubt choosing between exporting and collecting, a good rule
    204 of thumb is to always prefer =embark-export= since when an exporter to a
    205 special major mode is available for a given type of target, it will be
    206 more featureful than an Embark collect buffer, and if no such exporter
    207 is configured the =embark-export= command falls back to the generic
    208 =embark-collect=.
    209 
    210 These commands are always available as "actions" (although they do not
    211 act on just the current target but on all candidates) for =embark-act=
    212 and are bound to =A=, =S= (for "snapshot"), and =E=, respectively, in
    213 =embark-general-map=. This means that you do not have to bind your own
    214 key bindings for these (although you can, of course!), just a key
    215 binding for =embark-act=.
    216 
    217 In Embark Collect or Embark Export buffers that were obtained by
    218 running =embark-collect= or =embark-export= from within a minibuffer
    219 completion session, =g= is bound to a command that restarts the
    220 completion session, that is, the command that opened the minibuffer is
    221 run again and the minibuffer contents restored. You can then interact
    222 normally with the command, perhaps editing the minibuffer contents,
    223 and, if you wish, you can rerun =embark-collect= or =embark-export= to get
    224 an updated buffer.
    225 
    226 *** Selecting some targets to make an ad hoc candidate set
    227 
    228 The commands for working with sets of candidates just described,
    229 namely =embark-act-all=, =embark-export= and =embark-collect= by default
    230 work with all candidates defined in the current context. For example,
    231 in the minibuffer they operate on all currently completion candidates,
    232 or in a dired buffer they work on all marked files (or all files if
    233 none are marked). Embark also has a notion of /selection/, where you can
    234 accumulate an ad hoc list of targets for these commands to work on.
    235 
    236 The selection is controlled by using the =embark-select= action, bound
    237 to =SPC= in =embark-general-map= so that it is always available (you can
    238 also give =embark-select= a global key binding if you wish; when called
    239 directly, not as an action for =embark-act=, it will select the first
    240 target at point). Calling this action on a target toggles its
    241 membership in the current buffer's Embark selection; that is, it adds
    242 it to selection if not selected and removes it from the selection if
    243 it was selected. Whenever the selection for a buffer is non-empty, the
    244 commands =embark-act-all=, =embark-export= and =embark-collect= will act on
    245 the selection.
    246 
    247 To deselect all selected targets, you can use the =embark-select= action
    248 through =embark-act-all=, since this will run =embark-select= on each
    249 member of the current selection. Similarly if no targets are selected
    250 and you are in a minibuffer completion session, running =embark-select=
    251 from =embark-act-all= will select all the current completion candidates.
    252 
    253 By default, whenever some targets are selected in the current buffer,
    254 a count of selected targets appears in the mode line. This can be
    255 turned off or customized through the =embark-selection-indicator= user
    256 option.
    257 
    258 The selection functionality is supported in every buffer:
    259 
    260 - In the minibuffer this gives a convenient way to act on several
    261   completion candidates that don't follow any simple pattern: just go
    262   through the completions selecting the ones you want, then use
    263   =embark-act-all=. For example, you could attach several files at once
    264   to an email.
    265 - For Embark Collect buffers this functionality enables a dired-like
    266   workflow, in which you mark various candidates and apply an action
    267   to all at once. (It supersedes a previous ad hoc dired-like
    268   interface that was implemented only in Embark Collect buffers, with
    269   a slightly different interface.)
    270 - In a eww buffer you could use this to select various links you wish
    271   to follow up on, and then collect them into a buffer. Similarly,
    272   while reading Emacs's info manual you could select some symbols you
    273   want to read more about and export them to an =apropos-mode= buffer.
    274 - You can use selections in regular text or programming buffers to do
    275   complex editing operations. For example, if you have three
    276   paragraphs scattered over a file and you want to bring them
    277   together, you can select each one, insert them all somewhere and
    278   finally delete all of them (from their original locations).
    279   
    280 *** =embark-live= a live-updating variant of =embark-collect=
    281 
    282 Finally, there is also an =embark-live= variant of the =embark-collect=
    283 command which automatically updates the collection after each change
    284 in the source buffer. Users of a completion UI that automatically
    285 updates and displays the candidate list (such as Vertico, Icomplete,
    286 Fido-mode, or MCT) will probably not want to use
    287 =embark-live= from the minibuffer as they will then have two live
    288 updating displays of the completion candidates!
    289 
    290 A more likely use of =embark-live= is to be called from a regular buffer
    291 to display a sort of live updating "table of contents" for the buffer.
    292 This depends on having appropriate candidate collectors configured in
    293 =embark-candidate-collectors=. There are not many in Embark's default
    294 configuration, but you can try this experiment: open a dired buffer in
    295 a directory that has very many files, mark a few, and run =embark-live=.
    296 You'll get an Embark Collect buffer containing only the marked files,
    297 which updates as you mark or unmark files in dired. To make
    298 =embark-live= genuinely useful other candidate collectors are required.
    299 The =embark-consult= package (documented near the end of this manual)
    300 contains a few: one for imenu items and one for outline headings as
    301 used by =outline-minor-mode=. Those collectors really do give
    302 =embark-live= a table-of-contents feel.
    303 
    304 ** Switching to a different command without losing what you've typed
    305 
    306 Embark also has the =embark-become= command which is useful for when
    307 you run a command, start typing at the minibuffer and realize you
    308 meant a different command. The most common case for me is that I run
    309 =switch-to-buffer=, start typing a buffer name and realize I haven't
    310 opened the file I had in mind yet! I'll use this situation as a
    311 running example to illustrate =embark-become=. When this happens I can,
    312 of course, press =C-g= and then run =find-file= and open the file, but
    313 this requires retyping the portion of the file name you already
    314 typed. This process can be streamlined with =embark-become=: while still
    315 in the =switch-to-buffer= you can run =embark-become= and effectively
    316 make the =switch-to-buffer= command become =find-file= for this run.
    317 
    318 You can bind =embark-become= to a key in =minibuffer-local-map=, but it is
    319 also available as an action under the letter =B= (uppercase), so you
    320 don't need a binding if you already have one for =embark-act=. So,
    321 assuming I have =embark-act= bound to, say, =C-.=, once I realize I
    322 haven't open the file I can type =C-. B C-x C-f= to have
    323 =switch-to-buffer= become =find-file= without losing what I have already
    324 typed in the minibuffer.
    325 
    326 But for even more convenience, =embark-become= offers shorter key
    327 bindings for commands you are likely to want the current command to
    328 become. When you use =embark-become= it looks for the current command in
    329 all keymaps named in the list =embark-become-keymaps= and then activates
    330 all keymaps that contain it. For example, the default value of
    331 =embark-become-keymaps= contains a keymap =embark-become-file+buffer-map=
    332 with bindings for several commands related to files and buffers, in
    333 particular, it binds =switch-to-buffer= to =b= and =find-file= to =f=. So when
    334 I accidentally try to switch to a buffer for a file I haven't opened
    335 yet, =embark-become= finds that the command I ran, =switch-to-buffer=, is
    336 in the keymap =embark-become-file+buffer-map=, so it activates that
    337 keymap (and any others that also contain a binding for
    338 =switch-to-buffer=). The end result is that I can type =C-. B f= to
    339 switch to =find-file=.
    340 
    341 * Quick start
    342 
    343 The easiest way to install Embark is from GNU ELPA, just run =M-x
    344 package-install RET embark RET=. (It is also available on MELPA.) It is
    345 highly recommended to also install [[https://github.com/minad/marginalia][Marginalia]] (also available on GNU
    346 ELPA), so that Embark can offer you preconfigured actions in more
    347 contexts. For =use-package= users, the following is a very reasonable
    348 starting configuration:
    349 
    350 #+begin_src emacs-lisp
    351   (use-package marginalia
    352     :ensure t
    353     :config
    354     (marginalia-mode))
    355 
    356   (use-package embark
    357     :ensure t
    358 
    359     :bind
    360     (("C-." . embark-act)         ;; pick some comfortable binding
    361      ("C-;" . embark-dwim)        ;; good alternative: M-.
    362      ("C-h B" . embark-bindings)) ;; alternative for `describe-bindings'
    363 
    364     :init
    365 
    366     ;; Optionally replace the key help with a completing-read interface
    367     (setq prefix-help-command #'embark-prefix-help-command)
    368 
    369     ;; Show the Embark target at point via Eldoc.  You may adjust the Eldoc
    370     ;; strategy, if you want to see the documentation from multiple providers.
    371     (add-hook 'eldoc-documentation-functions #'embark-eldoc-first-target)
    372     ;; (setq eldoc-documentation-strategy #'eldoc-documentation-compose-eagerly)
    373 
    374     :config
    375 
    376     ;; Hide the mode line of the Embark live/completions buffers
    377     (add-to-list 'display-buffer-alist
    378                  '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
    379                    nil
    380                    (window-parameters (mode-line-format . none)))))
    381 
    382   ;; Consult users will also want the embark-consult package.
    383   (use-package embark-consult
    384     :ensure t ; only need to install it, embark loads it after consult if found
    385     :hook
    386     (embark-collect-mode . consult-preview-at-point-mode))
    387 #+end_src
    388 
    389 About the suggested key bindings for =embark-act= and =embark-dwim=:
    390 - Those key bindings are unlikely to work in the terminal, but
    391   terminal users are probably well aware of this and will know to
    392   select different bindings.
    393 - The suggested =C-.= binding is used by default in (at least some
    394   installations of) GNOME to input emojis, and Emacs doesn't even get
    395   a chance to respond to the binding. You can select a different key
    396   binding for =embark-act= or use =ibus-setup= to change the shortcut for
    397   emoji insertion (Emacs 29 will likely use =C-x 8 e e=, in case you
    398   want to set the same one system-wide).
    399 - The suggested alternative of =M-.= for =embark-dwim= is bound by default
    400   to =xref-find-definitions=. That is a very useful command but
    401   overwriting it with =embark-dwim= is sensible since in Embark's
    402   default configuration, =embark-dwim= will also find the definition of
    403   the identifier at point. (Note that =xref-find-definitions= with a
    404   prefix argument prompts you for an identifier, =embark-dwim= does not
    405   cover this case).
    406 
    407 Other Embark commands such as =embark-act-all=, =embark-become=,
    408 =embark-collect=, and =embark-export= can be run through =embark-act= as
    409 actions bound to =A=, =B=, =S= (for "snapshot"), and =E= respectively, and
    410 thus don't really need a dedicated key binding, but feel free to bind
    411 them directly if you so wish. If you do choose to bind them directly,
    412 you'll probably want to bind them in =minibuffer-local-map=, since they
    413 are most useful in the minibuffer (in fact, =embark-become= only works
    414 in the minibuffer).
    415 
    416 The command =embark-dwim= executes the default action at point. Another good
    417 keybinding for =embark-dwim= is =M-.= since =embark-dwim= acts like
    418 =xref-find-definitions= on the symbol at point. =C-.= can be seen as a
    419 right-click context menu at point and =M-.= acts like left-click. The
    420 keybindings are mnemonic, both act at the point (=.=).
    421 
    422 Embark needs to know what your minibuffer completion system considers
    423 to be the list of candidates and which one is the current candidate.
    424 Embark works out of the box if you use Emacs's default tab completion,
    425 the built-in =icomplete-mode= or =fido-mode=, or the third-party packages
    426 [[https://github.com/minad/vertico][Vertico]] or [[https://github.com/abo-abo/swiper][Ivy]].
    427 
    428 If you are a [[https://emacs-helm.github.io/helm/][Helm]] or [[https://github.com/abo-abo/swiper][Ivy]] user you are unlikely to want Embark since
    429 those packages include comprehensive functionality for acting on
    430 minibuffer completion candidates. (Embark does come with Ivy
    431 integration despite this.)
    432 
    433 * Advanced configuration
    434 ** Showing information about available targets and actions
    435 
    436 By default, if you run =embark-act= and do not immediately select an
    437 action, after a short delay Embark will pop up a buffer called =*Embark
    438 Actions*= containing a list of available actions with their key
    439 bindings. You can scroll that buffer with the mouse of with the usual
    440 commands =scroll-other-window= and =scroll-other-window-down= (bound by
    441 default to =C-M-v= and =C-M-S-v=).
    442 
    443 That functionality is provided by the =embark-mixed-indicator=, but
    444 Embark has other indicators that can provide information about the
    445 target and its type, what other targets you can cycle to, and which
    446 actions have key bindings in the action map for the current type of
    447 target. Any number of indicators can be active at once and the user
    448 option =embark-indicators= should be set to a list of the desired
    449 indicators.
    450 
    451 Embark comes with the following indicators:
    452 
    453 - =embark-minimal-indicator=: shows a messages in the echo area or
    454   minibuffer prompt showing the current target and the types of all
    455   targets starting with the current one; this one is on by default.
    456 
    457 - =embark-highlight-indicator=: highlights the target at point;
    458   also on by default.
    459 
    460 - =embark-verbose-indicator=: displays a table of actions and their key
    461   bindings in a buffer; this is not on by default, in favor of the
    462   mixed indicator described next.
    463 
    464 - =embark-mixed-indicator=: starts out by behaving as the minimal
    465   indicator but after a short delay acts as the verbose indicator;
    466   this is on by default.
    467 
    468 - =embark-isearch-highlight-indicator=: this only does something when
    469   the current target is the symbol at point, in which case it
    470   lazily highlights all occurrences of that symbol in the current
    471   buffer, like isearch; also on by default.
    472 
    473 Users of the popular [[https://github.com/justbur/emacs-which-key][which-key]] package may prefer to use the
    474 =embark-which-key-indicator= from the [[https://github.com/oantolin/embark/wiki/Additional-Configuration#use-which-key-like-a-key-menu-prompt][Embark wiki]]. Just copy its
    475 definition from the wiki into your configuration and customize the
    476 =embark-indicators= user option to exclude the mixed and verbose
    477 indicators and to include =embark-which-key-indicator=.
    478 
    479 ** Selecting commands via completions instead of key bindings
    480 
    481 As an alternative to reading the list of actions in the verbose or
    482 mixed indicators (see the previous section for a description of
    483 these), you can press the =embark-help-key=, which is =C-h= by default
    484 (but you may prefer =?= to free up =C-h= for use as a prefix) after
    485 running =embark-act=. Pressing the help key will prompt you for the name
    486 of an action with completion (but feel free to enter a command that is
    487 not among the offered candidates!), and will also remind you of the
    488 key bindings. You can press =embark-keymap-prompter-key=, which is =@= by
    489 default, at the prompt and then one of the key bindings to enter the
    490 name of the corresponding action.
    491 
    492 You may think that with the =*Embark Actions*= buffer popping up to
    493 remind you of the key bindings you'd never want to use completion to
    494 select an action by name, but personally I find that typing a small
    495 portion of the action name to narrow down the list of candidates feels
    496 significantly faster than visually scanning the entire list of actions.
    497 
    498 If you find you prefer entering actions that way, you can configure
    499 embark to always prompt you for actions by setting the variable
    500 =embark-prompter= to =embark-completing-read-prompter=.
    501 
    502 ** Quitting the minibuffer after an action
    503 
    504 By default, if you call =embark-act= from the minibuffer it quits the
    505 minibuffer after performing the action. You can change this by setting
    506 the user option =embark-quit-after-action= to =nil=. Having =embark-act= /not/
    507 quit the minibuffer can be useful to turn commands into little "thing
    508 managers". For example, you can use =find-file= as a little file manager
    509 or =describe-package= as a little package manager: you can run those
    510 commands, perform a series of actions, and then quit the command.
    511 
    512 If you want to control the quitting behavior in a fine-grained manner
    513 depending on the action, you can set =embark-quit-after-action= to an
    514 alist, associating commands to either =t= for quitting or =nil= for not
    515 quitting. When using an alist, you can use the special key =t= to
    516 specify the default behavior. For example, to specify that by default
    517 actions should not quit the minibuffer but that using =kill-buffer= as
    518 an action should quit, you can use the following configuration:
    519 
    520 #+begin_src emacs-lisp
    521   (setq embark-quit-after-action '((kill-buffer . t) (t . nil)))
    522 #+end_src
    523 
    524 The variable =embark-quit-after-action= only specifies a default, that
    525 is, it only controls whether or not =embark-act= quits the minibuffer
    526 when you call it without a prefix argument, and you can select the
    527 opposite behavior to what the variable says by calling =embark-act= with
    528 =C-u=. Also note that both the variable =embark-quit-after-action= and =C-u=
    529 have no effect when you call =embark-act= outside the minibuffer.
    530 
    531 If you find yourself using the quitting and non-quitting variants of
    532 =embark-act= about equally often, independently of the action, you may
    533 prefer to simply have separate commands for them instead of a single
    534 command that you call with =C-u= half the time. You could, for example,
    535 keep the default exiting behavior of =embark-act= and define a
    536 non-quitting version as follows:
    537 
    538 #+begin_src emacs-lisp
    539   (defun embark-act-noquit ()
    540     "Run action but don't quit the minibuffer afterwards."
    541     (interactive)
    542     (let ((embark-quit-after-action nil))
    543       (embark-act)))
    544 #+end_src
    545 
    546 ** Running some setup after injecting the target
    547 
    548 You can customize what happens after the target is inserted at the
    549 minibuffer prompt of an action. There are
    550 =embark-target-injection-hooks=, that are run by default after injecting
    551 the target into the minibuffer. The variable
    552 =embark-target-injection-hooks= is an alist associating commands to
    553 their setup hooks. There are two special keys: if no setup hook is
    554 specified for a given action, the hook associated to =t= is run; and the
    555 hook associated to =:always= is run regardless of the action. (This
    556 variable used to have the less explicit name of
    557 =embark-setup-action-hooks=, so please update your configuration.)
    558 
    559 For example, consider using =shell-command= as an action during file
    560 completion. It would be useful to insert a space before the target
    561 file name and to leave the point at the beginning, so you can
    562 immediately type the shell command to run on that file. That's why in
    563 Embark's default configuration there is an entry in
    564 =embark-target-injection-hooks= associating =shell-command= to a hook that
    565 includes =embark--shell-prep=, a simple helper function that quotes all
    566 the spaces in the file name, inserts an extra space at the beginning
    567 of the line and leaves point to the left of it.
    568 
    569 Now, the preparation that =embark--shell-prep= does would be useless if
    570 Embark did what it normally does after it inserts the target of the
    571 action at the minibuffer prompt, which is to "press =RET=" for you,
    572 accepting the target as is; if Embark did that for =shell-command= you
    573 wouldn't get a chance to type in the command to execute! That is why
    574 in Embark's default configuration the entry for =shell-command= in
    575 =embark-target-injection-hooks= also contains the function
    576 =embark--allow-edit=.
    577 
    578 Embark used to have a dedicated variable =embark-allow-edit-actions= to
    579 which you could add commands for which Embark should forgo pressing
    580 =RET= for you after inserting the target. Since its effect can also be
    581 achieved via the general =embark-target-injection-hooks= mechanism, that
    582 variable has been removed to simplify Embark. Be sure to update your
    583 configuration; if you had something like:
    584 
    585 #+begin_src emacs-lisp
    586   (add-to-list 'embark-allow-edit-actions 'my-command)
    587 #+end_src
    588 
    589 you should replace it with:
    590 
    591 #+begin_src emacs-lisp
    592   (push 'embark--allow-edit
    593         (alist-get 'my-command embark-target-injection-hooks))
    594 #+end_src
    595 
    596 
    597 Also note that while you could abuse =embark--allow-edit= so that you
    598 have to confirm "dangerous" actions such as =delete-file=, it is better
    599 to implement confirmation by adding the =embark--confirm= function to
    600 the appropriate entry of a different hook alist, namely,
    601 =embark-pre-action-hooks=.
    602 
    603 Besides =embark--allow-edit=, Embark comes with another function that is
    604 of general utility in action setup hooks: =embark--ignore-target=. Use
    605 it for commands that do prompt you in the minibuffer but for which
    606 inserting the target would be inappropriate. This is not a common
    607 situation but does occasionally arise. For example it is used by
    608 default for =shell-command-on-region=: that command is used as an action
    609 for region targets, and it prompts you for a shell command; you
    610 typically do /not/ want the target, that is the contents of the region,
    611 to be entered at that prompt!
    612 
    613 ** Running hooks before, after or around an action
    614 
    615 Embark has three variables, =embark-pre-action-hooks=,
    616 =embark-post-action-hooks= and =embark-around-action-hooks=, which are
    617 alists associating commands to hooks that should run before or after
    618 or as around advice for the command when used as an action. As with
    619 =embark-target-injection-hooks=, there are two special keys for the
    620 alists: =t= designates the default hook to run when no specific hook is
    621 specified for a command; and the hook associated to =:always= runs
    622 regardless.
    623 
    624 The default values of those variables are fairly extensive, adding
    625 creature comforts to make running actions a smooth experience. Embark
    626 comes with several functions intended to be added to these hooks, and
    627 used in the default values of =embark-pre-action-hooks=,
    628 =embark-post-action-hooks= and =embark-around-action-hooks=.
    629 
    630 For pre-action hooks:
    631 
    632 - =embark--confirm= :: Prompt the user for confirmation before executing
    633   the action. This is used be default for commands deemed "dangerous",
    634   or, more accurately, hard to undo, such as =delete-file= and
    635   =kill-buffer=.
    636 
    637 - =embark--unmark-target= :: Unmark the active region. Use this for
    638   commands you want to act on the region contents but without the
    639   region being active. The default configuration uses this function as
    640   a pre-action hook for =occur= and =query-replace=, for example, so that
    641   you can use them as actions with region targets to search the whole
    642   buffer for the text contained in the region. Without this pre-action
    643   hook using =occur= as an action for a region target would be
    644   pointless: it would search for the the region contents /in the
    645   region/, (typically, due to the details of regexps) finding only one
    646   match!
    647 
    648 - =embark--beginning-of-target= :: Move to the beginning of the target
    649   (for targets that report bounds). This is used by default for
    650   backward motion commands such as =backward-sexp=, so that they don't
    651   accidentally leave you on the current target.
    652 
    653 - =embark--end-of-target= :: Move to the end of the target. This is used
    654   similarly to the previous function, but also for commands that act
    655   on the last s-expression like =eval-last-sexp=. This allow you to act
    656   on an s-expression from anywhere inside it and still use
    657   =eval-last-sexp= as an action.
    658 
    659 - =embark--xref-push-markers= :: Push the current location on the xref
    660   marker stack. Use this for commands that take you somewhere and for
    661   which you'd like to be able to come back to where you were using
    662   =xref-pop-marker-stack=. This is used by default for =find-library=.
    663 
    664 For post-action hooks:
    665 
    666 - =embark--restart= :: Restart the command currently prompting in the
    667   minibuffer, so that the list of completion candidates is updated.
    668   This is useful as a post action hook for commands that delete or
    669   rename a completion candidate; for example the default value of
    670   =embark-post-action-hooks= uses it for =delete-file=, =kill-buffer=,
    671   =rename-file=, =rename-buffer=, etc.
    672 
    673 For around-action hooks:
    674 
    675 - =embark--mark-target= :: Save existing mark and point location, mark
    676   the target and run the action. Most targets at point outside the
    677   minibuffer report which region of the buffer they correspond to
    678   (this is the information used by =embark-highlight-indicator= to
    679   know what portion of the buffer to highlight); this function marks
    680   that region. It is useful as an around action hook for commands that
    681   expect a region to be marked, for example, it is used by default for
    682   =indent-region= so that it works on s-expression targets, or for
    683   =fill-region= so that it works on paragraph targets.
    684 
    685 - =embark--cd= :: Run the action with =default-directory= set to the
    686   directory associated to the current target. The target should be of
    687   type =file=, =buffer=, =bookmark= or =library=, and the associated directory
    688   is what you'd expect in each case.
    689 
    690 - =embark--narrow-to-target= :: Run the action with buffer narrowed to
    691   current target. Use this as an around hook to localize the effect of
    692   actions that don't already work on just the region. In the default
    693   configuration it is used for =repunctuate-sentences=.
    694 
    695 - =embark--save-excursion= :: Run the action restoring point at the end.
    696   The current default configuration doesn't use this but it is
    697   available for users.
    698 
    699 ** Creating your own keymaps
    700 
    701 All internal keymaps are defined with the standard helper macro
    702 =defvar-keymap=. For example a simple version of the file action keymap
    703 could be defined as follows:
    704 
    705 #+BEGIN_SRC emacs-lisp
    706   (defvar-keymap embark-file-map
    707     :doc "Example keymap with a few file actions"
    708     :parent embark-general-map
    709     "d" #'delete-file
    710     "r" #'rename-file
    711     "c" #'copy-file)
    712 #+END_SRC
    713 
    714 These action keymaps are perfectly normal Emacs
    715 keymaps.  You may want to inherit from the =embark-general-map= if you
    716 want to access the default Embark actions. Note that =embark-collect=
    717 and =embark-export= are also made available via =embark-general-map=.
    718 
    719 ** Defining actions for new categories of targets
    720 
    721 It is easy to configure Embark to provide actions for new types of
    722 targets, either in the minibuffer or outside it. I present below two
    723 very detailed examples of how to do this. At several points I'll
    724 explain more than one way to proceed, typically with the easiest
    725 option first. I include the alternative options since there will be
    726 similar situations where the easiest option is not available.
    727 
    728 *** New minibuffer target example - tab-bar tabs
    729 
    730 As an example, take the new [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Tab-Bars.html][tab bars]] from Emacs 27. I'll explain how
    731 to configure Embark to offer tab-specific actions when you use the
    732 tab-bar-mode commands that mention tabs by name. The configuration
    733 explained here is now built-in to Embark (and Marginalia), but it's
    734 still a good self-contained example. In order to setup up tab actions
    735 you would need to: (1) make sure Embark knows those commands deal with
    736 tabs, (2) define a keymap for tab actions and configure Embark so it
    737 knows that's the keymap you want.
    738 
    739 **** Telling Embark about commands that prompt for tabs by name
    740 
    741 For step (1), it would be great if the =tab-bar-mode= commands reported
    742 the completion category =tab= when asking you for a tab with
    743 completion. (All built-in Emacs commands that prompt for file names,
    744 for example, do have metadata indicating that they want a =file=.) They
    745 do not, unfortunately, and I will describe a couple of ways to deal
    746 with this.
    747 
    748 Maybe the easiest thing is to configure [[https://github.com/minad/marginalia][Marginalia]] to enhance those
    749 commands. All of the =tab-bar-*-tab-by-name= commands have the words
    750 "tab by name" in the minibuffer prompt, so you can use:
    751 
    752 #+begin_src emacs-lisp
    753   (add-to-list 'marginalia-prompt-categories '("tab by name" . tab))
    754 #+end_src
    755 
    756 That's it! But in case you are ever in a situation where you don't
    757 already have commands that prompt for the targets you want, I'll
    758 describe how writing your own command with appropriate =category=
    759 metadata looks:
    760 
    761 #+begin_src emacs-lisp
    762   (defun my-select-tab-by-name (tab)
    763     (interactive
    764      (list
    765       (let ((tab-list (or (mapcar (lambda (tab) (cdr (assq 'name tab)))
    766                                   (tab-bar-tabs))
    767                           (user-error "No tabs found"))))
    768         (completing-read
    769          "Tabs: "
    770          (lambda (string predicate action)
    771            (if (eq action 'metadata)
    772                '(metadata (category . tab))
    773              (complete-with-action
    774               action tab-list string predicate)))))))
    775     (tab-bar-select-tab-by-name tab))
    776 #+end_src
    777 
    778 As you can see, the built-in support for setting the category
    779 meta-datum is not very easy to use or pretty to look at. To help with
    780 this I recommend the =consult--read= function from the excellent
    781 [[https://github.com/minad/consult/][Consult]] package. With that function we can rewrite the command as
    782 follows:
    783 
    784 #+begin_src emacs-lisp
    785   (defun my-select-tab-by-name (tab)
    786     (interactive
    787      (list
    788       (let ((tab-list (or (mapcar (lambda (tab) (cdr (assq 'name tab)))
    789                                   (tab-bar-tabs))
    790                           (user-error "No tabs found"))))
    791         (consult--read tab-list
    792                        :prompt "Tabs: "
    793                        :category 'tab))))
    794     (tab-bar-select-tab-by-name tab))
    795 #+end_src
    796 
    797 Much nicer! No matter how you define the =my-select-tab-by-name=
    798 command, the first approach with Marginalia and prompt detection has
    799 the following advantages: you get the =tab= category for all the
    800 =tab-bar-*-bar-by-name= commands at once, also, you enhance built-in
    801 commands, instead of defining new ones.
    802 
    803 **** Defining and configuring a keymap for tab actions
    804 
    805  Let's say we want to offer select, rename and close actions for tabs
    806  (in addition to Embark general actions, such as saving the tab name to
    807  the kill-ring, which you get for free). Then this will do:
    808 
    809  #+begin_src emacs-lisp
    810    (defvar-keymap embark-tab-actions
    811      :doc "Keymap for actions for tab-bar tabs (when mentioned by name)."
    812      :parent embark-general-map
    813      "s" #'tab-bar-select-tab-by-name
    814      "r" #'tab-bar-rename-tab-by-name
    815      "k" #'tab-bar-close-tab-by-name)
    816 
    817    (add-to-list 'embark-keymap-alist '(tab . embark-tab-actions))
    818  #+end_src
    819 
    820  What if after using this for a while you feel closing the tab
    821  without confirmation is dangerous? You have a couple of options:
    822 
    823  1. You can keep using the =tab-bar-close-tab-by-name= command, but have
    824     Embark ask you for confirmation:
    825     #+begin_src emacs-lisp
    826       (push #'embark--confirm
    827             (alist-get 'tab-bar-close-tab-by-name
    828                        embark-pre-action-hooks))
    829     #+end_src
    830 
    831  2. You can write your own command that prompts for confirmation and
    832     use that instead of =tab-bar-close-tab-by-name= in the above keymap:
    833     #+begin_src emacs-lisp
    834       (defun my-confirm-close-tab-by-name (tab)
    835         (interactive "sTab to close: ")
    836         (when (y-or-n-p (format "Close tab '%s'? " tab))
    837           (tab-bar-close-tab-by-name tab)))
    838     #+end_src
    839 
    840     Notice that this is a command you can also use directly from =M-x=
    841     independently of Embark. Using it from =M-x= leaves something to be
    842     desired, though, since you don't get completion for the tab names.
    843     You can fix this if you wish as described in the previous section.
    844 
    845 *** New target example in regular buffers - short Wikipedia links
    846 
    847 Say you want to teach Embark to treat text of the form
    848 =wikipedia:Garry_Kasparov= in any regular buffer as a link to Wikipedia,
    849 with actions to open the Wikipedia page in eww or an external browser
    850 or to save the URL of the page in the kill-ring. We can take advantage
    851 of the actions that Embark has preconfigured for URLs, so all we need
    852 to do is teach Embark that =wikipedia:Garry_Kasparov= stands for the URL
    853 =https://en.wikipedia.org/wiki/Garry_Kasparov=.
    854 
    855 You can be as fancy as you want with the recognized syntax. Here, to
    856 keep the example simple, I'll assume the link matches the regexp
    857 =wikipedia:[[:alnum:]_]+=. We will write a function that looks for a
    858 match surrounding point, and returns a dotted list of the form ='(url
    859 URL-OF-THE-PAGE START . END)= where =START= and =END= are the buffer
    860 positions bounding the target, and are used by Embark to highlight it
    861 if you have =embark-highlight-indicator= included in the list
    862 =embark-indicators=. (There are a couple of other options for the return
    863 value of a target finder: the bounding positions are optional and a
    864 single target finder is allowed to return multiple targets; see the
    865 documentation for =embark-target-finders= for details.)
    866 
    867 #+begin_src emacs-lisp
    868   (defun my-short-wikipedia-link ()
    869     "Target a link at point of the form wikipedia:Page_Name."
    870     (save-excursion
    871       (let* ((start (progn (skip-chars-backward "[:alnum:]_:") (point)))
    872              (end (progn (skip-chars-forward "[:alnum:]_:") (point)))
    873              (str (buffer-substring-no-properties start end)))
    874         (save-match-data
    875           (when (string-match "wikipedia:\\([[:alnum:]_]+\\)" str)
    876             `(url
    877               ,(format "https://en.wikipedia.org/wiki/%s"
    878                        (match-string 1 str))
    879               ,start . ,end))))))
    880 
    881   (add-to-list 'embark-target-finders 'my-short-wikipedia-link)
    882 #+end_src
    883 
    884 * How does Embark call the actions?
    885 
    886   Embark actions are normal Emacs commands, that is, functions with an
    887   interactive specification. In order to execute an action, Embark
    888   calls the command with =call-interactively=, so the command reads user
    889   input exactly as if run directly by the user. For example the
    890   command may open a minibuffer and read a string
    891   (=read-from-minibuffer=) or open a completion interface
    892   (=completing-read=). If this happens, Embark takes the target string
    893   and inserts it automatically into the minibuffer, simulating user
    894   input this way. After inserting the string, Embark exits the
    895   minibuffer, submitting the input. (The immediate minibuffer exit can
    896   be disabled for specific actions in order to allow editing the
    897   input; this is done by adding the =embark--allow-edit= function to the
    898   appropriate entry of =embark-target-injection-hooks=). Embark inserts
    899   the target string at the first minibuffer opened by the action
    900   command, and if the command happens to prompt the user for input
    901   more than once, the user still interacts with the second and further
    902   prompts in the normal fashion. Note that if a command does not
    903   prompt the user for input in the minibuffer, Embark still allows you
    904   to use it as an action, but of course, never inserts the target
    905   anywhere. (There are plenty of examples in the default configuration
    906   of commands that do not prompt the user bound to keys in the action
    907   maps, most of the region actions, for instance.)
    908 
    909   This is how Embark manages to reuse normal commands as actions. The
    910   mechanism allows you to use as Embark actions commands that were not
    911   written with Embark in mind (and indeed almost all actions that are
    912   bound by default in Embark's action keymaps are standard Emacs
    913   commands). It also allows you to write new custom actions in such a
    914   way that they are useful even without Embark.
    915 
    916   Staring from version 28.1, Emacs has a variable
    917   =y-or-n-p-use-read-key=, which when set to =t= causes =y-or-n-p= to use
    918   =read-key= instead of =read-from-minibuffer=. Setting
    919   =y-or-n-p-use-read-key= to =t= is recommended for Embark users because
    920   it keeps Embark from attempting to insert the target at a =y-or-n-p=
    921   prompt, which would almost never be sensible. Also consider this as
    922   a warning to structure your own action commands so that if they use
    923   =y-or-n-p=, they do so only after the prompting for the target.
    924 
    925   Here is a simple example illustrating the various ways of reading
    926   input from the user mentioned above. Bind the following commands to
    927   the =embark-symbol-map= to be used as actions, then put the point on
    928   some symbol and run them with =embark-act=:
    929 
    930   #+begin_src emacs-lisp
    931     (defun example-action-command1 ()
    932       (interactive)
    933       (message "The input was `%s'." (read-from-minibuffer "Input: ")))
    934 
    935     (defun example-action-command2 (arg input1 input2)
    936       (interactive "P\nsInput 1: \nsInput 2: ")
    937       (message "The first input %swas `%s', and the second was `%s'."
    938                (if arg "truly " "")
    939                input1
    940                input2))
    941 
    942     (defun example-action-command3 ()
    943       (interactive)
    944       (message "Your selection was `%s'."
    945                (completing-read "Select: " '("E" "M" "B" "A" "R" "K"))))
    946 
    947     (defun example-action-command4 ()
    948       (interactive)
    949       (message "I don't prompt you for input and thus ignore the target!"))
    950 
    951     (keymap-set embark-symbol-map "X 1" #'example-action-command1)
    952     (keymap-set embark-symbol-map "X 2" #'example-action-command2)
    953     (keymap-set embark-symbol-map "X 3" #'example-action-command3)
    954     (keymap-set embark-symbol-map "X 4" #'example-action-command4)
    955   #+end_src
    956 
    957   Also note that if you are using the key bindings to call actions,
    958   you can pass prefix arguments to actions in the normal way. For
    959   example, you can use =C-u X2= with the above demonstration actions to
    960   make the message printed by =example-action-command2= more emphatic.
    961   This ability to pass prefix arguments to actions is useful for some
    962   actions in the default configuration, such as
    963   =embark-shell-command-on-buffer=.
    964 
    965 ** Non-interactive functions as actions
    966 
    967   Alternatively, Embark does support one other type of action: a
    968   non-interactive function of a single argument. The target is passed
    969   as argument to the function. For example:
    970 
    971   #+begin_src emacs-lisp
    972     (defun example-action-function (target)
    973       (message "The target was `%s'." target))
    974 
    975     (keymap-set embark-symbol-map "X 4" #'example-action-function)
    976   #+end_src
    977 
    978   Note that normally binding non-interactive functions in a keymap is
    979   useless, since when attempting to run them using the key binding you
    980   get an error message similar to "Wrong type argument: commandp,
    981   example-action-function". In general it is more flexible to write
    982   any new Embark actions as commands, that is, as interactive
    983   functions, because that way you can also run them directly, without
    984   Embark. But there are a couple of reasons to use non-interactive
    985   functions as actions:
    986 
    987   1. You may already have the function lying around, and it is
    988      convenient to simply reuse it.
    989 
    990   2. For command actions the targets can only be simple string, with
    991      no text properties. For certain advanced uses you may want the
    992      action to receive a string /with/ some text properties, or even a
    993      non-string target.
    994 
    995 * Embark, Marginalia and Consult
    996 
    997 Embark cooperates well with the [[https://github.com/minad/marginalia][Marginalia]] and [[https://github.com/minad/consult][Consult]] packages.
    998 Neither of those packages is a dependency of Embark, but both are
    999 highly recommended companions to Embark, for opposite reasons:
   1000 Marginalia greatly enhances Embark's usefulness, while Embark can help
   1001 enhance Consult.
   1002 
   1003 In the remainder of this section I'll explain what exactly Marginalia
   1004 does for Embark, and what Embark can do for Consult.
   1005 
   1006 ** Marginalia
   1007 
   1008 Embark comes with actions for symbols (commands, functions, variables
   1009 with actions such as finding the definition, looking up the
   1010 documentation, evaluating, etc.) in the =embark-symbol-map= keymap, and
   1011 for packages (actions like install, delete, browse url, etc.) in the
   1012 =embark-package-keymap=.
   1013 
   1014 Unfortunately Embark does not automatically offers you these keymaps
   1015 when relevant, because many built-in Emacs commands don't report
   1016 accurate category metadata. For example, a command like
   1017 =describe-package=, which reads a package name from the minibuffer,
   1018 does not have metadata indicating this fact.
   1019 
   1020 In an earlier Embark version, there were functions to supply this
   1021 missing metadata, but they have been moved to Marginalia, which
   1022 augments many Emacs command to report accurate category metadata.
   1023 Simply activating =marginalia-mode= allows Embark to offer you the
   1024 package and symbol actions when appropriate again. Candidate
   1025 annotations in the Embark collect buffer are also provided by the
   1026 Marginalia package:
   1027 
   1028 - If you install Marginalia and activate =marginalia-mode=, Embark
   1029   Collect buffers will use the Marginalia annotations automatically.
   1030 
   1031 - If you don't install Marginalia, you will see only the annotations
   1032   that come with Emacs (such as key bindings in =M-x=, or the unicode
   1033   characters in =C-x 8 RET=).
   1034 
   1035 ** Consult
   1036 
   1037 The excellent Consult package provides many commands that use
   1038 minibuffer completion, via the =completing-read= function; plenty of its
   1039 commands can be considered enhanced versions of built-in Emacs
   1040 commands, and some are completely new functionality. One common
   1041 enhancement provided in all commands for which it makes sense is
   1042 preview functionality, for example =consult-buffer= will show you a
   1043 quick preview of a buffer before you actually switch to it.
   1044 
   1045 If you use both Consult and Embark you should install the
   1046 =embark-consult= package which provides integration between the two. It
   1047 provides exporters for several Consult commands and also tweaks the
   1048 behavior of many Consult commands when used as actions with =embark-act=
   1049 in subtle ways that you may not even notice, but make for a smoother
   1050 experience. You need only install it to get these benefits: Embark
   1051 will automatically load it after Consult if found.
   1052 
   1053 The =embark-consult= package provides the following exporters:
   1054 
   1055 - You can use =embark-export= from =consult-line=, =consult-outline=, or
   1056   =consult-mark= to obtain an =occur-mode= buffer. As with the built-in
   1057   =occur= command you use that buffer to jump to a match and after that,
   1058   you can then use =next-error= and =previous-error= to navigate to other
   1059   matches. You can also press =e= to activate =occur-edit-mode= and edit
   1060   the matches in place!
   1061 
   1062 - You can export from any of the Consult asynchronous search commands,
   1063   =consult-grep=, =consult-git-grep=, or =consult-ripgrep= to get a
   1064   =grep-mode= buffer. Here too you can use =next-error= and =previous-error=
   1065   to navigate among matches, and, if you install the [[http://github.com/mhayashi1120/Emacs-wgrep/raw/master/wgrep.el ][wgrep]] package,
   1066   you can use it to edit the matches in place.
   1067 
   1068 In both cases, pressing =g= will rerun the Consult command you had
   1069 exported from and re-enter the input you had typed (which is similar
   1070 to reverting but a little more flexible). You can then proceed to
   1071 re-export if that's what you want, but you can also edit the input
   1072 changing the search terms or simply cancel if you see you are done
   1073 with that search.
   1074 
   1075 The =embark-consult= also contains some candidates collectors that allow
   1076 you to run =embark-live= to get a live-updating table of contents for
   1077 your buffer:
   1078 
   1079 - =embark-consult-outline-candidates= produces the outline headings of
   1080   the current buffer, using =consult-outline=.
   1081 - =embark-consult-imenu-candidates= produces the imenu items of
   1082   the current buffer, using =consult-imenu=.
   1083 - =embark-consult-imenu-or-outline-candidates= is a simple combination
   1084   of the two previous functions: it produces imenu items in buffers
   1085   deriving from =prog-mode= and otherwise outline headings.
   1086 
   1087 The way to configure =embark-live= (or =embark-collect= and =embark-export=
   1088 for that matter) to use one of these function is to add it at the end
   1089 of the =embark-candidate-collectors= list. The =embark-consult= package by
   1090 default adds the last one, which seems to be the most sensible
   1091 default.
   1092 
   1093 Besides those exporters and candidate collectors, the =embark-consult=
   1094 package provides many subtle tweaks and small integrations between
   1095 Embark and Consult. Some examples are:
   1096 
   1097 - When used as actions, the asynchronous search commands will search
   1098   only the files associated to the targets: if the targets /are/ files,
   1099   it searches those files; for buffers it will search either the
   1100   associated file if there is one, else all files in the buffer's
   1101   =default-directory=; for bookmarks it will search the file they point
   1102   to, same for Emacs Lisp libraries. This is particularly powerful
   1103   when using =embark-act-all= to act on multiple files at once, for
   1104   example you can use =consult-find= to search among file /names/ and then
   1105   =embark-act-all= and =consult-grep= to search within the matching files.
   1106 
   1107  - For all other target types, those that do not have a sensible
   1108    notion of associated file, a Consult search command (asynchronous
   1109    or not) will search for the text of the target but leave the
   1110    minibuffer open so you can interact with the Consult command.
   1111 
   1112 - =consult-imenu= will search for the target and take you directly to
   1113   the location if it matches a unique imenu entry, otherwise it will
   1114   leave the minibuffer open so you can navigate among the matches.
   1115 
   1116 * Related Packages
   1117 
   1118 There are several packages that offer functionality similar
   1119 to Embark's. 
   1120 
   1121 - Acting on minibuffer completion candidates :: The popular Ivy and
   1122   Helm packages have support for acting on the completion candidates
   1123   of commands written using their APIs, and there is an extensive
   1124   ecosystem of packages meant for Helm and for Ivy (the Ivy ones
   1125   usually have "counsel" in the name) providing commands and
   1126   appropriate actions.
   1127 - Acting on things at point :: The built-in =context-menu-mode= provides
   1128   a mouse-driven context-sensitive configurable menu. The =do-at-point=
   1129   package by Philip Kaludercic (available on GNU ELPA), on the other
   1130   hand is keyboard-driven.
   1131 - Collecting completion candidates into a buffer :: The Ivy package
   1132   has the command =ivy-occur= which is similar to =embark-collect=. As
   1133   with Ivy actions, =ivy-occur= only works for commands written using
   1134   the Ivy API.
   1135   
   1136 * Resources
   1137 
   1138 If you want to learn more about how others have used Embark here are
   1139 some links to read:
   1140 
   1141 - [[https://karthinks.com/software/fifteen-ways-to-use-embark/][Fifteen ways to use Embark]], a blog post by Karthik Chikmagalur.
   1142 - [[https://protesilaos.com/dotemacs/][Protesilaos Stavrou's dotemacs]], look for the section called
   1143   "Extended minibuffer actions and more (embark.el and
   1144   prot-embark.el)"
   1145 
   1146 And some videos to watch:
   1147 
   1148 - [[https://protesilaos.com/codelog/2021-01-09-emacs-embark-extras/][Embark and my extras]] by Protesilaos Stavrou.
   1149 - [[https://youtu.be/qpoQiiinCtY][Embark -- Key features and tweaks]] by Raoul Comninos on the
   1150   Emacs-Elements YouTube channel.
   1151 - [[https://youtu.be/WsxXr1ncukY][Livestreamed: Adding an Embark context action to send a stream
   1152   message]] by Sacha Chua.
   1153 - [[https://youtu.be/qk2Is_sC8Lk][System Crafters Live! - The Many Uses of Embark]] by David Wilson.
   1154 - [[https://youtu.be/5ffb2at2d7w][Using Emacs Episode 80 - Vertico, Marginalia, Consult and Embark]] by
   1155   Mike Zamansky.
   1156 
   1157 * Contributions
   1158 
   1159 Contributions to Embark are very welcome. There is a [[https://github.com/oantolin/embark/issues/95][wish list]] for
   1160 actions, target finders, candidate collectors and exporters. For other
   1161 ideas you have for Embark, feel free to open an issue on the [[https://github.com/oantolin/embark/issues][issue
   1162 tracker]]. Any neat configuration tricks you find might be a good fit
   1163 for the [[https://github.com/oantolin/embark/wiki][wiki]].
   1164 
   1165 Code contributions are very welcome too, but since Embark is now on
   1166 GNU ELPA, copyright assignment to the FSF is required before you can
   1167 contribute code.
   1168 
   1169 * Acknowledgments
   1170 
   1171 While I, Omar Antolín Camarena, have written most of the Embark code
   1172 and remain very stubborn about some of the design decisions, Embark
   1173 has received substantial help from a number of other people which this
   1174 document has neglected to mention for far too long. In particular,
   1175 Daniel Mendler has been absolutely invaluable, implementing several
   1176 important features, and providing a lot of useful advice.
   1177 
   1178 Code contributions:
   1179 
   1180 - [[https://github.com/minad][Daniel Mendler]]
   1181 - [[https://github.com/clemera/][Clemens Radermacher]]
   1182 - [[https://codeberg.org/jao/][José Antonio Ortega Ruiz]]
   1183 - [[https://github.com/iyefrat][Itai Y. Efrat]]
   1184 - [[https://github.com/a13][a13]]
   1185 - [[https://github.com/jakanakaevangeli][jakanakaevangeli]]
   1186 - [[https://github.com/mihakam][mihakam]]
   1187 - [[https://github.com/leungbk][Brian Leung]]
   1188 - [[https://github.com/karthink][Karthik Chikmagalur]]
   1189 - [[https://github.com/roshanshariff][Roshan Shariff]]
   1190 - [[https://github.com/condy0919][condy0919]]
   1191 - [[https://github.com/DamienCassou][Damien Cassou]]
   1192 - [[https://github.com/JimDBh][JimDBh]]
   1193 
   1194 Advice and useful discussions:
   1195 
   1196 - [[https://github.com/minad][Daniel Mendler]]
   1197 - [[https://gitlab.com/protesilaos/][Protesilaos Stavrou]]
   1198 - [[https://github.com/clemera/][Clemens Radermacher]]
   1199 - [[https://github.com/hmelman/][Howard Melman]]
   1200 - [[https://github.com/astoff][Augusto Stoffel]]
   1201 - [[https://github.com/bdarcus][Bruce d'Arcus]]
   1202 - [[https://github.com/jdtsmith][JD Smith]]
   1203 - [[https://github.com/karthink][Karthik Chikmagalur]]
   1204 - [[https://github.com/jakanakaevangeli][jakanakaevangeli]]
   1205 - [[https://github.com/iyefrat][Itai Y. Efrat]]
   1206 - [[https://github.com/mohkale][Mohsin Kaleem]]