Emacs Lisp Coding Style

By Xah Lee. Date: .

emacs lisp coding style, multi line setq

emacs lisp just did a refactoring. combine multiline setq into 1 line. e.g.

(setq $p1 (region-beginning)) (setq $p2 (region-end))

to

(setq $p1 (region-beginning) $p2 (region-end))

the syntactic grouping helps indicate semantic unit of code. similarly, i tend to add (progn) even when not necessary.

elisp setq 2018-10-31
elisp setq 2018-10-31 https://github.com/xahlee/xah-fly-keys/commit/9f122c3d680f66416c12a87db7db7a0844505120

over the years, my elisp coding style changed slightly. Before, i never put value in let. e.g. (let (x y) (setq x 3) … ) but now i do (let ((x 3) y) … ) when x is meant to not change value.

This form (let (x y) … ) is simpler and more readable. Simplicity is the king in coding. Putting value in let doesn't do anything semantically, and elisp isn't typed. You can't declare constants. Now, i put constant in let. It helps a little to indicate intention of not changing the var. (note, this is problematic, because it's also common to initialize a value in let. So, the advantage of intention being a constant is gone, depending whose code you are reading)