Elisp: 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 Elisp: load, load-file, autoload]

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

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs

Emacs Tutorial

Emacs Init

Emacs Keys

ELisp

ELisp Examples

ELisp Write Major Mode


Emacs Lisp

Basics

Basic Functions

Writing Command

Writing Script

Lisp Data Structure

Lisp Symbol

Elisp Misc