Questions tagged [eval]
57 questions
45
votes
6 answers
Org-mode 9: unable to eval code-blocks
My Emacs config lives inside of a .org file from which I tangle source blocks to a .el file. I could evaluate source blocks with C-c C-c
Today I updated to org-mode version 9 from org elpa and now evaluating a source block like
#+BEGIN_SRC…

rrogg
- 595
- 1
- 4
- 7
25
votes
3 answers
How to evaluate Elisp code contained in a string?
The question pretty much says it all: I have a string containing the source code for a valid Elisp expression, and I would like to evaluate it.
(In Python, for example, the expression eval("1 - 2 + 3") evaluates to 2.)

kjo
- 3,145
- 14
- 42
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
emacs --eval of multiple functions on command line
How do I evaluate multiple functions simultaneously using emacs --eval on command line? For example I want to combine the followings in a single command:
emacs --eval "(toggle-frame-maximized)"
emacs --eval "(sr-speedbar-toggle)"
I tried to wrap…

phonycollectibles
- 614
- 5
- 13
8
votes
1 answer
Evaluate some arguments to macro immediately
I am trying to call a macro (defined somewhere else; I can't change it), but I want to evaluate some of the arguments before the macro is expanded. Is this possible?
For example:
(defmacro foo (&rest args)
(mapcar (lambda (a) (message "arg: %s"…

0x5453
- 319
- 1
- 7
6
votes
1 answer
How do you recompile an .el source file and make it active in my current session
I have been writing some elisp code, current i have to open the file edit quit and reload emacs seems there must be a better way ?
I know i can recompile the current file but that does not seem to make my changes active with in emacs until i restart…

Oly
- 583
- 1
- 5
- 15
6
votes
1 answer
How to set a key binding conditional to evaluate a Lisp expression
I am thinking of binding C-x C-e to a single command, which does eval-last-sexp if there is no selection or eval-region if there is a selection. This is what I have tried:
(defun my/eval()
(interactive)
(if (region-active-p) (eval-region…

godblessfq
- 1,177
- 8
- 21
5
votes
2 answers
“A mutable object stops being mutable if it is part of an expression that is evaluated.”
GNU Emacs Lisp Reference Manual, section 2.9 Mutability:
A mutable object stops being mutable if it is part of an expression that is evaluated. For example:
(let* ((x (list 0.5))
(y (eval (list 'quote x))))
(setcar x 1.5) ;; The program…

shynur
- 4,065
- 1
- 3
- 23
5
votes
3 answers
How to replace the expression with evaluation result using Elisp interpreter?
When I do bulk calculations in a scratch buffer, it is annoying to have to delete the actual expressions after they are evaluated (I want them to be deleted on evaluation).
Example:
(+ 2 2)
Pressing C-u C-x C-e gives:
(+ 2 2)4
What I want instead…

A_P
- 662
- 4
- 21
5
votes
2 answers
elisp - print result not found after eval-buffer
Create a test.el file as below:
(print "hello world!")
Then run M-x eval-buffer. No output can be seen even in *Messages* buffer. where is the print output for this case?

lucky1928
- 1,622
- 8
- 28
5
votes
1 answer
Is there any difference between \` and backquote?
I was surprised to find that if I use M-x ielm, I get a literal backquote:
ELISP> (read "`foo")
`foo
However, if I use M-: (read "`foo") then *Messages* and the minibuffer show (\` foo).
Are these two equivalent? Why doesn't (equal (read "`foo")…

Wilfred Hughes
- 6,890
- 2
- 29
- 59
4
votes
3 answers
Set an Elisp var on the command line and read it in the init file
I'm trying to set a variable at load-time:
# emacs --eval '(defvar myvar t)'
Now, in this session, if I C-h v myvar RET I get a nice t. But if I put (message "MYVAR: %s" myvar) in my init file, I get a nasty Symbol's value as variable is void:…

yPhil
- 963
- 5
- 22
4
votes
2 answers
How to re-load a package?
The situation I have is this. First, I run
(require 'prolog)
...which loads the system's default version of prolog.el, and makes the variable prolog-mode-version available. It has value "1.22".
Now, I know that my personal copy of this package,…

kjo
- 3,145
- 14
- 42
4
votes
2 answers
Deep eager macroexpansion
This works:
(require 'clojure-mode)
(when (member 'clojure-mode my-packages)
(define-clojure-indent
(-> 1)
(->> 1)))
This gives the error Wrong type argument: listp, 1:
(when (member 'clojure-mode my-packages)
(require 'clojure-mode)
…

Resigned June 2023
- 1,502
- 15
- 20
3
votes
1 answer
How to handle end of file during parsing errors while reading a string?
I was trying to read and eval Lisp forms from a string using a loop, instead of just putting the string into a buffer and using eval-buffer to load everything in the string. That method was mentioned in another thread here.
The problem is that…

Kevin
- 1,308
- 8
- 20