I’m writing an interactive function that I’d like to have remember the last argument the user supplied and use it as the default.
(defun run-rake (param) (interactive 'sTask: ') (shell-command (format 'rake %s' task)))
The first time the function is invoked I want it to remember the argument the user supplied so that the next time they invoke the function they can just press enter and it will use the value they supplied the previous time.
I can’t seem to find this in the documentation – how do you do this in elisp?
You can see how the
compilecommand does this. Bring up the help text for the compile command withC-h f compile, move the cursor over the name of the file that contains the function, then hitRETURN. This will bring up the source file forcompile.Basically, there’s a dynamic/global variable
compile-commandthat holds the last compile command. Emacs is a single-user, single-threaded system, so there’s really no need for much more. Also keep in mind that Elisp is a very old school Lisp, and variables have dynamic (call stack), not lexical, scope. In this kind of system it is natural to:Speaking of the
compilecommand, have you tried using it instead of your ownrun-rakefunction?