32

As explained in other answers, evaluating a defvar form using eval-last-sexp does not reset the default value. Instead, you can use eval-defun (bound to C-M-x in emacs-lisp-mode by default), which implements the behaviour you want as a special exception: If the current defun is actually a call to defvar or defcustom, evaluating it this way resets the ...


21

Authoring edebug: Step-by-step debugging of Elisp code. checkdoc: Learn about style errors in your comments and docs. elint: Linter for Emacs Lisp. paredit: Manipulate lisp code as trees instead of lines. Never have unbalanced parentheses. lispy: vi-like alternative / superset of paredit. Additionally includes shortcuts for outlines, narrowing, edebug, ...


18

(defconst nil ()) seems to have the right effect; note that nil and an empty list are indistinguishable in Emacs Lisp. I looked at lread.c:4034 to see how nil is created in an obarray. Note the comment at line 3896 in lread.c: /* There are plenty of other symbols which will screw up the Emacs session if we unintern them, as well as even more ways to ...


10

Call unload-feature to undefine all symbols that were defined as part of loading an Elisp source or byte-compiled file. Make sure that your file ends by calling provide at the end. This assumes that you loaded the file with one of the load functions or via require, it won't undefined symbols defined by C-M-x (eval-defun) or similar mechanisms. If you really ...


7

Use makunbound to remove the use of a symbol as a dynamic variable (i.e., to void its symbol-value). Use fmakunbound to remove the use of a symbol as a function (i.e., to void its symbol-function). Use mapatoms to iterate over all symbols. Act on each whose symbol-name is matched by the particular prefix you are interested in: call both makunbound and ...


5

Like the other answers say, this is just the way defvar works, but you can get around it, this is elisp after all. You can temporarily redefine how defvar works if you'd like and during that time, reload the packages you'd like to reset. I wrote a macro where during the evaluation of the body, defvars values will always be reevaluated. (defmacro my-fake-...


3

The defvar is being evaluated and doing exactly what you've specified. However, defvar only sets an initial value: The optional argument INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void. So to achieve what you want you would either need to unbind the variable before re-evaluating, e.g. (makunbound 'foo) or use setq to ...


1

The following macro was created by tracing eval-defun to its supporting functions and modifying it so that it is no longer necessary to evaluate a region of a particular buffer. I needed help in the related thread Converting an expression to a string, and @Tobias came to the rescue -- teaching me how to convert the imperfect function into a macro. I don't ...


Only top voted, non community-wiki answers of a minimum length are eligible