1

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                                                                                           
  (enlarge-window                                                                                
   (- 10                                                                                         
      (window-height)))                                                                          
  10)

My question: Is there a way to find out dynamically whether an Emacs function is "setf-able" like window-height is?

I searched in the GNU EMacs Common Lisp Emulation manual and could not find and answer to my question.

4
  • 2
    They are (elisp) Generalized Variables which seems have become a core part of Emacs Lisp language, you can find infomation there, such as list of predefined setf-able forms, you can also know if it's setf-able by M-x emacs-lisp-macroexpand, besides (get 'window-height 'gv-expander) returns a function if it's setf-able. – xuchunyang Dec 5 '20 at 9:30
  • @xuchunyang: Consider posting that as an answer. – Drew Dec 5 '20 at 16:24
  • @xuchunyang. Using (get 'window-height 'gv-expander) is the answer I was looking for. Note that the list of functions in the Setf Extensions section of the Emacs Common Lisp Extensions and the one in the section "The set Maco" in the Elisp Manual differ. I wanted to be able to detect them via code. Thanks! I agree with Drew, you should post it as an answer. – PRouleau Dec 5 '20 at 16:45
  • @Drew and PRouleau Done. – xuchunyang Dec 5 '20 at 18:46
4

Check the value of symbol's gv-expander property, for "setf-able" functions, the value is non-nil (and a function), e.g.,

(functionp (get 'window-height 'gv-expander))
;; => t

for other functions, the value is nil, e.g.,

(get 'length 'gv-expander)
;; => nil

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.