Embark: Key Features and Tweaks

https://github.com/oantolin/embark

Embark works with:

  • Vanilla Emacs
  • icomplete-mode
  • fido-mode
  • Selectrum
  • Works with Ivy too (though not recommended for Ivy or Helm users)

Installation and configuration

It is recommended that one also installs Marginalia, so that Embark can offer you more actions

(package-install 'marginalia)
(package-install 'embark)

(straight-use-package 'marginalia)
(straight-use-package 'embark)

My configuration is:

(require 'marginalia)
(marginalia-mode)

(advice-add #'marginalia-cycle :after
      (lambda () (when (bound-and-true-p selectrum-mode) (selectrum-exhibit
                'keep-selected))))
(require 'embark)
(bind-key "C-S-a" 'embark-act)

(require 'embark-consult)
(add-hook 'embark-collect-mode 'embark-consult-preview-minor-mode)

Note the importance of the command C-S-a

Commands on individual objects/targets

An object is something you can act upon. One can act on the following objects:

  • a completion candidate in the minibuffer or completions buffer
  • a file/folder at point
  • a URL at point
  • a symbol at point: commands, functions, variables
  • a buffer
  • packages!
  • an active region of text
  • Unicode character names

The ACTIONS one can perform on an object depend on the characteristics of that object.

The Key Help Command – C-h

Tells you what actions you can perform on an object at any given time.

package-refresh-contents

One can press @ and then one of the keybindings to execute or use arrows + RET

One can also get rid of the need to invoke C-h altogether by changing this variable:

embark-prompter to embark-completing-read-prompter

That way the actions will appear automatically when you invoke embark-act

One can also install which-key to help one see which actions one can perform.

See guidelines here:

https://github.com/oantolin/embark

The following link provides a list of objects and the default actions one can perform in relation to them:

https://github.com/oantolin/embark/wiki/Default-Actions

EXAMPLES OF ACTING ON SINGLE OBJECTS

e.g. URL

https://github.com/oantolin/embark/wiki/Default-Actions

e.g. one can quickly copy a file name to the kill-ring

EA + w

c:/red/.emacs.d/elpa/selectrum-20210322.1305

e.g. one can quickly invoke query replace (M-%)

Susan

e.g. one can insert at point a duplicate of a line that is in the same buffer but far away from the point

Duplicate this line at point
Duplicate this line at point

Place cursor where you want you duplicate line

M-s l (consult-line)
Type "dup"
EA + i

Duplicate this line at point

e.g. open files in external applications

~/resources/plato

EA + x

Commands on multiple objects (officially "candidate sets") WOW

In the minibuffer this means all the candidates one could possibly act upon

e.g. M-x org-roam

There are three NB commands that work on multiple objects:

  • embark-collect-snapshot – produces a buffer listing all the current candidates which one can peruse and act on
  • The embark-export command tries to open a buffer in an appropriate major mode for the set of candidates. If the candidates are files export produces a Dired buffer; if they are buffers, you get an Ibuffer buffer; and if they are packages you get a buffer in package menu mode.
  • embark-collect-live – as the above but the candidates auto-update as the set changes. One would not use this generally if you use Selectrum.

Note: sometimes these commands produce the same effect.

e.g. f8 "consult"

Examples

One can Export lists of files

f8 - org-roam-find-file

e.g. Emacs
e.g. My video series "consult"

C-x b "f" spacebar

to export files and create a dired buffer of one's files

Run multiple commands in quick succession using M-x

M-x "version"

M-s g to export results of a grep or ripgrep buffer

consult-ripgrep -> embark-export -> wgrep

M-g o to export the results of consult-line (or consult-outline)

consult-line -> embark-export -> occur-edit-mode

Type "e" to being editing

The nice thing here is that Embark simply uses the normal occur and grep mode.

Additional notes

  • The variable embark-quit-after-action controls whether embark-act quits the minibuffer or not
  • The "occur" subsystem has been overhauled and renamed "collect".

Return to Home