Search code examples
elisp

How to get a comprehensive listing of all defined variables (and their values)?


How can one list all the globally defined variables (ideally with their global-scope values) for the current Emacs session?


Solution

  • Looking at the source code for describe-variable and obarray, it seems that the following should give you what you want.

    (defun global-bindings ()
      (let (res)
        (mapatoms (lambda (vv)
                    (when (and (boundp vv)
                               (not (keywordp vv))
                               (get vv 'variable-documentation))
                      (push (cons vv (symbol-value vv)) res))))
        res))