Questions tagged [setf]
7 questions
7
votes
1 answer
Setf weird expansion
Trying to understand what setf can do, I called
(macroexpand '(setf (aref vec i) val))
⇒ (let* ((v vec) (v i)) (aset v v val))
This seems obviously wrong.
However I couldn't create an actual instance where (setf (aref .. fails. E.g.
(setq vec…

phs
- 1,095
- 6
- 13
4
votes
1 answer
How can I make `setf` work with `plist-get`?
There's no built-in setter for plist-get. Example:
(let ((pl '(:what (one))))
(push 'two (plist-get pl :what))
pl)
Error: let*: Symbol’s function definition is void: \(setf\ plist-get\)
How can I make setf work with plist-get?

user3496846
- 378
- 1
- 10
2
votes
2 answers
setf + alist-get but with "equal" instead of "eq"?
I got a suggestion to use setf to replace value in an alist: Replace element in a list / add in case of absence, with custom test/key functions
The example was provided, but it doesn't work if key is a string:
(let ((al (list (cons "a" 1) (cons "b"…

gavenkoa
- 3,352
- 19
- 36
2
votes
1 answer
`cl-incf` returns inconsistent values
(setq ali '())
>>> nil
(cl-incf (alist-get 'a ali 0))
>>> ((a . 1))
(setf (alist-get 'b ali) 0)
>>> ((b . 0) (a . 1))
(cl-incf (alist-get 'b ali 0))
>>> 1
As you can see, cl-incf returns different kinds of values in the second and the fourth…

grepcake
- 145
- 7
2
votes
0 answers
Is there a generalized setter for buffer-modified-p?
It is very simple to define a simple generalized setter for buffer-modified-p:
(gv-define-simple-setter buffer-modified-p set-buffer-modified-p)
That enables constructs like:
(with-current-buffer "test.cc"
(cl-letf (((buffer-modified-p) t))
…

Tobias
- 32,569
- 1
- 34
- 75
1
vote
1 answer
How to find if an Emacs lisp function is setf-able?
Emacs Lisp setf macro allows you to set generalized variables. You can, for example change the size of the current window with the following form:
(setf (window-height) 10)
The macro will translate the above code to:
(progn …

PRouleau
- 744
- 3
- 10
0
votes
3 answers
How do I remove :width and :height from an image created with create-image?
I am trying to make jabber.el support images sent from e.g. Conversations.
I download the image using url-retrieve-synchonously and call create-image to get an image which I can then use with insert-image. This works as expected.
I would like,…

asjo
- 1,037
- 8
- 12