Linux Emacs: Complete Guide for Developers

Introduction

In the free software ecosystem, few programs have been able to remain relevant for as many decades as Emacs. Created initially by Richard Stallman in the 1970s as a set of macros for the TECO editor, Emacs has grown into a fully programmable working environment, capable of adapting to virtually any task that a Linux user can imagine. Your GPL license ensures that anyone can study, modify and redistribute the code, perfectly aligned with the philosophy of transparency and collaboration that defines the Linux operating system.

Brief story of Emacs

The project was born in 1976 within the MIT's Artificial Intelligence Laboratory, where Stallman sought to improve the text editing experience in TECO-compatible systems. Over the years, the code was rewritten in Lisp, giving rise to GNU Emacs, the version that today distributes the Free Software Foundation. This transition to Lisp not only made the editor extendable, but also laid the foundations for a global community of contributors who continue to improve their functionality year after year.

Why Emacs stands out in Linux

  • Deep integration with the terminal and command line tools, allowing to run shells, compilers and debugging without leaving the editor.
  • Ability to run any external program through functions such asshell-commandorasync-shell-command, which makes Emacs a universal pitcher.
  • Extensibility by Emacs Lisp, a Lisp dialect specifically designed to customize each aspect of the editor, from keyboard shortcuts to complete editing modes.
  • Native support for version control systems through packages such as Magit, which offers a powerful and fully shortcut-based Git interface.
  • Self-content documentation environment, with integrated tutorial, Info mode and ability to generate documentation in Info, HTML or PDF format directly from the source code.

Basic configuration: the init.el file

Emacs behavior is mainly controlled by the fileinit.el(or.emacs) located in the directory~/.emacs.d/. A simple example of configuration includes:

  • Activate the global syntax highlight:(global-font-lock-mode 1)
  • Disable the toolbar and menu to maximize the editing space:(tool-bar-mode -1) (menu-bar-mode -1)
  • Set a nice dark theme:(load-theme 'tango-dark t)
  • Enable line number display:(global-display-line-numbers-mode 1)
  • Configure the tabulation size to four spaces:(setq-default tab-width 4)

These lines can be added at the end ofinit.eland recharge withM-x eval-bufferor reboot Emacs.

Essential packages for Linux developers

The integrated package managerpackage.elfacilitates the installation of extensions from the GNU ELPA, MELPA and other repositories. Some essential packages are:

  • Magit: powerful Git interface that allows to make commitments, branches, merges and conflict resolution with intuitive keyboard shortcuts.
  • Org-mode: note organization, planning and publishing tool that supports export to HTML, PDF, LaTeX and more, in addition to allowing code block execution by Org-babel.
  • LSP-mode: bring Language Server Protocol to Emacs, offering self-completed, diagnostic and jump-to-definition for multiple languages such as Python, JavaScript, Rust and Go.
  • Flycheck: real-time syntactic verification that shows errors and warnings directly in the buffer, integrating with linters such as pylint, eslint and rubocop.
  • Treemacs: IDE-style file tree view, with Git integration, markers and quick file opening.
  • Project: project management that automatically detects the root of the repository and offers commands to search files, switch between buffers and run tests.

Emacs as a full development environment (IDE)

Thanks to the combination of the mentioned packages, Emacs can function as a light but powerful IDE. For example, when you activatelsp-modewithlsp-uiis obtained self-completed based on language, emerging documentation and real-time refactorization. Adddap-mode(Debug Adapter Protocol) allows you to purify programs directly from the editor, setting breaking points, inspecting variables and watching the stop track without leaving the environment. In addition,company-modeprovides a self-completed menu that works with any backend, whilewhich-keyshows the possible continuations of a key sequence, reducing the learning curve for new users.

Eshell: the terminal within Emacs

Eshell is a shell written completely in Emacs Lisp that reproduces many of the features of bash, zsh or fish, but with the advantage of being fully integrated into the Emacs buffer. This allows to combine shell commands with text editing in a smooth way: for example, you can runls, select a file with the mouse or shortcuts, and open it directly into another buffer without copying and paste routes. In addition, Eshell can interact with the file system through TRAMP (see next section) and allows to redirect the output to temporary buffers for further analysis.

TRAMP: Remote edition without leaving the editor

TRAMP (Transparent Remote Access, Multiple Protocols) is a feature that allows editing files located on remote machines as if they were local. It supports protocols such as SSH, FTP, SIP and even Docker, which is invaluable for system administrators and developers working with cloud servers or containers. With TRAMP, just write a route like/ssh:usuario@host:/ruta/al/archivoin the minibuffer and Emacs will be in charge of establishing the connection, transferring the file, allowing its editing and synchronizing the changes safely.

Org-babel and literary programming

Org-babel extends Org-mode to allow the execution of code blocks within a flat text document. This facilitates the creation of playable notebooks where the narrative, the code and its results coexist in the same file. It supports dozens of languages, including Python, R, Julia, Bash and SQL, and can export the final document to formats such as HTML, LaTeX or Markdown. This capacity makes Emacs an ideal tool for research, data analysis and rigorous technical documentation.

Evil-mode: the Vim experience within Emacs

For those who come from Vim and want to keep their modal shortcuts Evil@-@ mode offers an almost complete emulation of the classic editor within Emacs. By activating Evil-mode, the normal modes, insert, visual and command behave as in Vim, while you can still access all the power of Emacs Lisp, packages and integration with the system. This combination allows you to enjoy Vim's editing efficiency along with the extensibility and advanced features of Emacs, such as Org, Magit and LSP.

Conclusion

Emacs remains a powerful option for anyone working in Linux, thanks to its combination of extensibility, deep integration with the system and an active community that continues to provide new features. Whether you are a programmer, a technical writer, a system manager or a personal organization enthusiast, investing time in learning and customizing Emacs can result in a remarkable productivity improvement and a work environment totally under your control. Its ability to adapt to virtually any workflow makes it a timeless tool that deserves a prominent place on the desktop of any Linux user.

This work is under aCreative Commons License Attribution 4.0 International for Francesc Roig francesc @ vivaldi.net.

EnglishenEnglishEnglish