aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/subr.el26
1 files changed, 24 insertions, 2 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 6dc53cd7201..f1a1dddd81c 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -756,9 +756,31 @@ Elements of ALIST that are not conses are ignored."
756If KEY is not found in ALIST, return DEFAULT. 756If KEY is not found in ALIST, return DEFAULT.
757Use TESTFN to lookup in the alist if non-nil. Otherwise, use `assq'. 757Use TESTFN to lookup in the alist if non-nil. Otherwise, use `assq'.
758 758
759This is a generalized variable suitable for use with `setf'. 759You can use `alist-get' in PLACE expressions. This will modify
760an existing association (more precisely, the first one if
761multiple exist), or add a new element to the beginning of ALIST,
762destructively modifying the list stored in ALIST.
763
764Example:
765
766 (setq foo '((a . 0)))
767 (setf (alist-get 'a foo) 1
768 (alist-get 'b foo) 2)
769
770 foo => ((b . 2) (a . 1))
771
772
760When using it to set a value, optional argument REMOVE non-nil 773When using it to set a value, optional argument REMOVE non-nil
761means to remove KEY from ALIST if the new value is `eql' to DEFAULT." 774means to remove KEY from ALIST if the new value is `eql' to
775DEFAULT (more precisely the first found association will be
776deleted from the alist).
777
778Example:
779
780 (setq foo '((a . 1) (b . 2)))
781 (setf (alist-get 'b foo nil 'remove) nil)
782
783 foo => ((a . 1))"
762 (ignore remove) ;;Silence byte-compiler. 784 (ignore remove) ;;Silence byte-compiler.
763 (let ((x (if (not testfn) 785 (let ((x (if (not testfn)
764 (assq key alist) 786 (assq key alist)