1 Overview and Philosophy

1.1 History and Origins

1.1.1 Emacs before GNU (TECO Emacs)

The earliest version of Emacs was created in 1976 by Richard Stallman and Guy L. Steele Jr. at the MIT Artificial Intelligence Laboratory. It ran on the Incompatible Timesharing System (ITS) and was implemented as a set of macros for the TECO text editor. The name Emacs originally stood for “Editor MACroS.” This version introduced the concept of an extensible, self-documenting editor, allowing users to define new editing commands by writing TECO macros. Over the next few years, various forks appeared, including Multics Emacs and Jim Gosling’s Gosling Emacs (written in C). These early implementations demonstrated the appeal of a programmable editor but were proprietary or limited in portability.

1.1.2 GNU Emacs (1984–present)

In 1984, Richard Stallman began developing GNU Emacs as part of the GNU Project. The goal was to create a completely free and open-source Emacs that would run on Unix-like systems. The first public release (version 13, continuing the version numbering from the original MIT Emacs) appeared in 1985. GNU Emacs was written primarily in C for the core and used a newly designed Lisp dialect called Emacs Lisp (Elisp) for extensibility. It quickly became the most popular implementation. Major releases followed: version 19 added multiple frames and X11 support; version 20 introduced Unicode support; version 21 added antialiased fonts and a new redisplay engine; version 24 brought package management (package.el) and lexical scoping for Elisp; version 26 added threading support; version 27 introduced native JSON parsing; version 28 added native compilation; and version 29 improved language server protocol (LSP) integration.

1.2 Design Principles

1.2.1 Self-documenting and extensible

GNU Emacs is designed so that every command, function, and variable has built-in documentation accessible via the help system (e.g., C-h f for function description, C-h v for variable). Users can inspect source code, modify behavior, and add new features without leaving the editor. Extensibility is achieved through Emacs Lisp, which can be evaluated interactively or loaded from files.

1.2.2 Keyboard-centric interface

Emacs emphasizes keyboard-driven interaction. Most commands are bound to key sequences (e.g., C-x C-s to save a file, M-x to run a command by name). Mouse support is available in GUI mode but is secondary. This design allows rapid editing once keybindings are memorized, and it works efficiently across both graphical and text-only terminals.

1.2.3 "Everything is a buffer"

The central abstraction in Emacs is the *buffer*: an in-memory object containing editable text. Files, help pages, directory listings, shell output, and even running processes are presented as buffers. Operations like searching, replacing, and editing are buffer-centric. Windows display buffers, and frames contain windows.

1.3 Community and Governance

1.3.1 GNU Project stewardship

GNU Emacs is maintained by the Free Software Foundation as part of the GNU Project. Richard Stallman served as the original maintainer; later maintainers include John Wiegley and Stefan Monnier. Core decisions are discussed on the emacs-devel mailing list.

1.3.2 Emacs development mailing lists

Major development lists include emacs-devel (for new features and patches), bug-gnu-emacs (for bug reports), and emacs-orgmode (for the Org mode package). Users also participate on the help-gnu-emacs mailing list for support.

1.3.3 Release cycle and versioning

GNU Emacs follows a time-based release cycle of roughly one major version per year. Version numbers are sequential integers (e.g., 27, 28, 29). Minor releases (e.g., 28.1, 28.2) include bug fixes and small improvements. The next development version is indicated by a period after the minor number (e.g., 29.0.50).

2 Core Architecture

2.1 The C Core

2.1.1 Redisplay engine

The redisplay engine in Emacs updates the screen display efficiently. It computes which portions of the buffer have changed and redraws only those regions. It handles multiple windows, frames, fonts, faces, and syntax highlighting. The engine is implemented in C for performance and is invoked automatically after each command.

2.1.2 Input handling and system integration

The C core manages keyboard and mouse input through a generic input subsystem that abstracts over different terminal types (X11, Wayland, Windows, terminal). It also handles system-level operations such as file I/O, process creation, signals, and networking. The core interacts with the Emacs Lisp interpreter via a main loop that reads events, dispatches commands, and updates the display.

2.2 Emacs Lisp (Elisp)

2.2.1 Data types and primitives

Emacs Lisp is a dialect of Lisp with dynamic typing. Core data types include integers, floats, strings, symbols, cons cells, lists, vectors, hash tables, buffers, windows, frames, processes, and markers. Primitives are functions implemented in C that provide low-level operations (e.g., car, cdr, concat, buffer-substring). Elisp also supports lexical scoping (since version 24) alongside historical dynamic scoping.

2.2.2 Byte compilation and native compilation

Elisp source code can be compiled into byte code (.elc files) for faster execution. Byte-compiled Emacs loads and runs more quickly. Starting with Emacs 28, native compilation (using a modified GCC called libgccjit) produces machine code (.eln files), yielding performance close to C. Native compilation is optional and can be enabled at build time.

2.2.3 The Elisp interpreter and garbage collection

The interpreter evaluates Elisp forms in a recursive descent manner. It uses a mark-and-sweep garbage collector to reclaim unused memory. Garbage collection pauses can be tuned by adjusting gc-cons-threshold and related variables. The collector runs automatically when allocated memory exceeds a threshold.

2.3 Buffer, Window, and Frame Model

2.3.1 Buffers and text representation

A buffer holds a sequence of characters with associated text properties (e.g., font-lock faces, invisible text, read-only markers). Each buffer has a local keymap, major mode, and a set of variables. Buffers can be modified (dirty) and associate with a file. The textual content is stored as a gap array for efficient insertion and deletion.

2.3.2 Windows and window splitting

Windows are visual areas that display a buffer. A frame can be split horizontally or vertically into multiple windows. Windows can be resized, rearranged, and selected. Emacs supports window configurations for persisting layouts. The window.el library provides programmatic control.

2.3.3 Frames (GUI and terminal)

A frame corresponds to a graphical window (in GUI mode) or a terminal screen. Multiple frames can coexist, each with its own set of windows. GUI frames support menus, toolbars, scrollbars, and mouse operations. Terminal frames have limited functionality but are essential for remote sessions over SSH.

2.4 Major and Minor Modes

2.4.1 Major modes for programming languages

Each buffer has exactly one major mode that defines syntax highlighting, indentation, keybindings, and other language-specific behaviors. Examples include c-mode, python-mode, js-mode, org-mode, and text-mode. Major modes are implemented in Elisp and can be customized.

2.4.2 Minor modes (highlighting, completion, etc.)

Minor modes are additional features that can be toggled independently of the major mode. They may be buffer-local or global. Examples: flyspell-mode (spell checking), company-mode (auto-completion), auto-fill-mode (automatic line breaking), linum-mode (line numbers), paredit-mode (structured editing for Lisp).

2.4.3 Mode hooks and customization

Every major and minor mode defines a hook: a list of functions run when the mode is enabled. Users can add their own functions to hooks to customize behavior. For example, prog-mode-hook runs for all programming major modes. Customization is also done via the M-x customize interface, which generates Elisp code.

3 Editing Features

3.1 Basic Text Editing

3.1.1 Keybindings and movement commands

Emacs uses modifier keys (Ctrl, Meta, Shift, Super). Common movement keys: C-f (forward char), C-b (backward char), C-n (next line), C-p (previous line), C-a (beginning of line), C-e (end of line), M-< (beginning of buffer), M-> (end of buffer). Arrow keys and Page Up/Down also work. Many commands accept numeric prefixes (C-u 5 C-f moves 5 chars forward).

3.1.2 Kill ring and undo system

Deleted or killed text is stored in a *kill ring* (a circular list). C-k kills (cuts) from point to end of line; M-w copies; C-w kills region. Yanking (C-y) retrieves the most recent kill, and M-y cycles through older ones. The undo system (C-_ or C-x u) can undo changes linearly or (with undo-tree-mode) in a branching fashion.

3.1.3 Searching and replacing (Isearch, regex)

Incremental search (C-s, C-r) provides real-time highlighting and navigation. Query replace (M-%) offers replace with confirmation. Both support regular expressions. The re-builder tool interactively tests regex patterns.

3.2 Advanced Editing Tools

3.2.1 Completion with Company mode or built-in

Built-in completion (e.g., completion-at-point) suggests words from open buffers. Company mode provides a popup menu of completions as you type, configurable backends (e.g., company-capf for language server, company-dabbrev for dictionary).

3.2.2 Outline and folding (Org-mode, HideShow)

Org-mode provides structured outline editing with visibility cycling, task management, and plain-text markup. HideShow mode (hs-minor-mode) folds code blocks by syntactic structure (e.g., {...} blocks in C). Outline mode (outline-minor-mode) uses indentation or heading markers.

3.2.3 Macros and keyboard macros

Keyboard macros record a sequence of keystrokes for later replay. Start recording with C-x (, stop with C-x ), execute with C-x e. Macros can be named, edited, and saved. They are useful for repetitive text transformations.

3.3 Multi-file and Project Support

3.3.1 Treemacs and projectile

Treemacs provides a file tree sidebar similar to modern IDEs. Projectile offers project-level operations: jumping to files, searching across project, running tests, and more. It detects project roots via .git, Cargo.toml, etc.

3.3.2 Version control integration (Magit for Git)

Magit is the most popular Emacs interface for Git. It provides an interactive status buffer, staging changes, committing, branching, rebasing, diffs, and blam. Other VCS backends exist for Mercurial (Monotone), Subversion (psvn), etc.

4 Extensions and Customization

4.1 Package Management

4.1.1 ELPA, MELPA, and Non-GNU ELPA

ELPA (Emacs Lisp Package Archive) is the official repository, maintained by the GNU Project. MELPA (Milkypostman’s Emacs Lisp Package Archive) is a community archive with thousands of packages. Non-GNU ELPA is an official archive that includes free but non-GNU packages. Users can add multiple archives.

4.1.2 Package.el and use-package

package.el is the built-in package manager. Commands: M-x package-list-packages, M-x package-install. use-package macro provides a declarative way to configure packages, lazy-load them, and ensure they are installed.

Helm, Ivy, and Vertico provide incremental narrowing and selection interfaces. Helm uses a separate window with powerful filtering. Ivy offers a minimalist minibuffer-based completion. Vertico is a newer, more modular approach based on completion-styles.

4.2 Emacs Lisp Customization

4.2.1 The customization interface

The customize group (M-x customize) provides a GUI to modify variables and faces. Settings are saved to custom-file (often ~/.emacs.d/custom.el). Customization themes allow grouping related settings.

4.2.2 Writing custom functions and keybindings

Users can define functions with defun. Keybindings are set with global-set-key, define-key, or local-set-key. Example: (global-set-key (kbd "C-c h") 'help-for-help). Advanced users write entire modes and packages in Elisp.

4.2.3 Dotfiles and init.el organization

The main configuration file is ~/.emacs.d/init.el. Users often split configuration into multiple files (e.g., config.el, packages.el, ui.el) and load them with require or load. early-init.el runs before the GUI is initialized, allowing performance tweaks. Dotfiles are shared via version control.

4.3 Major Packages: Org-mode

4.3.1 Outline, tasks, and agenda

Org-mode is a plain-text system for notes, planning, and organization. Headings (stars) create an outline. TODO and DONE tags manage tasks. The agenda (M-x org-agenda) compiles scheduled and deadline items from multiple files into a daily/weekly view.

4.3.2 Literate programming (Org-babel)

Org-babel allows embedding and executing code in multiple languages within Org documents. Source blocks are delimited by #+BEGIN_SRC and #+END_SRC. Output can be incorporated into the document. This enables reproducible research and literate programming.

4.3.3 Export to LaTeX, HTML, PDF, Markdown

Org-mode exports to various formats using M-x org-export-dispatch. Output can be styled via export templates. Common use cases include generating PDF via LaTeX, creating websites via HTML, and writing markdown documentation.

4.4 Other Notable Packages

4.4.1 Dired (file manager)

Dired (Directory Editor) lists files in a navigable buffer. Operations: copy, move, delete, rename (with dired-dwim-target). It can compress files, change permissions, and open in external programs. Dired is extensible with dired-x and dired-subtree.

4.4.2 Eshell, shell, and term

Eshell is a pure-Elisp shell that integrates with Emacs buffers. M-x shell runs a traditional Unix shell in a buffer. M-x term provides terminal emulation with full ANSI support, running programs like vim or less inside Emacs.

4.4.3 Gnus (email and news)

Gnus is a powerful mail and news reader capable of handling IMAP, POP3, NNTP, and local mail. It organizes messages into groups, supports scoring, threading, and offline read. It can also act as a web browser for RSS feeds.

4.4.4 Emacs as a development environment (LSP mode, Eglot)

LSP mode (lsp-mode) and Eglot provide integration with the Language Server Protocol, enabling features like code completion, diagnostics, go-to-definition, refactoring, and hover documentation. They support many languages by connecting to external servers (e.g., clangd, pylsp, typescript-language-server).

5 User Interfaces and Platforms

5.1 Graphical User Interface (GUI)

5.1.1 Toolbars, menus, and scrollbars

The GUI provides a toolbar with icons for common operations (open, save, cut, copy, paste). Menu bars contain the same options as key commands. Scrollbars appear on windows. All can be toggled (M-x menu-bar-mode, tool-bar-mode, scroll-bar-mode).

5.1.2 Font rendering and themes

Emacs uses font backends (Xft, Cairo, Core Text, DirectWrite) for antialiased fonts. Themes can be set via M-x customize-themes or load-theme. The package auto-dark-mode switches themes based on system light/dark mode.

5.2 Terminal Mode (TTY)

5.2.1 Limitations and advantages

In terminal mode, Emacs lacks toolbars, menus, and mouse support (unless the terminal reports mouse events). Font rendering is limited to the terminal's capabilities. However, it runs within a standard terminal, works over SSH, and uses fewer resources. Many users prefer terminal Emacs for remote editing.

5.2.2 Emacs in the terminal over SSH

Emacs can be run remotely via SSH using emacs -nw. The same keybindings and modes work except for GUI features. tramp (Transparent Remote Access, Multiple Protocols) allows editing files on remote systems transparently (e.g., /ssh:user@host:/path/to/file).

5.3 Cross-platform Support

5.3.1 GNU/Linux, macOS, Windows, BSD

Emacs runs on all major operating systems. On macOS, it can be built with or without the native GUI (NS port). On Windows, the official binary uses the Win32 API, but native builds also support WSL. BSD systems are fully supported.

5.3.2 Native builds and Windows subsystem (WSL)

Native builds are available for each platform. On Windows, running Emacs inside WSL (Windows Subsystem for Linux) provides a Unix-like environment with access to Linux tools. Native Windows Emacs can still use WSL tools via wsl-utils. Cross-platform features like Unicode, file names, and process handling are handled carefully.

6 Advanced Topics

6.1 Performance Optimization

6.1.1 Garbage collection tuning

Garbage collection pauses can be reduced by setting gc-cons-threshold and gc-cons-percentage higher. A common technique is to set a large threshold during initialization and then restore a normal value after Emacs starts. Tools like gcmh (Garbage Collector Magic Hack) automate this.

6.1.2 Native compilation (gccemacs)

Native compilation with libgccjit generates machine code for Elisp functions, significantly speeding up execution. It can be enabled at compile time with --with-native-compilation. The resulting .eln files are cached for later sessions.

6.2 Emacs Lisp Debugging and Profiling

6.2.1 Debugger and backtraces

M-x debug-on-error enters the Elisp debugger when an error occurs. The debugger shows a backtrace, allows stepping through code, and examining variables. edebug (Elisp debugger) provides a source-level debugger with breakpoints and expression evaluation.

6.2.2 Profiling Elisp code (elp, profiler)

The built-in profiler (M-x profiler-start) records function call counts and timing. Results can be viewed with M-x profiler-report. The elp (Emacs Lisp Profiler) package provides a simpler instrumenting profiler. For memory, M-x memory-report shows buffer and variable usage.

6.3 Writing Major Modes

6.3.1 Syntax tables and font-lock

Syntax tables define character classes (word, symbol, string, comment, open parenthesis, etc.). Font-lock uses regular expressions to apply faces to tokens (keywords, strings, comments). Modes define a font-lock-defaults variable.

6.3.2 Indentation engine (cc-mode style)

CC-mode and SMIE (Simple Minded Indentation Engine) provide indentation algorithms. CC-mode uses c-offsets-alist to specify indentation rules for brace positions, line-up statements, etc. SMIE is a simpler approach that uses a tokenizer and a grammar.

6.3.3 Defining mode-specific commands

Major modes define keybindings, hooks, and commands. Example: (define-key my-mode-map (kbd "C-c C-c") 'my-compile). Modes can create menu entries and customize settings.

6.4 Emacs Internals

6.4.1 The byte-compiler and native compiler

The byte-compiler translates Elisp forms to byte-code instructions stored in a vector. The native compiler (using libgccjit) further converts byte-code to native machine code. The compilation pipeline is extensible (e.g., macroexpand runs before compile).

6.4.2 The dump technique (pdump)

Emacs can be dumped to a .pdmp file after loading certain libraries, reducing startup time. The process snapshots Emacs’s memory state and then loads that dump on start. This is used for the base Emacs and for preloaded packages like Org-mode.

6.4.3 Threading and concurrency (limited)

Emacs 26 introduced optional cooperative threading using make-thread. Threads share the same memory but execute Lisp code one at a time. They are mainly useful for background computation that does not call back into the redisplay. True parallelism is not supported; future developments may improve this.

7 Cultural and Community Aspects

7.1 Emacswiki and Documentation Culture

The Emacs community maintains the Emacs Wiki (emacswiki.org), a collaborative site with tips, configuration examples, and package reviews. The culture emphasizes self-documentation: every Emacs command has help text, and users are encouraged to contribute to the wiki and write tutorials. The manual (info format) is comprehensive.

7.2 The "Editor War" vs. Vim

The long-standing rivalry between Emacs and Vim is known as the “editor war.” Each camp defends its editor’s philosophy: Emacs as an extensible operating system, Vim as a modal, lightweight editor. The debate is often humorous, with memes like “Emacs is a great operating system, lacking only a decent text editor.” Many users today combine both (Evil mode in Emacs for Vim bindings, or Spacemacs/Doom Emacs distribution).

7.3 Emacs Lisp idioms and Humor (Dired, phony manuals)

Emacs Lisp has its own idioms: defun and defmacro, backquote and comma for templates, interactive specs for commands. Humor includes the infamous “Dired” file manager (jokes about its complexity), fake manuals like “The Hacker’s Guide to Emacs Lisp,” and the “XEmacs vs. GNU Emacs” fork lore. The community celebrates puns (e.g., “Emacs is the only editor that comes with its own operating system”).

7.4 Notable Personalities and Contributions

Richard Stallman is the founder and original maintainer. Other notable contributors: John Wiegley (current maintainer), Stefan Monnier (architecture), Carsten Dominik (Org-mode), Jonas Bernoulli (Magit), Oleh Krehel (Avy, Counsel), Tom van Vleck (early Emacs history), and many package authors. The development model is meritocratic, with committers and contributors worldwide.

8 Appendix

8.1 Getting Started

8.1.1 Installation

Emacs can be installed from official sources: sudo apt install emacs on Debian/Ubuntu, brew install emacs on macOS, or download from gnu.org/software/emacs. Precompiled binaries are available for Windows. Building from source is straightforward with ./configure && make && sudo make install.

8.1.2 Tutorial (CTRL-h t)

The built-in tutorial (C-h t) teaches basic movement, editing, and help navigation. It runs in a separate buffer and is interactive. Users new to Emacs should complete it.

8.1.3 Help system (info, describe-function)

C-h f describes a function; C-h v describes a variable; C-h k shows what command a key sequence runs; C-h m describes the current major mode. The Info system (C-h i) provides the Emacs manual, Lisp reference, and package documentation. M-x apropos searches for symbols matching a string.

8.2 Glossary of Key Terms

  • Buffer: in-memory text container.
  • Frame: a GUI window or terminal screen.
  • Window: a pane within a frame displaying a buffer.
  • Point: the cursor position in a buffer.
  • Mark: another position that defines a region together with point.
  • Kill ring: history of killed (deleted/cut) text.
  • Major mode: buffer-specific editing environment.
  • Minor mode: optional feature that can be toggled.
  • Hooks: lists of functions run at certain events.
  • Emacs Lisp (Elisp): the extension language.
  • Byte compilation: converting Elisp to byte code for speed.
  • Native compilation: converting byte code to machine code.
  • Package: a collection of Elisp files and metadata.
  • Init file: user configuration file (usually init.el).
  • Org-mode: a major mode for note-taking and organizing.
  • Dired: directory editor.
  • Tramp: transparent remote file access.
  • Magit: Git interface.
  • Evil: Vim emulation mode.

8.3 Frequently Asked Questions (FAQ)

Q: How do I exit Emacs? A: C-x C-c (or M-x kill-emacs). If you are stuck, try C-g to cancel a command.

Q: Why is my Ctrl key not working? A: Some terminal emulators remap Ctrl. Check your terminal settings or try M-x C-h to see if the key is recognized.

Q: How do I install a package? A: M-x package-list-packages, find the package, press i to mark for install, then x to execute.

Q: What is the difference between C-x and M-x? A: C-x (Control-x) is the prefix for many file, buffer, and editing commands. M-x (Meta-x) is the prefix for running commands by name.

Q: How do I change the default font? A: M-x customize-face default, then set font attribute. Or set it in init.el: (set-frame-font "DejaVu Sans Mono-10").

Q: Can I use Vim keybindings in Emacs? A: Yes, install the evil package and enable evil-mode. Many distributions like Spacemacs or Doom Emacs use Evil by default.

Q: Why is my Emacs slow? A: Common causes: too many packages loaded, large files, slow garbage collection. Try profiling with M-x profiler-start and profiler-report. Increase gc-cons-threshold. Disable unused minor modes.

Q: How can I contribute to Emacs? A: Subscribe to emacs-devel mailing list, submit patches via git send-email or bug reports to bug-gnu-emacs. Follow the GNU coding standards.