(macros)
Code

Shell & compile

Macros integrates with external processes the Emacs way: one-shot shell commands (M-!, M-|, M-&), a compile command that runs a build into a read-only buffer and parses its errors, plus error navigation that jumps straight to the offending source line, grep / rgrep / lgrep over any directory, and a basic interactive shell.

Shell commands

Key Command Action
M-! shell-command Run a command in the buffer's directory and show its output
C-u M-! …and insert the output at point instead
M-| shell-command-on-region Pipe the region to a command and show its output
C-u M-| …and replace the region with the output
M-& async-shell-command Run a command in the background, streaming into *Async Shell Command*

Commands run through your shell, $SHELL -c (cmd /C on Windows), so pipes, globs, environment variables and your shell's own syntax all work. They run in the current buffer's directory (Emacs's default-directory): the visited file's folder, or the editor's working directory for a buffer with no file.

  • Output. stderr is merged into the output, as in Emacs. Output of one line is shown in the echo area. Longer output goes to *Shell Command Output*, which opens below without taking focus; press q there to close it. No output at all is reported as (Shell command succeeded with no output).
  • Exit status. A non-zero exit is always reported, for example Shell command exited with code 2. If the shell couldn't be started at all, you get the error message instead.
  • Filtering the region. C-u M-| is the one to remember. It sends the region to the command's stdin and puts the result in its place: C-u M-| sort, C-u M-| jq ., C-u M-| column -t. The replacement is a single undo step. If the command fails, its output still replaces the region (undo with C-/) and the exit status is shown. A command that can't be started leaves the region untouched.
  • Asynchronous. M-&, or an M-! command that ends in &, runs without blocking the editor. Output streams into *Async Shell Command*, and the exit status is appended when the command finishes. Only one runs at a time. C-g in its buffer, or M-x kill-async-shell-command, stops it, and killing the buffer kills the process.

M-! and M-| wait for the command to finish, like in Emacs. Use M-& for anything long-running.

compile

Key Command Action
C-c b compile Prompt for a command and run it
recompile Re-run the last compile (also g in the buffer)

Output streams into a *compilation* buffer. When the process finishes, Macros parses each line for an error location and faces it. It recognizes the common compiler and grep formats (the first matching pattern wins, like Emacs's compilation-error-regexp-alist).

In the compilation buffer

Key Action
Enter visit the source for the error on this line
g recompile
n / p move
q close

Walking errors anywhere

Key Command
M-g n next-error
M-g p previous-error

next-error / previous-error step through the parsed error list without needing the compilation buffer focused. They're shared with diagnostics and grep: the most recently used source claims them.

grep

Command Prompts for Searches
M-x grep a regexp every file under the buffer's directory
M-x rgrep regexp, file glob, directory matching files under that directory, recursively
M-x lgrep regexp, file glob, directory matching files in that directory only

These work anywhere, not only inside a project. They search in-process with ripgrep's engine, so no grep binary is needed. The search skips hidden files and whatever .gitignore excludes, and it honours the search-* options described under Projects & search. The regexp uses ripgrep (Rust regex) syntax. The file glob takes one or more space-separated patterns such as *.rs *.toml; * (the default) means every file.

Results open in the *grep* buffer, one path:line:text per match, with paths relative to the searched directory:

Key Action
Enter / click visit the match
n / p next / previous match
g run the search again
e edit the results in place, wgrep-style (C-c C-c writes the changes back)
q close

The matches also become the error list, so M-g n / M-g p step through them from any buffer, just as after a compile. Project-wide grep (C-c p g, C-c p G) is described under Projects & search and uses the same *grep* buffer.

Shell

Key Command Action
C-c s shell Open a basic interactive shell buffer
Enter shell-send-input Send the current input line

The shell command gives you a simple line-oriented shell inside a buffer. For a full terminal — ANSI/VT, curses apps, REPLs, htop — use the embedded terminal instead.

Running processes from Scheme

All of this is built on call-process, which you can call directly in your own commands:

(define (current-branch)
  (call-process "git" '("rev-parse" "--abbrev-ref" "HEAD")))

See Scripting with Steel for more on call-process, the async make-process, and giving a child extra environment (call-process-env, with-process-env). That's also how to pass it a password safely; see Passwords & secrets.