diff options
| -rw-r--r-- | doc/lispref/lists.texi | 12 | ||||
| -rw-r--r-- | etc/NEWS | 3 | ||||
| -rw-r--r-- | lisp/subr.el | 10 |
3 files changed, 16 insertions, 9 deletions
diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index c18c408209a..e7a739f88f3 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi | |||
| @@ -1556,12 +1556,16 @@ keys may not be symbols: | |||
| 1556 | @end smallexample | 1556 | @end smallexample |
| 1557 | @end defun | 1557 | @end defun |
| 1558 | 1558 | ||
| 1559 | @defun alist-get key value &optional default | 1559 | @defun alist-get key value &optional default remove |
| 1560 | This function is like @code{assq}, but instead of returning the entire | 1560 | This function is like @code{assq}, but instead of returning the entire |
| 1561 | association for @var{key}, @code{(@var{key} . @var{value})}, it | 1561 | association for @var{key}, @code{(@var{key} . @var{value})}, it |
| 1562 | returns just the @var{value}. It returns @var{default} if @var{key} | 1562 | returns just the @var{value}. If @var{key} is not found in |
| 1563 | is not found in @var{alist}, defaulting to @code{nil} if @var{default} | 1563 | @var{alist} it returns @var{default}. |
| 1564 | is omitted. | 1564 | |
| 1565 | This is a generalized variable (@pxref{Generalized Variables}) that | ||
| 1566 | can be used to change a value with @code{setf}. When using it to set | ||
| 1567 | a value, optional argument @var{remove} non-nil means to remove | ||
| 1568 | @var{key} from @var{alist} if the new value is @code{eql} to @var{default}. | ||
| 1565 | @end defun | 1569 | @end defun |
| 1566 | 1570 | ||
| 1567 | @defun rassq value alist | 1571 | @defun rassq value alist |
| @@ -1680,7 +1680,8 @@ codeset is "UTF-8" (as in "en_US.UTF-8"). This is needed because | |||
| 1680 | MS-Windows doesn't support UTF-8 as codeset in its locales. | 1680 | MS-Windows doesn't support UTF-8 as codeset in its locales. |
| 1681 | 1681 | ||
| 1682 | +++ | 1682 | +++ |
| 1683 | ** New function 'alist-get', which is also a valid place (aka lvalue). | 1683 | ** New function 'alist-get', which is a generalized variable |
| 1684 | suitable for use with 'setf'. | ||
| 1684 | 1685 | ||
| 1685 | +++ | 1686 | +++ |
| 1686 | ** New function 'funcall-interactively', which works like 'funcall' | 1687 | ** New function 'funcall-interactively', which works like 'funcall' |
diff --git a/lisp/subr.el b/lisp/subr.el index 81570d484b9..ed2166a0ee2 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -598,10 +598,12 @@ Elements of ALIST that are not conses are ignored." | |||
| 598 | alist) | 598 | alist) |
| 599 | 599 | ||
| 600 | (defun alist-get (key alist &optional default remove) | 600 | (defun alist-get (key alist &optional default remove) |
| 601 | "Get the value associated to KEY in ALIST. | 601 | "Return the value associated with KEY in ALIST, using `assq'. |
| 602 | DEFAULT is the value to return if KEY is not found in ALIST. | 602 | If KEY is not found in ALIST, return DEFAULT. |
| 603 | REMOVE, if non-nil, means that when setting this element, we should | 603 | |
| 604 | remove the entry if the new value is `eql' to DEFAULT." | 604 | This is a generalized variable suitable for use with `setf'. |
| 605 | When using it to set a value, optional argument REMOVE non-nil | ||
| 606 | means to remove KEY from ALIST if the new value is `eql' to DEFAULT." | ||
| 605 | (ignore remove) ;;Silence byte-compiler. | 607 | (ignore remove) ;;Silence byte-compiler. |
| 606 | (let ((x (assq key alist))) | 608 | (let ((x (assq key alist))) |
| 607 | (if x (cdr x) default))) | 609 | (if x (cdr x) default))) |