Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 38 ยท Workflows

Writing and Note-taking Workflows in Emacs

Make Emacs a comfortable writing tool: visual line wrapping, spell checking with Flyspell, Markdown and LaTeX modes, rectangles, and linked notes with Denote.

Emacs began as a text editor, and writing prose is still one of its strengths. With a few settings you get comfortable line wrapping, spell checking, word counts, structure navigation and a system of linked notes, all in plain text files you will still be able to open in twenty years. This lesson collects the settings and packages for writers, students and note-takers.

Configuration is real Emacs Lisp. The runnable blocks are JavaScript stand-ins: a word counter and a note-link scanner that follow the same file name rules a note package uses.

Comfortable text

Code buffers prefer short lines; prose reads better when long lines wrap at the window edge.

ELISP
(add-hook 'text-mode-hook #'visual-line-mode)     ; wrap at window edge, C-a/C-e/C-k work on screen lines
(setq-default fill-column 80)                     ; for M-q (fill-paragraph)
(setq sentence-end-double-space nil)              ; one space after a period

Two different ideas: visual-line-mode wraps only on screen and keeps the file's lines long, ideal for Markdown and Org; auto-fill-mode and M-q insert real line breaks at fill-column, ideal for emails and commit messages. Useful movement and editing commands for prose:

  • M-a / M-e sentence start and end; M-{ / M-} paragraph;
  • M-t transpose words, C-t transpose characters, M-c / M-u / M-l capitalize, upper- and lowercase a word;
  • M-q fill paragraph, C-u M-q justify; M-h marks the paragraph;
  • M-= (count-words-region) counts words in the region or buffer; M-x count-words works anywhere.

For a distraction-free look, olivetti-mode (a package) centres a column of text, and M-x variable-pitch-mode or (add-hook 'text-mode-hook #'variable-pitch-mode) switches to a proportional font.

Spell checking

Emacs uses an external spell checker. Install Hunspell, Aspell or Enchant, then:

ELISP
(setq ispell-program-name "hunspell")        ; or "aspell"
(setq ispell-dictionary "en_US")
(add-hook 'text-mode-hook #'flyspell-mode)
(add-hook 'prog-mode-hook #'flyspell-prog-mode)   ; only comments and strings

flyspell-mode underlines misspellings as you type. With the cursor on a word, C-; (flyspell-auto-correct-previous-word) fixes the previous one, M-$ (ispell-word) opens a menu of suggestions, C-M-i or the mouse's middle button also works on some setups, and M-x ispell-buffer checks the whole buffer. M-x ispell-change-dictionary switches language, and a local variable ispell-local-dictionary can be set per file. jinx (a package) is a faster alternative that uses Enchant and avoids Flyspell's delays.

JS Stand-in: word counts and reading time

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Markup languages

  • Org is Emacs's own outliner and markup language, covered in the Org Mode chapter.
  • markdown-mode (package) provides highlighting, folding with TAB, list handling, C-c C-c p to preview and C-c C-x C-l to render images. Set markdown-command to pandoc or multimarkdown for HTML output.
  • AUCTeX (package) gives LaTeX buffers: C-c C-c compiles (command LaTeX), viewer integration, C-c C-e inserts environments, C-c = shows a table of contents (RefTeX). Use reftex-mode for citations and cross-references.
  • pandoc-mode or plain pandoc via M-x compile converts between Markdown, Org, DOCX and PDF.
  • Citations: the built-in citar and org-cite handle bibliographies from a .bib file; M-x org-cite-insert (or C-c C-x @ in Org) inserts a citation.

Rectangles and tables

Rectangle commands edit a column of text between two corners (mark one corner, move to the other): C-x r k kills the rectangle, C-x r y pastes it, C-x r t replaces each line's text with a string (add a prefix to many lines), C-x r o opens a blank rectangle, and C-x SPC (rectangle-mark-mode) shows the rectangle. For tabular data, M-x align-regexp lines up columns, and M-x sort-lines and M-x delete-duplicate-lines clean a list.

Linked notes with Denote

A "second brain" is a folder of small notes that link to each other. Denote (by Protesilaos Stavrou, available on GNU ELPA) names notes with a rigid, readable file name and works with Org, Markdown and plain text:

Text
20240131T094500--emacs-registers__emacs_notes.org
|  identifier   | title (slug)   | tags (_ separated)

The identifier is the creation date and time (YYYYMMDDTHHMMSS), then --, the title as a lowercase slug, then __ and underscore-separated tags. M-x denote creates a note (it asks for a title and keywords); M-x denote-link inserts a link to another note by completing on title; M-x denote-backlinks lists notes that link here; M-x denote-rename-file retitles a file while keeping the identifier. Because the name carries the data, any file manager, ls or grep can search it.

ELISP
(use-package denote
  :ensure t
  :custom
  (denote-directory (expand-file-name "~/notes/"))
  (denote-known-keywords '("emacs" "ideas" "work"))
  :hook (dired-mode . denote-dired-mode))

Other systems you may meet: org-roam (Org files plus a database of links and a backlinks buffer), Org-Journal, and howm. All store text files, so switching later is straightforward.

JS Stand-in: parse note names and find backlinks

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Plain text and open formats are the point. Whichever note system you choose, keep notes in a Git repository, give them meaningful titles, and use M-x consult-ripgrep over the folder as your search engine.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the difference between visual-line-mode and auto-fill-mode?

    visual-line-mode keeps long lines in the file but displays them wrapped; auto-fill changes the text.
  2. 2. Which command shows suggestions for the misspelled word at point?

    M-$ runs ispell-word; flyspell also offers corrections via mouse or C-;.
  3. 3. In a Denote file name, what do double underscores introduce?

    20240131T094500--title__tag1_tag2.org: after __ come tags separated by single underscores.
  4. 4. Which command inserts a link to another Denote note?

    denote-link completes on note titles and inserts a link.

Summary

  • Use visual-line-mode for wrapped prose and M-q with fill-column for hard-wrapped text.
  • Install Hunspell or Aspell and enable flyspell-mode; M-$ lists suggestions.
  • Markdown (markdown-mode), Org, AUCTeX and pandoc cover most writing formats.
  • Rectangle commands (C-x r t, C-x r k) edit columns of text.
  • Denote names notes ID--title__tags.ext so plain tools can search and link them.

Next: Project: A Minimal init.el