aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMichael Heerdegen2018-03-06 18:28:51 +0100
committerMichael Heerdegen2018-03-06 18:32:04 +0100
commitf6bd7e06861142371994ff9ce54dd62573809fa5 (patch)
tree7d75a0b4aba2f82cd6bde0686760e3a1b49345c6 /lisp
parentaf4697faa1f5b643f63a9ea61aa205a4c1432e23 (diff)
downloademacs-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.el55
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.
126Each binding is evaluated in turn, and evaluation stops if a 126Each binding is evaluated in turn, and evaluation stops if a
127binding value is nil. If all are non-nil, the value of THEN is 127binding 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
131SYMBOL to the value of VALUEFORM. An element can additionally 131SYMBOL to the value of VALUEFORM. An element can additionally
132be of the form (VALUEFORM), which is evaluated and checked for 132be of the form (VALUEFORM), which is evaluated and checked for
133nil; i.e. SYMBOL can be omitted if only the test result is of 133nil; i.e. SYMBOL can be omitted if only the test result is of
134interest. 134interest."
135
136As a special case, a VARLIST of the form (SYMBOL SOMETHING) is
137treated 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.
155Each binding is evaluated in turn, and evaluation stops if a 147Each binding is evaluated in turn, and evaluation stops if a
156binding value is nil. If all are non-nil, the value of the last 148binding value is nil. If all are non-nil, the value of the last
157form in BODY is returned. 149form in BODY is returned.
158 150
159VARLIST is the same as in `if-let'." 151VARLIST 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.
167Like `when-let', except if BODY is empty and all the bindings 157Like `when-let*', except if BODY is empty and all the bindings
168are non-nil, then the result is non-nil." 158are 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) 171Like `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.
185Like `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)."