Questions tagged [read]
30 questions
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
12
votes
1 answer
Meaning of period in (. 123)
I learnt . /path/to/file in bash is used to execute a file. Just out of curiosity, I eval something like the following in Emacs
(. 123)
⇒ 123
(read "(. 123)")
⇒ 123
It looks like Emacs simply reads (. 123) as 123, what happened?

xuchunyang
- 14,302
- 1
- 18
- 39
6
votes
1 answer
How can I convert a string form of a list to an actual list?
I would like to convert these two strings
"(a b c)"
"(9 . 3)"
to these
(a b c)
(9 . 3)
I'd had some luck with the first one evaluating this,
(mapcar 'intern (split-string (string-trim "(a b c)" "(" ")")))
basically, removes parentheses from string,…

C11g
- 333
- 1
- 7
4
votes
3 answers
the Term “Hash Notation“ in the Elisp Manual
I'm reading GNU Emacs Lisp Reference Manual, and I see the phrase "hash notation".
Two places in the document seem to have different interpretations, so I have 2 questions.
2.1 Printed Representation and Read Syntax:
...... some types have no…

shynur
- 4,065
- 1
- 3
- 23
4
votes
1 answer
Read first N lines of file into list
The general way this seems to be done using Elisp is to first read the entire file using something like insert-file-contents-literally or find-file-no-select, using split-string on a newline, and then removing the unwanted elements:
(defun first-n…

Lorem Ipsum
- 4,327
- 2
- 14
- 35
4
votes
2 answers
How to read elisp file into s-expression?
I have a file of elisp code, say foo.el. I want to turn the content into a s-expression, so that I can play with it. Right now, I use the following method:
Read foo.el into a string.
Turn the string into a s-expression using read.
The code is as…

Alex Vong
- 161
- 5
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
2
votes
1 answer
When does Emacs enter command loop?
I'm reading (info "(elisp) Command Overview"):
Variable: post-command-hook
: ... ...
: This hook is also run when Emacs first enters the command loop (at which point this-command and last-command are both nil).
Users may need to know the exact…

shynur
- 4,065
- 1
- 3
- 23
2
votes
0 answers
Inconsistency between read-key and read-key-sequence-vector w.r.t. conditional application of local-function-key-map translations
While working with read-key-sequence-vector and read-key, I found that the former applies the local-function-key-map translations in a conditional manner but the latter does not. I am using Emacs 28.1 on a macOS system.
The function…

Susam Pal
- 161
- 5
2
votes
0 answers
Distinguish expected from erroneous end-of-file in read function?
What is the correct way to use (read (current-buffer)) to read from a buffer until the end of the file is reached?
When no forms remain in a buffer, Emacs signals an error:
(with-temp-buffer
(save-excursion
(insert "(first)…

kdb
- 1,561
- 12
- 21
2
votes
1 answer
What does hash s indicate in lisp
This is the result of
M-: (elfeed-search-selected :ignore-region)
#s(elfeed-entry
("www.cbc.com.com" . "https://www.cbc.com.com/defg/Polyglot-programming_%7E017e364530a5359046?source=rss")
"Polyglot programming - Abc"
…

american-ninja-warrior
- 3,773
- 2
- 21
- 40
2
votes
1 answer
How should you read a Lisp file as Lisp for processing without condition-case?
To help catch predictable errors, I've written my own linting tasks that read the code and report any inconsistencies it finds. One of the hackier pieces to this right now is the following function:
(defun lint-get-forms (filename)
"Read FILENAME…

Sean Allred
- 6,861
- 16
- 85
2
votes
1 answer
Read a config file and get some value into elisp variable
I'm trying to read a value of variable context from the config file. I use something like this (but have got an error..):
(with-current-buffer
(insert-file-contents "/home/user/liquibase.properties")
(keep-lines "contexts" point-min…

egor7
- 123
- 6
2
votes
1 answer
How to add-to-list to read-in file contents
When I do this (setq v (f-read-text "s.el")) where s.el is of this form
((thing1 . thing2) (thing3 . thing4))
I get v back as one long string. And (setq v (append (f-read-text "s.el"))) doesn't seem to change things to a list. I want to do a push…

147pm
- 2,907
- 1
- 18
- 39
1
vote
2 answers
Make the minibuffer prompt always have a default argument
Is it possible to make the first history item available as the default argument when running commands like eval-expression and goto-line?
I'd like to be able to just press enter to use the previous value.
I started writing a wrapper around goto-line…

Matt
- 15
- 6