Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to understand this form (interactive (list 'interactive)) in Emacs Lisp?

Tags:

emacs

elisp

I was found some codes like this,

 1 (require 'cl-lib)
 2 (require 'company)
 3 
 4 (defun company-sample-backend (command &optional arg &rest ignored)
 5   (interactive (list 'interactive))
    ...
   )

but how to understand line 5?

like image 294
OYYZ Avatar asked Apr 03 '17 08:04

OYYZ


People also ask

What does interactive do in Lisp?

The interactive-form symbol property can be used to add an interactive form to an existing function, or change how its arguments are processed interactively, without redefining the function.

What is a function interactive?

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.

What is Emacs Lisp used for?

Emacs Lisp is a dialect of the Lisp programming language used as a scripting language by Emacs (a text editor family most commonly associated with GNU Emacs and XEmacs). It is used for implementing most of the editing functionality built into Emacs, the remainder being written in C, as is the Lisp interpreter.

Is Emacs functional Lisp?

Emacs Lisp is not a purely functional programming language since side effects are common. Instead, Emacs Lisp is considered an early functional flavored language. The following features contribute to the functional flavor: its notation is functional (including a lambda calculus-like notation – see LambdaExpression)


1 Answers

The argument to the interactive declaration is either a string or an elisp form which, when evaluated, returns a list of argument values for the function.

In this instance the declaration uses a form returning a list. The form is:

(list 'interactive)

which is a form that returns a list of a single item, being the symbol interactive

The argument list for the function was:

(command &optional arg &rest ignored)

Therefore, when this function is called interactively, the argument command will have the value interactive

like image 52
phils Avatar answered Oct 13 '22 10:10

phils