<span class="mw-page-title-main">Emacs</span>
Fabrice P. Lauss𝕪s enzic Web

Emacs

Emacs is the most powerful text editor.

It is so powerful that you cannot limit it to this task alone; removing "text" in the above statement gives a better idea of what Emacs is.

It is one of the big marvels of computer codes, along with Unix, $\mathrm{\TeX}$ and others. Stallman wrote the popular GNU version in 1984 and it is still actively maintained as of today and will hopefully remain so forever. This is the real jewel.

The XEmacs branch, from the flamboyant Jamie Zawinski, was one of the earliest forking process in the computer software industry. It's without any doubt the version to use in the DNA lounge.

Integration

Useful

To align a full block, select and Tab.

To remove trailing␣␣␣␣␣␣spaces, use M-SPACE. This is however preempted by kde for "Run command", for which I prefer the global alternative Alt+F2, so just remove this assignment in ksettings.

To replace a character, say ";", with a line-break, use [2]:

M-x replace-string RET ; RET C-q C-j

with C-q for "quoted-insert" and C-j for "newline".

To swap two contiguous lines, use C-x C-t on the 2nd line (after binding transpose-lines to it [3]).

Registers

See [4]

  • text register

C-x r s a | store region as “a”
C-x r i a | insert region stored in “a”
C-x r r a | store rectangle as “a”

  • point register

C-x r SPC a | store current point as “a”
C-x r j a | move to point in “a”

  • window register

C-x r w a | store configuration of windows in frame
C-x r j a | restore window configurations

  • frame register

C-x r f a | store window configuration for all frames
C-x r j a | restore all window configurations

  • number register

C-x r N | insert a column of successive numbers - Prefix with C-u to set starting value.
C-u 1 C-x r n a | store 1 in “a”
C-u 1 C-x r + a | add 1 to number in “a”
C-x r i a | insert number in “a”

  • position register

C-x r m RET | save default
C-x r m <NAME> RET | save as NAME
C-x r b RET move to | default
C-x r b <NAME> RET | move to NAME
C-x r l list

Personal Key bindings & Emacs commands

Keyboard macros

This is like registers but on steroids: there, you record entire sequences.

See the documentation or follow these steps:

  • Hit C-x ( to start recording a keyboard macro.
  • Do what the command is supposed to do (i.e. execute commands, hit keys, ...)
  • Hit C-x ) to stop recording the keyboard macro.
  • Execute M-x name-last-kbd-macro to name the last-defined keyboard macro (i.e. the one you just defined).
  • Execute M-x insert-kbd-macro to insert the code of the last defined macro at point, copy it into your init file.
  • Put (global-set-key (kbd "M-n") 'my-macro) into your init file (assuming you named the macro my-macro) and to have M-n bind to it.

This is for instance how to bind subequations and align with automatic labelling (after my uniqname convention) for aucTeX:

(fset 'mysubeqs
   [?\C-c ?\C-e ?s ?u ?b ?e ?q ?u ?a ?t ?i ?o ?n ?s return ?\\ ?l ?a ?b ?e ?l ?\{ ?e ?q ?: ?\C-u ?\M-! ?u ?n ?i ?q ?n ?a ?m ?e return ?\C-e ?\} return ?\C-c ?\C-e ?a ?l ?i ?g ?n return return])
(global-set-key (kbd "C-c s") 'mysubeqs)

Lisp

To define a new Lisp command M-x eval-region RET on the code itself of M-x Eval-buffer to evaluate the whole page.

See also

Links

Local file variables

A file can specify local variables. "Visiting" the file checks for local variable and makes them local to the buffer. We use this mainly for aucTeX, to read:

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% TeX-command-extra-options: "-shell-escape"
%%% End:

the -shell-escape command is useful when compiling, e.g., with minted (and is usually not needed).

aucTeX

If for some reason, pdf stops compiling (and reverts to dvi) or there is a complain of no-matching-viewer, then:

M-x TeX-PDF-mode

should revert to enabling it.

Proofing marks

A proofread .tex comes back with three kinds of mark: \sout{...} around what should go, \textcolor{red}{...} around what should come in, and \textcolor{blue}{[Note: ...]} for a comment to be resolved and then deleted. proof.el settles them one at a time, or all at once, matching braces instead of trusting a regexp, so nested braces, \cite, maths and multi-line arguments all survive—the reasoning is in the hack that started it.

The file lives in ~/comp/emacs/lisp/proof.el and is autoloaded from .emacs (v°1.9), so the commands are there in every .tex buffer with nothing to load by hand:

Keys Command What it does
C-c p a or Ctrl+◯ proof-accept-at-point accept the innermost mark at point, or every mark the selection touches: the struck text goes, the red text stays, the blue note goes
C-c p r or Ctrl+✕ proof-reject-at-point reject it: the struck text comes back, the red text goes, the blue note goes as well
C-c p A proof-accept-all accept every mark in the buffer; with C-u first, ask at each one

◯ and ✕ are the round keys of the gaming keyboard, whose bare presses belong to xbindkeys—the AF tag and tex2uni—but whose Ctrl versions fall through to Emacs untouched, so a proofing pass is one key for yes and one key for no. C-c p is the typed equivalent, and the only free prefix left: C-c C-p belongs to preview-latex, C-c C-a runs the whole compile chain, and my own C-c letters were taken.

A mark only partly inside the selection is split, the rest staying marked. A selection boundary falling inside a brace group is refused rather than left unbalanced. A \cite inside a strike-out has to be written \mbox{\cite{...}}, as ulem and natbib otherwise fail at a page break; the \mbox comes off when the struck text is restored.

.emacs

My dot-emacs configuration file: .emacs.gz. It can be kept compressed as ".emacs.gz" in the home directory /home/laussy/ and opened directly with emacs and saved as such.

Versions:

  1. 1°0: 1 April (2022) started versioning (not a joke) to keep track + operatorname (C-M-o) to add \operatorname{}.
  2. 1°1: 20 May (2022) eqtomultline to replace a LaTeX equation environment to a multline one.
  3. 1°2: Some time in 2024. Red comments.
  4. 1°3: 20 February (2025) Added (setq system-time-locale "en_US.UTF-8")
  5. 1°4: 14 August (2025) Added C-c M-q & C-c M-Q
  6. 1°5: 18 July (2026) Added C-c r for redaction.
  7. 1°6: 15 August (2026) Fresh startup screen: no splash, empty *scratch* buffer in fundamental-mode.
  8. 1°7: 19 August (2026) uniqname replaced by the af tag in the labelling macros.
  9. 1°8: 9 September (2026) proof.el autoloaded for .tex files, accept and reject on C-c p and on F5 and F6.
  10. 1°9: 9 September (2026) accept and reject moved to Ctrl+◯ and Ctrl+✕, the gaming keys.

Abbrevs

My Emacs-abbrevs file.

Links