Emacs Lisp Naming Convention

By Xah Lee. Date: .

reddit discussion, on emacs naming convention

elisp naming convention 2017-01-22
source reddit question

many gnu elisp conventions, are kinda vague, some are out-dated, some are ill-designed.

many packages outside GNU emacs do not adhere to them, but are tolerated. For example, the most popular packages on MELPA, dash, s, break these conventions.

it's a gray area, between conservative and progressive.

if you chose progressive, the problem is that huge amounts of existing lisp code are not gonna change (lots work, risking bug to fix but little benefit, or packages not maintained but still used, etc.), you end up with inconsistency.

if you chose conservative, then you reduce progress and adoptation.

For example, let's say the naming convention. Besides the prefix:

• predicate function names could end in “?” (as in Scheme/Racket Lisp, ruby, clojure) instead of “p”. Since question mark is more intuitive, is easier to identify, and can be syntactically verified by machine. (p can't because not all functions ending in p is a predicate.)

• the double dash for internal methods (aka auxiliary functions) is kinda unsaid convention, and code out there may or may not conform. (if we go strict about this, you'll find huge amount of functions need to be renamed.)

• variable beginning with low line _ as form-filler unused var is another unsaid convention. It kinda came from modern (say after 2010) practices in other langs (i think python ruby).

• in function doc string, it's GNU emacs convention to use ALLCAPS for parameters. This is also not a perfect convention, since elisp is case sensitive. This make it hard to actually have parameters that's ALLCAP or camelCase or single capital letter such as Z. Also, using ALLCAPS is a weak, ambiguous markup, since it prevents the normal English convention of using ALLCAPS for emphasis.

but as most coding convention goes, they are not systematically designed. They came by-and-by via practice and evolution. It'd be nice if the language enforce syntactic conventions. For example, var of ALLCAPS has semantics of global var. (sigils in perl, ruby, golang, and other lang feature these) An extreme case would be syntax algebra, where the syntax alone is the semantics and can be processed/manipulated (like highschool algebra). Formal Languages are such case.

Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboards for Emacs

If you have a question, put $5 at patreon and message me.