use this tag for Elisp `functions` for their usage, definitions, re-definitions, defining aliases, and other standard features of function execution fundamental to Lisp programming languages. Add additional Elisp tags when the functions are about specific Emacs features.
Questions tagged [functions]
235 questions
43
votes
1 answer
What is the difference between a function and a command?
When posting questions and answers here, people sometimes use the terms "function" and "command" interchangeably. In other cases, people only use one of the two terms to discuss specific pieces of code. As their posts usually focus on other topics,…

itsjeyd
- 14,586
- 3
- 58
- 87
35
votes
4 answers
When to sharp-quote a lambda expression?
Q: When, if ever, is it useful to sharp-quote a lambda, and when, if ever, must we not sharp-quote a lambda?
People use lambdas in three ways:
plain: (lambda (x) x)
quoted: '(lambda (x) x)
sharp-quoted: #'(lambda (x) x)
This SO thread discusses…

Dan
- 32,584
- 6
- 98
- 168
34
votes
1 answer
What is the difference between ' and #' in front of a symbol?
I'm a little new to Emacs.
When looking at some of the configurations, I found there are two types command in "add-hook".
(add-hook 'LaTeX-mode-hook #'LaTeX-math-mode)
and
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
This has confused me for a…

X.Arthur
- 443
- 4
- 9
29
votes
2 answers
Can functions access their name?
In C there is the magic variable __func__ that holds the current function name. In Bash, there is an array FUNCNAME holding the names of all functions in the calling stack !!!
Is there a similar thing in Emacs Lisp? Or any simple way for a function…

phs
- 1,095
- 6
- 13
24
votes
1 answer
Curiosity: What does progn stands for?
According to Emacs documentation:
progn is a special form in `C source code'.
(progn BODY...)
Eval BODY forms sequentially and return value of last one.
What does progn stands for (or its origin)?
Useage: Is it equivalent to Clojure's -> macro?

Nick
- 4,423
- 4
- 24
- 41
23
votes
2 answers
Difference between load-file and load
I went through the documentation of both the function but they don't seem to shed much information. What is the actual difference between them apart from the fact that load is a built-in function in C source code whereas load-file is an interactive…

Sibi
- 3,603
- 2
- 22
- 35
20
votes
2 answers
How do you return from a function at an arbitrary point?
How do you return early from a function before it's ended? For example:
(defun my-func ()
"for example."
(unless something (return nil))
; continue as usual...
(+ 42 1))

ocodo
- 1,202
- 11
- 20
20
votes
2 answers
When should sharp quotes be used?
I see sharp quotes being used in other people's eLisp code, and I use them myself, but I'm not completely clear on when they are appropriate and when not.
Could anyone clarify on exactly when it's appropriate to use sharp quotes and when ordinary…

izkon
- 1,798
- 10
- 23
16
votes
1 answer
Why can't I bind my function to a key or call it with M-x?
I wrote a function, and I want to call it via M-x, and bind it to a key. This is my function:
(defun my-function ()
(message "This is a great function"))
If I try to call it with M-x my-function, I get the error: [no match] in the…

Tyler
- 21,719
- 1
- 52
- 92
10
votes
4 answers
How to obtain a list of all functions exclusively provided by a certain major mode
This question in inspired by https://stackoverflow.com/q/605785/.
By M-x describe-function I can get a list of all
interactive or nonintractive functions available in the current state
of emacs.
If an specific mode is activated (e.g.…

Name
- 7,689
- 4
- 38
- 84
9
votes
6 answers
When is the first element in the argument list regarded as a function symbol and when not?
I'm learning elisp, and I just learned that the first element of a list is interpreted as a function symbol. I then learned how to define a function with defun. Here's the example from An Introduction to Programming in Emacs Lisp
(defun…

norio
- 191
- 4
9
votes
1 answer
Symbol’s function definition is void
I am trying to make an interactive toggle in emacs 27.0.90
When I eval-region no warnings or errors are shown.
However, when I do (helm/toggle-frame) in ielm it throws
Symbol’s function definition is void: helm-in-frame-p
Here is the code,
(let…

546756ryd
- 93
- 1
- 1
- 3
9
votes
1 answer
Override a function locally, but allow calls to the original function
The advice feature allows modifying the behavior of a function globally. An advice definition can make calls to the original function.
(defadvice foo
(around foo-bar activate compile)
"Always set `qux' to t when running `foo'."
(let ((qux t))
…

Gilles 'SO- stop being evil'
- 21,702
- 4
- 53
- 89
9
votes
1 answer
How to find out where a function is called from (backtrace/stacktrace)?
I've hit a problem that region is deactivated (in transient-mark-mode). The function deactivate-mark is called and I would like to find out where (and why) it is called from.
I tried M-x debug-on-entry RET deactivate-mark and it stops but I found no…

Gracjan Polak
- 1,082
- 6
- 21
8
votes
2 answers
Argspec or arity of a bytecode function in Emacs 24
I have code that tests the arity of a function. I use it to determine whether optional arguments added in recent versions of a package are present. It calls subr-arity for built-in functions and parses the arglist of bytecode objects and…

Gilles 'SO- stop being evil'
- 21,702
- 4
- 53
- 89