emacs

emacs

# interactive and non-interactive

ESC x is for using an emacs command by only its name, because a command is an interactive function: it prompts for its needed values. (Command: ESC x execute-extended-command.)

ESC : is for any function, even commands, therefore encapsulate the function name and the listed values it needs within a pair of parentheses. For example, when inserting text. (Command: ESC x eval-expression.)

When a parenthesized expression is available within the text, place the point somewhere after its final parenthesis and use Controlx Controle to evaluate it. (Command: ESC x eval-last-sexp.)

# general OS commands

ESC ! is for an operating system command without having to use ESC x shell. The shell commands for the default shell are also available. Use the Controlu prefix to insert the results of the OS command, t.i. Controlu ESC !, f.e. when inserting text. (Command: ESC x shell-command.)

ESC& is for an operating system command as a background process so as to continue using emacs for something else while that gets done in the background. The shell commands for the default shell are also available. (Command: ESC x async-shell-command.)

For example, turn off Airport on macOS (from macOS commands).

ESC!networksetup -setairportpower en0 off

For general file manipulation with operating system commands, consider using dired with either ! or &.

# customization

ESC x customize reveals the customization table of contents. ESC x customize-variable asks for the name of a variable (with tab completion, of course). ESC x customize-face asks for the name of a face to customize. ESC x customize-group asks for the name of a group of settings.

ESC x customize-unsaved for showing all settings changed for this session only rather than saved for future sessions.

faces

Discover the face at point with ESC x describe-face.

Customize a face with the command ESC x customize-face, and the face at point will be the suggested face. For the default face, choose the default face. For the face used to indicate when text has been selected, choose the region face.

The first face listed as inherited has priority over later faces in that list. An unmarked feature allows inheritance. Specifically setting a marked feature as "off" will prevent the feature from affecting that text from a lesser priority face with that marked feature specifically set as "on".

A box with a negative width thickens the top and bottom borders towards its inside, while the left and right sides thicken outward as usual. That maintains line height.

The overline margin variable is two pixels by default, which is one pixel for the overline thickness and a 1 pixel gap above the text. Zero for the overline-margin maintains line height. The overline itself is the same as the top edge of the top border of a box.

cursor

The cursor foreground color is taken from the region's backgroud color, and the cursor's background color is taken from the region's foreground color. The cursor face allows customizing only the background color, and it is usually ignored when it's set the same as the region's foreground color.

The cursor-type is customized with ESC x customize-variable, which is in the display group. A horizontal bar specified with a height of zero is approximately equivalent to 4 pixels in height and automatically resizes itself when the text is resized with ControlxControl+ or ControlxControl-.

# search, then highlight or replace

Search interactively with Controls or in reverse with Controlr, or use regular-expression patterns with ESC Controls or ESC Controlr.

The "isearch" minor mode is active in the mode line when searching. There are many options listed within the help for that mode, available while searching with the shortcut for mode help Controlh m. While searching, list all keybindings with Controlh b.

Controlw adds the next word or character from the buffer. ESC Controly adds the next character from the buffer. ESC Controld removes the last character of search term. ESC s e for editing the search term directly.

ESC s c toggles case-sensitivity. ESC s SPACE toggles whitespace matching. ESC s r toggles regular-expression mode. ESC s o evokes the occur command (same shortcut) with the search term.

ESC s h r for highlighting the matches and exiting. ESC % for specifiying a replacement and begin getting asked for each match. Or ESC Control% for regular-expressions.

ESC s ESC < goes to the first match. ESC s ESC > goes to the last match.

ESC p switches to the previous search term. ESC n switches to the next search term.

For the current match, customize the isearch face. For other matches, customize the lazy-highlight face.

# highlighting

ESC s h p for highlighting a phrase. ESC s h r for highlighting with a regular-expression pattern. ESC s h u for unhighlighting a previous highlight. Prefix with Controlu to unhighlight all previous highlights.

Customize the highlighting faces in the hi-lock-faces group (with the command ESC x customize-group).

# replacement of matches

ESC % begins query for replacement without prior search. Or ESC Control% to use regular-expression patterns.

After specifying the replacement, it states in the minibuffer to type ? for help. There are three basic options while replacing matches: whether to replace; pausing, continuing, exiting; and remaining or moving to the previous or next match.

RET or q to exit. Period . to replace the current match and exit. ! replaces all remaining matches in the current buffer. For multi-buffer/file replacements, Y replaces all remaining matches in all remaining buffers/files.

SPACE or y replaces the current match and moves to the next. Comma , replaces match and stays there. DELETE or n skips to the next match. For multi-buffer/file replacements, N skips to the next buffer/file without replacing remaining matches in the current buffer.

Controlr is for pausing (recursive edit), and ESC Controlc continues. Controlw deletes match and pauses for recursive edit.

^ moves to previous match. u moves to previous match and reverts its replacement. U undoes all replacements.

E for editing the replacement string. Controll refreshes the screen and offers same replacement again.