Emacs – Basic Configuration

As is well-known, Emacs is a powerful editor. Due to its infinite customizability and extensibility, in some sense, it is an operation system (OS) rather than an editor. This page briefly introduces how to customize it.

Set values for predefined variables

(setq variable value)

Bind shortcut keys

Set global shortcut key

(global-set-key key command)

where key is shortcut1, e.g. M-SPC, <f7>, and command is the command name with a prefix of single quotation mark.

Set shortcut key for specific modes

(define-key keymap key command)

where keymap is associated to some mode, e.g. c-mode-map. Usually, each mode has its own keymap, which is the mode name appended with -map.

Mode & hook

Emacs uses different modes to provide different editing environment. Generally, each file type has its own major-mode 2 and one or more minor-mode 3. Usually, each major-mode provides hook, mode name appended with -hook. When entering some major-mode, the functions in the corresponding hook will be provoked.

Third party extension

After the installation, the configuration includes two steps

(add-to-list 'load-path path-of-the-extension)
(require 'extension-name)

Footnotes:

1

The expressions of the shortcut key can be obtained by C-h k first and then treated as the input parameter of kbd, e.g. (kbd "M-SPC").

2

For the file type, define syntax highlight, indent, comment, etc.

3

It can be aded to major-mode. It defines the enhancement or decoration.