by natrys · 2y ago · 0 comments
(setf (buffer-string) "hello")
I thought this was just bananas, turns out that Elisp setf simply has a bunch of hardcoded rules for matching getters/setters for even a lot of non-standard data structures like Buffer that are Emacs specific. So the above gets rewritten to: (insert (prog1 "hello" (erase-buffer)))
It's not exactly AGI but still very cool. (gv-define-setter buffer-string (store)
`(insert (prog1 ,store (erase-buffer))))
Unfortunately, it is marked obsolete since 29.1. The NEWS says:* Many seldom-used generalized variables have been made obsolete. Emacs has a number of rather obscure generalized variables defined, that, for instance, allowed you to say things like:
(setf (point-min) 4)
These never caught on and have been made obsolete. The form above,
for instance, is the same as saying (narrow-to-region 4 (point-max))