I’ve got a variable in Emacs called my-var that I’d like to set whenever I press C-v. How do I do that? I tried this:
(defun set-my-var (value) 'set my var' (interactive) (defvar my-var value 'a variable of mine') ) (global-set-key '\C-v' 'set-my-var)
But that fails:
call-interactively: Wrong number of arguments: (lambda (value) 'set my var' (interactive) (defvar my-var value 'a variable of mine')), 0
Actually, defvar doesn’t do what you think it does either: it only changes the value IF there was no value before. Here’s a chunk that does what you’re looking for, using the CTRL-u argument:
and here’s an example, code from the
*scratch*buffer