Skip to content

Instantly share code, notes, and snippets.

@j8takagi
Last active May 27, 2017 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j8takagi/aef5115954d40341996d7caa5a19b2d3 to your computer and use it in GitHub Desktop.
Save j8takagi/aef5115954d40341996d7caa5a19b2d3 to your computer and use it in GitHub Desktop.
A Emacs Lisp utilitiy for managing association list (alist), such as default-frame-alist. If key in ALIST, update VALUE of the key. Unless, cons cell (KEY . VALUE) is added
(defun update-or-add-alist (alist-var key value)
"If KEY in ALIST, update VALUE of the KEY.
Unless, cons cell (KEY . VALUE) is added."
(interactive)
(let (aconscell (alist (symbol-value alist-var)))
(if (setq aconscell (assoc key alist))
(unless (equal (cdr aconscell) value)
(setf (cdr aconscell) value))
(set alist-var (push (cons key value) alist)))
alist))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment