dotemacs

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

README-elpa (60154B)


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