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?
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.
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 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.
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)
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
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