Maksym Prokopov personal blog
Idea is a something worth sharing

Emacs For Beginners

10.05.2024

Reading time: 4 min.

The article provides overview of facts why Emacs is so different but also so powerful comparing to other editors. It gives a good starting point for the reader to understand the fundamentals and start own journey to effective work.

The way of learning is painful, but rewarding. The essense of Emacs is to codify your specific repetitive tasks so that eventually you realize, the editor contains a lot of customizations speeding up your daily routines, as no other editor does.

I do the following things in Emacs:

First of all, Emacs is a runtime environment with a set of named functions you can call any time. Use Meta-x key combination to spawn a list of “interactive” functions. There are more functions, but only those who marked as interactive supposed to be in this list.

Functions are written in a dialect of Lisp, so called emacs-lisp. If you want one sentence definition of lisp, here it is. First argument in a brackets is a function name, the rest is its arguments. Example

(+ 1 2)

In this example + is a function name, 1 and 2 are the arguments. The output is 3. Yeah, this is it. Emacs can execute a freshly written function on the fly.

Every time you hit a keystroke in Emacs you call a function. Even for a cursor movement. There is an easy way to find what function is bound to a keystroke by using C-h k followed by the keystroke. Remarkable feature is a documentation for any function is only C-h f away. This makes Emacs exploration a breeze.

An opened file is called a buffer. Depending on the file type, Emacs loads automatically a set of functions and key bindings to those functions. This is called a mode. Also how the content of the buffer is highlighted is defined in the “mode”. A set of functions, syntax highlighting and keybindings is called a major mode.

Whenever you switch between buffers, Emacs also switches the major mode depending on the selected buffer.

There are different modes for different purposes. Sometimes you want to share the same functionality across different types of buffers, so what you typically have in opened buffer is a mixture of different “modes”. A set of shared functions with keybindings is called a minor mode.

A package is a way to distribute such modes. Other editors call this a “plug-in”. There are repositories for the packages, such as MELPA. In case you want to install a new package, hit Meta-X and call the function list-packages-list.

Despite you can install packages and change settings manually, among the best practices is to keep Emacs configuration as a code. This is why you might find many “dotemacs“ repositories with configuration of other users in internet. It’s always a great source of insights of how other people use Emacs.

Typically users start their journey with popular packages and a standard or community-driven configuration, but with the time they recognize own repetitive tasks and create their own functions and assign them own keybindings. In this way they end up having an editor naturally fitting their workflows, saving significant amount of time every day.

Though, the learning curve is quite steep and there are good reasons for this. Emacs lisp is not so popular as Javascript or Python. The naming is always hard and is a something that is not easy to change over time. Other editors don’t use the same terminology as packages, buffers, modes, frames and windows. The syntax highlighting using regexps is a quite outdated technology nowadays. Even regexp library has a very special syntax from what users got used to. Another big issue is a combination of packages can be fragile, it’s a very common case when a package after update can break functionality of other packages.

Even key modifiers are named differently from other editors: Meta, Hyper, Super. My personal take on default keybindings - they’re aweful and RSI prone. Once you realize the Control key supposed to be a key closest to the spacebar, as it was designed for Space Cadet keyboards (it had also Meta, Hyper and Super keys), it became obvious how to make Emacs usage much more wrist friendly. Just do the same on your keyboard, map the control key to whatever key you have closest to the spacebar, in my case it’s cmd on mac keyboard.

Summary

In essence Emacs is an editing environment with set of functions, variables, syntax highlighting and keybindings.

Bare Emacs is not so feature reach, but packages ecosystem provides a good foundation for any type of everyday tasks and some of those are unmatched in another editors.

The real power comes after user learns enough fundamentals to start customizing Emacs to perform repetitive tasks faster.

Though, the learning curve can be steep for different reasons and it’s strongly advised to change default keybindings to improve ergonomic.