diff options
| author | Michael Heerdegen | 2018-03-06 18:28:51 +0100 |
|---|---|---|
| committer | Michael Heerdegen | 2018-03-06 18:32:04 +0100 |
| commit | f6bd7e06861142371994ff9ce54dd62573809fa5 (patch) | |
| tree | 7d75a0b4aba2f82cd6bde0686760e3a1b49345c6 /lisp | |
| parent | af4697faa1f5b643f63a9ea61aa205a4c1432e23 (diff) | |
| download | emacs-f6bd7e06861142371994ff9ce54dd62573809fa5.tar.gz emacs-f6bd7e06861142371994ff9ce54dd62573809fa5.zip | |
Revert last commit
This reverts commit af4697faa1f5b643f63a9ea61aa205a4c1432e23. It's
too late for this to be in the release.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/emacs-lisp/subr-x.el | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index b2d7f0dec4f..21dba377bf1 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el | |||
| @@ -121,7 +121,7 @@ If ELT is of the form ((EXPR)), listify (EXPR) with a dummy symbol." | |||
| 121 | binding)) | 121 | binding)) |
| 122 | bindings))) | 122 | bindings))) |
| 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 | Each binding is evaluated in turn, and evaluation stops if a |
| 127 | binding value is nil. If all are non-nil, the value of THEN is | 127 | binding value is nil. If all are non-nil, the value of THEN is |
| @@ -131,18 +131,10 @@ Each element of VARLIST is a list (SYMBOL VALUEFORM) which binds | |||
| 131 | SYMBOL to the value of VALUEFORM. An element can additionally | 131 | SYMBOL to the value of VALUEFORM. An element can additionally |
| 132 | be of the form (VALUEFORM), which is evaluated and checked for | 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 | 133 | nil; i.e. SYMBOL can be omitted if only the test result is of |
| 134 | interest. | 134 | interest." |
| 135 | |||
| 136 | As a special case, a VARLIST of the form (SYMBOL SOMETHING) is | ||
| 137 | treated like ((SYMBOL SOMETHING))." | ||
| 138 | (declare (indent 2) | 135 | (declare (indent 2) |
| 139 | (debug ([&or (symbolp form) | 136 | (debug ((&rest [&or symbolp (symbolp form) (form)]) |
| 140 | (&rest [&or symbolp (symbolp form) (form)])] | ||
| 141 | form body))) | 137 | form body))) |
| 142 | (pcase varlist | ||
| 143 | (`(,(pred symbolp) ,_) | ||
| 144 | ;; the single-tuple syntax case, for backward compatibility | ||
| 145 | (cl-callf list varlist))) | ||
| 146 | (if varlist | 138 | (if varlist |
| 147 | `(let* ,(setq varlist (internal--build-bindings varlist)) | 139 | `(let* ,(setq varlist (internal--build-bindings varlist)) |
| 148 | (if ,(caar (last varlist)) | 140 | (if ,(caar (last varlist)) |
| @@ -150,23 +142,23 @@ treated like ((SYMBOL SOMETHING))." | |||
| 150 | ,@else)) | 142 | ,@else)) |
| 151 | `(let* () ,then))) | 143 | `(let* () ,then))) |
| 152 | 144 | ||
| 153 | (defmacro when-let (varlist &rest body) | 145 | (defmacro when-let* (varlist &rest body) |
| 154 | "Bind variables according to VARLIST and conditionally eval BODY. | 146 | "Bind variables according to VARLIST and conditionally eval BODY. |
| 155 | Each binding is evaluated in turn, and evaluation stops if a | 147 | Each binding is evaluated in turn, and evaluation stops if a |
| 156 | binding value is nil. If all are non-nil, the value of the last | 148 | binding value is nil. If all are non-nil, the value of the last |
| 157 | form in BODY is returned. | 149 | form in BODY is returned. |
| 158 | 150 | ||
| 159 | VARLIST is the same as in `if-let'." | 151 | VARLIST is the same as in `if-let*'." |
| 160 | (declare (indent 1) (debug ([&or (symbolp form) | 152 | (declare (indent 1) (debug if-let*)) |
| 161 | (&rest [&or symbolp (symbolp form) (form)])] | 153 | (list 'if-let* varlist (macroexp-progn body))) |
| 162 | body))) | ||
| 163 | (list 'if-let varlist (macroexp-progn body))) | ||
| 164 | 154 | ||
| 165 | (defmacro and-let (varlist &rest body) | 155 | (defmacro and-let* (varlist &rest body) |
| 166 | "Bind variables according to VARLIST and conditionally eval BODY. | 156 | "Bind variables according to VARLIST and conditionally eval BODY. |
| 167 | Like `when-let', except if BODY is empty and all the bindings | 157 | Like `when-let*', except if BODY is empty and all the bindings |
| 168 | are non-nil, then the result is non-nil." | 158 | are non-nil, then the result is non-nil." |
| 169 | (declare (indent 1) (debug when-let)) | 159 | (declare (indent 1) |
| 160 | (debug ((&rest [&or symbolp (symbolp form) (form)]) | ||
| 161 | body))) | ||
| 170 | (let (res) | 162 | (let (res) |
| 171 | (if varlist | 163 | (if varlist |
| 172 | `(let* ,(setq varlist (internal--build-bindings varlist)) | 164 | `(let* ,(setq varlist (internal--build-bindings varlist)) |
| @@ -174,9 +166,26 @@ are non-nil, then the result is non-nil." | |||
| 174 | ,@(or body `(,res)))) | 166 | ,@(or body `(,res)))) |
| 175 | `(let* () ,@(or body '(t)))))) | 167 | `(let* () ,@(or body '(t)))))) |
| 176 | 168 | ||
| 177 | (defalias 'if-let* #'if-let) | 169 | (defmacro if-let (spec then &rest else) |
| 178 | (defalias 'when-let* #'when-let) | 170 | "Bind variables according to SPEC and eval THEN or ELSE. |
| 179 | (defalias 'and-let* #'and-let) | 171 | Like `if-let*' except SPEC can have the form (SYMBOL VALUEFORM)." |
| 172 | (declare (indent 2) | ||
| 173 | (debug ([&or (&rest [&or symbolp (symbolp form) (form)]) | ||
| 174 | (symbolp form)] | ||
| 175 | form body)) | ||
| 176 | (obsolete "use `if-let*' instead." "26.1")) | ||
| 177 | (when (and (<= (length spec) 2) | ||
| 178 | (not (listp (car spec)))) | ||
| 179 | ;; Adjust the single binding case | ||
| 180 | (setq spec (list spec))) | ||
| 181 | (list 'if-let* spec then (macroexp-progn else))) | ||
| 182 | |||
| 183 | (defmacro when-let (spec &rest body) | ||
| 184 | "Bind variables according to SPEC and conditionally eval BODY. | ||
| 185 | Like `when-let*' except SPEC can have the form (SYMBOL VALUEFORM)." | ||
| 186 | (declare (indent 1) (debug if-let) | ||
| 187 | (obsolete "use `when-let*' instead." "26.1")) | ||
| 188 | (list 'if-let spec (macroexp-progn body))) | ||
| 180 | 189 | ||
| 181 | (defsubst hash-table-empty-p (hash-table) | 190 | (defsubst hash-table-empty-p (hash-table) |
| 182 | "Check whether HASH-TABLE is empty (has 0 elements)." | 191 | "Check whether HASH-TABLE is empty (has 0 elements)." |