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