Emacs Lisp function often start like this:
(lambda () (interactive) ...
What does "(interactive)" do?
A Lisp function becomes a command when its body contains, at top level, a form that calls the special form ` (interactive...) '. This special form does nothing when executed, but its presence in the function definition indicates that interactive calling is permitted.
Emacs Lisp supports multiple programming styles or paradigms, including functional and object-oriented. Emacs Lisp is not a purely functional programming language since side effects are common. Instead, Emacs Lisp is considered an early functional flavored language.
By default, Common Lisp is lexically scoped, that is, every variable is lexically scoped except for special variables. By default, Emacs Lisp files are dynamically scoped, that is, every variable is dynamically scoped.
Just to clarify (it is in the quoted docs that Charlie cites) (interactive)
is not just for key-bound functions, but for any function. Without (interactive)
, it can only be called programmatically, not from M-x
(or via key-binding).
EDIT: Note that just adding "(interactive)" to a function won't necessarily make it work that way, either -- there could be many reasons functions are not interactive. Scoping, dependencies, parameters, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With