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