diff options
| author | Michael Heerdegen | 2018-03-10 16:39:41 +0100 |
|---|---|---|
| committer | Michael Heerdegen | 2018-03-27 01:54:22 +0200 |
| commit | 441fe201ea129709ac9807b9b6b30caa45bbd293 (patch) | |
| tree | 9b137d50cdf8a3dfa300b318f36ae680ec3fc55f | |
| parent | 86960383cf8bd709e08aac483a7f60be2f8c2dcf (diff) | |
| download | emacs-441fe201ea129709ac9807b9b6b30caa45bbd293.tar.gz emacs-441fe201ea129709ac9807b9b6b30caa45bbd293.zip | |
De-obsolete `if-let' and `when-let'
For the following release it is planned to make `if-let*' and
`when-let*' aliases for `if-let' and `when-let'. For now we revert
declaring `if-let' and `when-let' obsolete and tweak the docstrings.
* lisp/emacs-lisp/subr-x.el (if-let*, when-let*): Make docstrings
refer to those of `if-let' and `when-let'.
(if-let, when-let): De-obsolete. Rewrite documentation.
| -rw-r--r-- | etc/NEWS | 8 | ||||
| -rw-r--r-- | lisp/emacs-lisp/subr-x.el | 46 |
2 files changed, 28 insertions, 26 deletions
| @@ -1305,12 +1305,8 @@ current buffer or the self-insertion takes place within a comment. | |||
| 1305 | ** The alist 'ucs-names' is now a hash table. | 1305 | ** The alist 'ucs-names' is now a hash table. |
| 1306 | 1306 | ||
| 1307 | --- | 1307 | --- |
| 1308 | ** 'if-let' and 'when-let' are subsumed by 'if-let*' and 'when-let*'. | 1308 | ** 'if-let' and 'when-let' now support binding lists as defined by the |
| 1309 | The incumbent 'if-let' and 'when-let' are now marked obsolete. | 1309 | SRFI-2 (Scheme Request for Implementation 2). |
| 1310 | 'if-let*' and 'when-let*' do not accept the single tuple special case. | ||
| 1311 | New macro 'and-let*' is an implementation of the Scheme SRFI-2 syntax | ||
| 1312 | of the same name. 'if-let*' and 'when-let*' now accept the same | ||
| 1313 | binding syntax as 'and-let*'. | ||
| 1314 | 1310 | ||
| 1315 | --- | 1311 | --- |
| 1316 | ** 'C-up', 'C-down', 'C-left' and 'C-right' are now defined in term | 1312 | ** 'C-up', 'C-down', 'C-left' and 'C-right' are now defined in term |
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index 21dba377bf1..7fab9083e85 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el | |||
| @@ -123,15 +123,8 @@ If ELT is of the form ((EXPR)), listify (EXPR) with a dummy symbol." | |||
| 123 | 123 | ||
| 124 | (defmacro if-let* (varlist then &rest else) | 124 | (defmacro if-let* (varlist then &rest else) |
| 125 | "Bind variables according to VARLIST and eval THEN or ELSE. | 125 | "Bind variables according to VARLIST and eval THEN or ELSE. |
| 126 | Each binding is evaluated in turn, and evaluation stops if a | 126 | This is like `if-let' but doesn't handle a VARLIST of the form |
| 127 | binding value is nil. If all are non-nil, the value of THEN is | 127 | \(SYMBOL SOMETHING) specially." |
| 128 | returned, or the last form in ELSE is returned. | ||
| 129 | |||
| 130 | Each element of VARLIST is a list (SYMBOL VALUEFORM) which binds | ||
| 131 | SYMBOL to the value of VALUEFORM. An element can additionally | ||
| 132 | be of the form (VALUEFORM), which is evaluated and checked for | ||
| 133 | nil; i.e. SYMBOL can be omitted if only the test result is of | ||
| 134 | interest." | ||
| 135 | (declare (indent 2) | 128 | (declare (indent 2) |
| 136 | (debug ((&rest [&or symbolp (symbolp form) (form)]) | 129 | (debug ((&rest [&or symbolp (symbolp form) (form)]) |
| 137 | form body))) | 130 | form body))) |
| @@ -144,11 +137,8 @@ interest." | |||
| 144 | 137 | ||
| 145 | (defmacro when-let* (varlist &rest body) | 138 | (defmacro when-let* (varlist &rest body) |
| 146 | "Bind variables according to VARLIST and conditionally eval BODY. | 139 | "Bind variables according to VARLIST and conditionally eval BODY. |
| 147 | Each binding is evaluated in turn, and evaluation stops if a | 140 | This is like `when-let' but doesn't handle a VARLIST of the form |
| 148 | binding value is nil. If all are non-nil, the value of the last | 141 | \(SYMBOL SOMETHING) specially." |
| 149 | form in BODY is returned. | ||
| 150 | |||
| 151 | VARLIST is the same as in `if-let*'." | ||
| 152 | (declare (indent 1) (debug if-let*)) | 142 | (declare (indent 1) (debug if-let*)) |
| 153 | (list 'if-let* varlist (macroexp-progn body))) | 143 | (list 'if-let* varlist (macroexp-progn body))) |
| 154 | 144 | ||
| @@ -168,12 +158,25 @@ are non-nil, then the result is non-nil." | |||
| 168 | 158 | ||
| 169 | (defmacro if-let (spec then &rest else) | 159 | (defmacro if-let (spec then &rest else) |
| 170 | "Bind variables according to SPEC and eval THEN or ELSE. | 160 | "Bind variables according to SPEC and eval THEN or ELSE. |
| 171 | Like `if-let*' except SPEC can have the form (SYMBOL VALUEFORM)." | 161 | Each binding is evaluated in turn, and evaluation stops if a |
| 162 | binding value is nil. If all are non-nil, the value of THEN is | ||
| 163 | returned, or the last form in ELSE is returned. | ||
| 164 | |||
| 165 | Each element of SPEC is a list (SYMBOL VALUEFORM) which binds | ||
| 166 | SYMBOL to the value of VALUEFORM. An element can additionally be | ||
| 167 | of the form (VALUEFORM), which is evaluated and checked for nil; | ||
| 168 | i.e. SYMBOL can be omitted if only the test result is of | ||
| 169 | interest. It can also be of the form SYMBOL, then the binding of | ||
| 170 | SYMBOL is checked for nil. | ||
| 171 | |||
| 172 | As a special case, a SPEC of the form \(SYMBOL SOMETHING) is | ||
| 173 | interpreted like \((SYMBOL SOMETHING)). This exists for backward | ||
| 174 | compatibility with the old syntax that accepted only one | ||
| 175 | binding." | ||
| 172 | (declare (indent 2) | 176 | (declare (indent 2) |
| 173 | (debug ([&or (&rest [&or symbolp (symbolp form) (form)]) | 177 | (debug ([&or (&rest [&or symbolp (symbolp form) (form)]) |
| 174 | (symbolp form)] | 178 | (symbolp form)] |
| 175 | form body)) | 179 | form body))) |
| 176 | (obsolete "use `if-let*' instead." "26.1")) | ||
| 177 | (when (and (<= (length spec) 2) | 180 | (when (and (<= (length spec) 2) |
| 178 | (not (listp (car spec)))) | 181 | (not (listp (car spec)))) |
| 179 | ;; Adjust the single binding case | 182 | ;; Adjust the single binding case |
| @@ -182,9 +185,12 @@ Like `if-let*' except SPEC can have the form (SYMBOL VALUEFORM)." | |||
| 182 | 185 | ||
| 183 | (defmacro when-let (spec &rest body) | 186 | (defmacro when-let (spec &rest body) |
| 184 | "Bind variables according to SPEC and conditionally eval BODY. | 187 | "Bind variables according to SPEC and conditionally eval BODY. |
| 185 | Like `when-let*' except SPEC can have the form (SYMBOL VALUEFORM)." | 188 | Each binding is evaluated in turn, and evaluation stops if a |
| 186 | (declare (indent 1) (debug if-let) | 189 | binding value is nil. If all are non-nil, the value of the last |
| 187 | (obsolete "use `when-let*' instead." "26.1")) | 190 | form in BODY is returned. |
| 191 | |||
| 192 | The variable list SPEC is the same as in `if-let'." | ||
| 193 | (declare (indent 1) (debug if-let)) | ||
| 188 | (list 'if-let spec (macroexp-progn body))) | 194 | (list 'if-let spec (macroexp-progn body))) |
| 189 | 195 | ||
| 190 | (defsubst hash-table-empty-p (hash-table) | 196 | (defsubst hash-table-empty-p (hash-table) |