Eliminating magic strings from ELisp's (interactive)
17 March 2009 (programming language lisp)If you hate magic string API's as much as I do, you'll like this macro replacing Emacs's (interactive) declaration. It allows you to rewrite the following function definition:
(defun foo (pos str)
"Foobarize the current cursor position and some text entered by the user at the prompt"
(interactive "d\nsPlease enter a value for str: "
(foobarize pos str)))
"Foobarize the current cursor position and some text entered by the user at the prompt"
(interactive "d\nsPlease enter a value for str: "
(foobarize pos str)))
into the much cleaner form below:
(defun/interactive foo ((pos :pos) (str "Please enter a value for str"))
"Foobarize the current cursor position and some text entered by the user at the prompt"
(foobarize pos str)))
"Foobarize the current cursor position and some text entered by the user at the prompt"
(foobarize pos str)))
It currenty only supports :pos, :region and strings entered at the prompt, but the code is trivial to extend to other initializers.