I am trying to setup a workflow wherein I generate Ledger files from different record files. Typically I like to view them in ledger mode after cleaning but if I make a change to the conversion, then I have to revert the file, reenable ledger mode and then run the clean operation. I tried making a function to do this for me, but I am encountering an error that I don't understand. Below is the function as written in my initialize code:

(use-package ledger-mode
  (defun ledger-revert ()
    (if not (eq major-mode 'ledger-mode)
    (revert-buffer t t t)

when I try to run the function to revert a ledger journal file I get:

>>> Symbol's value as variable is void: not

Any thoughts?

  • 5
    Replacing not (eq major-mode 'ledger-mode) with (not (eq major-mode 'ledger-mode)) would be a start. To help yourself here, you might want to read the Intro to Emacs Lisp manual (C-h i), or another introduction to Lisp, about symbols, variables, and functions in Lisp.
    – Drew
    Commented Feb 10, 2019 at 19:41
  • @Drew, thanks very much, and the tip for RTFM I suppose is always a good one to follow
    – Vince W.
    Commented Feb 11, 2019 at 16:49

1 Answer 1


You're missing a set of parentheses.

The line

(if not (eq major-mode 'ledger-mode)

should be

(if (not (eq major-mode 'ledger-mode))

To quote An Introduction to Programming in Emacs Lisp1,

When you evaluate a list, the Lisp interpreter looks at the first symbol in the list and then at the function definition bound to that symbol. Then the instructions in the function definition are carried out.

Without the parentheses around not, the symbol not it is interpreted as the first argument of the if function. Since not has not been assigned a value, it's value is void, hence the error message.

Emacs has a lot of tools to help you write Lisp2. A simple one is show-paren-mode. It will highlight matching pairs of parens:

enter image description here

You can enable show-paren-mode at startup by putting the following in your init.el:

(show-paren-mode 1)

1An Introduction to programming in Emacs Lisp is typically bundled with Emacs and can be found using C-h i. If you're running Debian, it's packaged separately.

2Built-in or 3rd party: electric-pair-mode, autopair.el, smart-parens.el, lispy, paredit, et cetera.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.