diff options
| -rw-r--r-- | lisp/subr.el | 26 |
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." | |||
| 756 | If KEY is not found in ALIST, return DEFAULT. | 756 | If KEY is not found in ALIST, return DEFAULT. |
| 757 | Use TESTFN to lookup in the alist if non-nil. Otherwise, use `assq'. | 757 | Use TESTFN to lookup in the alist if non-nil. Otherwise, use `assq'. |
| 758 | 758 | ||
| 759 | This is a generalized variable suitable for use with `setf'. | 759 | You can use `alist-get' in PLACE expressions. This will modify |
| 760 | an existing association (more precisely, the first one if | ||
| 761 | multiple exist), or add a new element to the beginning of ALIST, | ||
| 762 | destructively modifying the list stored in ALIST. | ||
| 763 | |||
| 764 | Example: | ||
| 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 | |||
| 760 | When using it to set a value, optional argument REMOVE non-nil | 773 | When using it to set a value, optional argument REMOVE non-nil |
| 761 | means to remove KEY from ALIST if the new value is `eql' to DEFAULT." | 774 | means to remove KEY from ALIST if the new value is `eql' to |
| 775 | DEFAULT (more precisely the first found association will be | ||
| 776 | deleted from the alist). | ||
| 777 | |||
| 778 | Example: | ||
| 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) |