1

This is how you check if an object is a built-in function:

(subrp (symbol-function 'assoc))
=> t

Is there an equivalent way to do this for variables as well?

Drew
  • 75,699
  • 9
  • 109
  • 225
John DeBord
  • 550
  • 3
  • 13

1 Answers1

0

I assume that by "built-in" you mean a variable defined in C. This should do it:

(defun built-in-var-p (variable)
  "Return non-nil if VARIABLE is defined in C source code."
    (let ((file-name  (find-lisp-object-file-name variable 'defvar)))
      (and file-name  (eq file-name 'C-source))))
Drew
  • 75,699
  • 9
  • 109
  • 225
  • Internally, `find-lisp-object-file-name` calls `help-C-file-name`. Is there a reason to prefer one over the other? – John DeBord Aug 26 '21 at 02:50
  • @JohnDeBord: No, not that I know of. I basically took this code from `describe-variable` etc. in `help-fns.el`. Please consider adding your comment that suggests `help-C-file-name` as an answer! Thx. – Drew Aug 26 '21 at 18:05