Elisp: Define a Command
What is a Command
A command is a emacs lisp function that can be called interactively.
By execute-extended-command 【Alt+x】.
Define a Command
to define a command, you define a function and add
(interactive)
after the doc string.
(defun my-yes () "Insert YES at cursor position." (interactive) (insert "YES"))
Command Template
Here is a function definition template that majority of elisp commands follow.
(defun my-command () "One sentence summary of what this command do. Less than 70 chars here. More details here. Be sure to document the parameters. Be sure to mention the return value, if any. Lines here should not be indented." (interactive) (let (var1 var2 etc) ;; do something here ;; last expression is returned ))
Reference
Elisp, Function
- Elisp: Define Function
- Elisp: Define a Command
- Elisp: Function Parameters (optional, rest)
- Elisp: Function Keyword Parameters (Named Parameters)
- Elisp: Docstring Markup
- Elisp: Lambda Function
- Elisp: Exit Loop or Function (throw, catch)
- Elisp: Apply Function, funcall, identity
- Elisp: Types of Functions