Introduction
An .el file holds Emacs Lisp, the dialect of Lisp built into the
GNU Emacs text editor. Most of Emacs
is written in it, and so are its extensions and packages. A user’s own settings, in
init.el, are Emacs Lisp too.
Emacs can byte-compile an .el file to a .elc file, and
versions built with native compilation produce .eln files as well. The
.el file stays the source that people read and edit.
Structure
An Emacs Lisp file is plain text, usually UTF-8, made of parenthesised forms that are
evaluated in turn. Comments start with ; and run to the end of the line.
By convention, the number of semicolons shows the level of a comment. Emacs also reads
the first line for file-local settings between -*- marks. The setting
lexical-binding: t turns on lexical scope, which new code is expected to
use.
A library follows a set layout: a first line naming the file and describing it, a
header of comment lines such as Author:, Version: and
Package-Requires:, a ;;; Commentary: part and a
;;; Code: part. It ends with (provide 'name), which lets
(require 'name) load it, and a closing comment. Package tools read these
headers. Functions are defined with defun and user settings with
defcustom, and a function that can be run with a keystroke or
M-x contains (interactive).
;;; greet.el --- Say hello -*- lexical-binding: t; -*-
;; Author: A. Example
;; Version: 1.0
;;; Commentary:
;; A small example library.
;;; Code:
(defun greet (name)
"Show a greeting for NAME."
(interactive "sName: ")
(message "Hello, %s" name))
(provide 'greet)
;;; greet.el ends here
Links
Software
Developers
- tree-sitter-elisp – Emacs Lisp grammar for the Tree-sitter parser used by editors
Reference
- GNU Emacs Lisp Reference Manual – the official description of the language
- Conventional Headers for Emacs Libraries – the header lines a library should have