Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does (interactive) mean in an Emacs Lisp function?

Tags:

emacs

lisp

Emacs Lisp function often start like this:

(lambda () (interactive) ... 

What does "(interactive)" do?

like image 829
mike Avatar asked Dec 18 '08 19:12

mike


People also ask

What is an interactive function?

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.

Is Emacs functional Lisp?

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.

Is Emacs Lisp the same as Lisp?

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.


1 Answers

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.

like image 68
Michael Paulukonis Avatar answered Oct 02 '22 16:10

Michael Paulukonis