Emacs Lisp: Check If a {function, variable, feature} is Defined/Loaded

By Xah Lee. Date: . Last updated: .

This page shows you how to check if a {function, variable} is defined, or if a “feature” is loaded, and find out what Operating System your emacs is running on.

Check Function

Check if a function is defined.

;; check if a function is defined
(fboundp 'info)                         ; t
(fboundp 'setq)                         ; t

(fboundp 'xyz)                          ; nil

Check Variable

Check if a variable is defined.

;; check if a variable is defined
(boundp 'auto-mode-alist)               ; t
(boundp 'default-input-method)          ; t
(boundp 'nil)                           ; t

(boundp 'xyz)                           ; nil

The fboundp actually check a symbol's function cell. Similarly, the boundp checks a symbol's value cell. 〔➤see Emacs Lisp Symbol

Check Feature

Check if a “feature” is loaded.

;; check if a “feature” (package) has been loaded
(featurep 'ibuffer)

〔➤see Emacs Lisp's Library System: What's require, load, load-file, autoload, feature?

See also: Emacs Lisp: Find/Determine OS and Emacs Version.

Like it? Buy Xah Emacs Tutorial. Thanks.