Emacs Lisp, short for Emacs Lisp Programming Language, was created by Richard Stallman in 1976 as the extension language for the Emacs text editor. Emacs Lisp is a dialect of the Lisp family and is primarily used for scripting, customization, and extending the functionality of Emacs. Developers can access Emacs Lisp through the official GNU Emacs distribution: GNU Emacs Downloads, which provides the interpreter, libraries, and documentation for Windows, macOS, and Linux platforms.
Emacs Lisp exists to provide a programmable environment for text editing and automation within Emacs. Its design philosophy emphasizes simplicity, flexibility, and interactive development. By embedding a Lisp interpreter directly into the editor, Emacs Lisp allows users to define new commands, modify editor behavior, and create complex extensions while maintaining the underlying Emacs core. This solves the problem of static software by enabling a fully adaptable, user-driven editing environment.
Emacs Lisp: Variables and Symbols
Emacs Lisp uses dynamically scoped variables, symbols, and basic data types like numbers, strings, and lists. Symbols can act as both variable names and function identifiers.
(setq name "Emacs Lisp")
(setq version 1.0)
(print (format "Language: %s, Version: %s" name version))Variables can be assigned and accessed interactively. Symbols unify identifiers and functions, making code concise and highly flexible. This approach is similar to other Lisp dialects.
Emacs Lisp: Lists and S-Expressions
Lists and S-expressions form the core data structure of Emacs Lisp, representing both code and data.
(setq numbers '(1 2 3 4 5))
(car numbers) ; returns 1
(cdr numbers) ; returns (2 3 4 5)S-expressions allow programs to manipulate code as data, enabling macros, metaprogramming, and dynamic evaluation. This design is fundamental in all Lisp variants.
Emacs Lisp: Functions and Macros
Emacs Lisp supports first-class functions and powerful macros for extending the language and the editor.
(defun square (x)
(* x x))
(defun describe-number (n)
(cond ((= n 0) "zero")
((= n 1) "one")
(t "other")))
(print (square 5))Functions encapsulate reusable behavior, and macros allow code transformation at compile-time. This enables highly dynamic editor customization, conceptually similar to Lisp and Common Lisp.
Emacs Lisp: Interactive Development and Buffers
Emacs Lisp allows interaction with editor buffers, windows, and user input, enabling scripts to automate editing tasks and manipulate text efficiently.
(with-current-buffer "*scratch*"
(insert "Hello, Emacs Lisp!"))Direct buffer manipulation and interactive evaluation promote rapid development and experimentation. This interactive environment is unique to Emacs Lisp and similar extension languages for editors.
Emacs Lisp remains central to customizing and extending GNU Emacs. Its combination of dynamic typing, S-expressions, macros, and interactive capabilities makes it a powerful tool for both programmers and text-processing enthusiasts. When combined with Lisp, Common Lisp, and Scheme, Emacs Lisp provides a flexible, programmable environment capable of evolving alongside the needs of its users and the editor itself.