built-in special variables with simple names in Emacs Lisp

Following is the list of all special variables with names without hyphens (as of Emacs 24.3.1). These should not be used as names of lexically scoped variables.

debugger features nil noninteractive obarray

The list is obtained with this code:

(require 'cl)
(require 'cl-lib)
(print
 (sort
  (let ((syms nil))
    (mapatoms (lambda (s)
                (if (and (special-variable-p s)
                         (not (string-match-p "-" (symbol-name s))))
                    (setq syms (cons s syms)))))
    syms)
  'string<))

Instead of memorizing them, you can have Emacs highlight those names by putting the following code in your init file:

(eval-after-load 'lisp-mode
  '(progn
     (defconst my-special-variables-without-hyphen
       '(debugger features nil noninteractive obarray)
       "list of special variables with names without hyphen")
     (defconst my-regexp-special-variables-without-hyphen
       (eval `(rx bow (or ,@(mapcar #'symbol-name my-special-variables-without-hyphen)) eow)))
     (font-lock-add-keywords 'emacs-lisp-mode
                             `((,my-regexp-special-variables-without-hyphen . font-lock-keyword-face)))))

The number of built-in special variables with simple names is decreasing on each release of Emacs. For example, pi, argv, argi used to be special variables but no more.

This entry was posted in Emacs and tagged , . Bookmark the permalink.

2 Responses to built-in special variables with simple names in Emacs Lisp

  1. Pingback: invasion of special variables in Emacs Lisp | Yoo Box

  2. Pingback: Invasion of local variables in Emacs Lisp | Yoo Box

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s