LinuxCommandLibrary

emacs

Edit text files

TLDR

Start Emacs and open a file

$ emacs [path/to/file]
copy

Open a file at a specified line number
$ emacs +[line_number] [path/to/file]
copy

Run an Emacs Lisp file as a script
$ emacs --script [path/to/file.el]
copy

Start Emacs in console mode (without an X window)
$ emacs [[-nw|--no-window-system]]
copy

Start an Emacs server in the background (accessible via emacsclient)
$ emacs --daemon
copy

Stop a running Emacs server and all its instances, asking for confirmation on unsaved files
$ emacsclient --eval '(save-buffers-kill-emacs)'
copy

Save a file in Emacs
$ <Ctrl x><Ctrl s>
copy

Quit Emacs
$ <Ctrl x><Ctrl c>
copy

SYNOPSIS

emacs [OPTIONS] [FILES...]
emacsclient [OPTIONS] [FILES...] (for server mode)
emacs -nw [OPTIONS] [FILES...] (text terminal)
emacs --daemon (start Emacs server)

PARAMETERS

-nw or --no-window-system
    Starts Emacs in a text-only terminal, without a graphical window system.

-q or --no-init-file
    Do not load the user's personal initialization file (~/.emacs or ~/.emacs.d/init.el). Useful for debugging.

-Q or --no-site-file --no-init-file --no-splash
    Starts Emacs in a 'pure' state: skips site-wide files, user init file, and the splash screen. Ideal for testing or debugging.

--daemon
    Starts Emacs as a background server process. Subsequent editing sessions can connect to this server using emacsclient for instant startup.

--debug-init
    Enables debugging during the Emacs initialization process, useful for troubleshooting issues in init.el.

-f FUNCTION or --funcall=FUNCTION
    Executes the specified Emacs Lisp FUNCTION upon startup.

-l FILE or --load=FILE
    Loads the Emacs Lisp code from FILE upon startup.

--version
    Prints Emacs version information and exits.

FILE
    Opens FILE for editing. Multiple files can be specified.

+LINE:FILE
    Opens FILE and moves the cursor to the specified LINE number.

DESCRIPTION

Emacs is a powerful, highly extensible, and customizable text editor and integrated development environment (IDE). It is known for its extensive features, including content-aware editing modes, a built-in Lisp interpreter (Emacs Lisp or Elisp), and a vast ecosystem of packages.

Users can configure nearly every aspect of Emacs, from key bindings to advanced functionalities, often extending it beyond simple text editing into a full-fledged work environment. It supports hundreds of programming languages and markup formats, offers project management, version control integration, mail client, web browser, and much more, all within the editor. Its flexibility makes it popular among programmers, writers, and anyone needing a highly personalized computing environment.

CAVEATS

Emacs has a steep learning curve due to its unique and extensive keybindings (often involving complex combinations of Ctrl and Meta/Alt keys) and its reliance on Emacs Lisp for deep customization. It can also be resource-intensive, especially when numerous packages are loaded or very large files are being edited.

<B>EMACS LISP (ELISP)</B>

The core of Emacs's extensibility is its built-in Lisp interpreter. Users can write, load, and execute Emacs Lisp code to customize nearly every aspect of the editor, defining new commands, modes, and behaviors. This makes Emacs an incredibly powerful and adaptable environment.

<B>PACKAGE ECOSYSTEM</B>

Emacs boasts a vast and active community that develops thousands of third-party packages. These packages, easily installable via repositories like MELPA, extend Emacs's functionality significantly, adding support for new programming languages, development tools, file formats, and even unique applications like games or email clients.

<B>SERVER MODE AND <CODE>EMACSCLIENT</CODE></B>

Emacs can be run as a persistent daemon (server) in the background. The emacsclient command then connects to this running Emacs instance, allowing for instant startup times when opening new files or creating new frames, avoiding the overhead of loading Emacs from scratch each time.

HISTORY

Emacs originated in 1976 as a set of 'Editor MACroS' for the TECO editor at MIT, developed by Richard Stallman and Guy L. Steele Jr.

The version commonly used today, GNU Emacs, was initiated by Richard Stallman in 1984 as a free software replacement for Gosling Emacs. It has been under continuous active development since then, evolving into one of the most powerful and flexible text editors available.

SEE ALSO

vi(1) / vim(1): Another powerful and widely used text editor, often contrasted with Emacs., nano(1): A simpler, more user-friendly text editor for basic tasks., less(1): A pager program for viewing file contents, often used for quick file inspection., grep(1): A command-line utility for searching plain-text data sets for lines matching a regular expression, often used in conjunction with editors.

Copied to clipboard