diff options
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/emacs-lisp/subr-x.el | 46 |
1 files changed, 26 insertions, 20 deletions
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) |