Elisp: Symbol Property List

By Xah Lee. Date: . Last updated: .

What is Symbol Property List

Each lisp Symbol is associated with a Property List .

This property list is stored in the symbol's property list cell.

Symbol 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.

Get Whole Plist

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

Set Whole Plist

setplist
(setplist SYMBOL NEWPLIST)
Set SYMBOL's property list to NEWPLIST, and return NEWPLIST.
(setplist 'ff '(a 1 b 2))

Get a Key's Value

get
(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)

Add or Set a Key

put
(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)

Example of Using Symbol Properties

Reference

Emacs Lisp, list

Special Lists

List Structure