Elisp: Symbol Property List

By Xah Lee. Date: . Last updated: .

Each lisp symbol is associated with a “property list”.

[see Elisp: Property List]

This property list is stored in the symbol's property list cell. [see Elisp: Lisp Symbol]

Emacs lisp property list is used extensively in emacs. It is also very useful if you want to write a function with state. You can store the state info with the symbol itself, instead of using a global variable.

Set Whole Plist

(setplist SYMBOL NEWPLIST) → Set SYMBOL's property list to NEWPLIST, and return NEWPLIST.

;; set the value of symbol ff's property list
(setplist 'ff '(a 1 b 2))

Get Whole Plist

(symbol-plist SYMBOL) → Return SYMBOL's property list.

;; get the value of symbol ff's property list
(symbol-plist 'ff )

Add/Set a Key's Value

(put SYMBOL PROPNAME VALUE) → Store SYMBOL's PROPNAME property with value VALUE.

;; set the value of key xx, of symbol ff's property list
(put 'ff 'xx 5)

Get a Key's Value

(get SYMBOL PROPNAME) → Return the value of SYMBOL's PROPNAME property.

;; get the value of key xx, of symbol ff's property list
(get 'ff 'xx)

Reference

(info "(elisp) Symbol Properties")

Example of Using Symbol Properties

Elisp: How to Write a Toggle Command

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial

Emacs Tutorial

Emacs Init

Emacs Keys

ELisp

ELisp Examples

ELisp Write Major Mode


ELisp

Basics

Basic Functions

Writing Command

Writing Script

Lisp Data Structure

Lisp Symbol

Elisp Misc