Install Emacs

2025-02-08, Sat

Install Emacs tends out to be more complicated than I thought. This log file intends to record huccups I've encountered.

1. on Debian GNU/Linux

Debian packages are provided in separate sections1, and emacs is available in the main section. However, this package lacks all the built-in documentation, which is somehow provided in the non-free section through package emacs-common-non-dfsg. Without documentation, the claim of "self-documenting editor" doesn't stand, so a bit tweak is needed.

  1. Open /etc/apt/sources.list and add "non-free" section after "main"
  2. Run "apt-get update", as usual
  3. Run "apt-get install emacs emacs-common-non-dfsg"

2. on macOS

The GNU site already provides instructions to install pre-built binaries of Emacs on macOS 2, 3. Follow any one would be sufficient.

However, things became tricker when I tried to compile from source.

First, install libraries required, in reverse order:

  • gnutls
  • nettle
  • gmp
  • libtasn1
  • help2man

The process was straightforward when I compiled these libraries from source one by one, …until gnutls-3.7.11, which is the current stable version provided on the official site4. When compiling from the source file downloaded, there was error thrown for file lib/system/certs.c. Turns out there is a one line change needed in the declaration of osstatus_error, like this:

static int osstatus_error(OSStatus status)

This problem was resolved long time ago in the master branch5. So it's not like a big issue anymore. Nevertheless, the experience worths a note.

Key Takeways

  • When there is error thrown while compiling source code from renowned resource, take a closer look at the error message. No need to get panic, upset, or scared.
  • If a solution is found for the error, consider to submit a patch to the source repo in order to give something back to the community.

3. Notes on Common Commands

This section records common commands & keybindings for some modes, major or minor.

3.1. Major mode c-mode

Key Binding Description
C-c C-e c-macro-expand Expand C macros in the region, using the C preprocessor

3.2. Major mode org-mode

Key Binding Description
C-c C-c org-ctrl-c-ctrl-c Multi-purpose command that does things depending on context

3.3. Major mode emacs-lisp-mode

Key Binding Description
C-c C-e elisp-eval-region-or-buffer Evaluate forms in the active region or whole buffer
C-M-i completion-at-point Perform completion on the text around point

3.4. Major mode lisp-interaction-mode (for *scratch*)

Key Binding Description
C-j eval-print-last-sexp Evalute sexp before point

4. Notes on Common Practices

4.1. sudo edit file

Use TRAMP mode6 to sudo open and edit file by append /sudo:: at the beginning of the file name, e.g.

find-file (C-x C-f)
/sudo::/path/to-file

4.2. Sample Init Config

Sample init config could be found in the Emacs manual7 or online8. Nevertheless, I'll put another snippet below for reference:

;; ref: ~/.emacs.d/init.el
;;
;; save & restore desktop-session
(desktop-save-mode 1)
;; enable display of line number across all windows
(global-display-line-numbers-mode)

;; show column number in the mode line
(column-number-mode)
;; disable tool-bar
(tool-bar-mode 0)

;;; ============================================================
;;; configs that applies to speicifc mode or
;;; depends on external program
;;; ============================================================
;; running external lisp from within Emacs
;; in this case, it is SBCL that is being used
(setq inferior-lisp-program "/usr/local/bin/sbcl --noinform")

;; unlock the treemacs window width
(setq treemacs-width-is-initially-locked nil)

Footnotes: