diff options
| author | Mark Oteiza | 2017-02-03 21:42:42 -0500 |
|---|---|---|
| committer | Mark Oteiza | 2017-02-03 21:42:42 -0500 |
| commit | be10c00d3d64d53a7f31441d42f6c5b1f75b9916 (patch) | |
| tree | f6398751a5f5d16e902f7d4b31e3912e550424f3 | |
| parent | e080d019f41d2738ba0db721c1b89ea57413439b (diff) | |
| download | emacs-be10c00d3d64d53a7f31441d42f6c5b1f75b9916.tar.gz emacs-be10c00d3d64d53a7f31441d42f6c5b1f75b9916.zip | |
Rename to if-let* and when-let*
Make the existing if-let and when-let aliases.
* lisp/emacs-lisp/subr-x.el (if-let*, when-let*): New macros. Rewrite
docstrings, incorporating that from let* and the existing if-let.
(if-let, when-let, and-let*): Alias them.
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/emacs-lisp/subr-x.el | 36 |
2 files changed, 28 insertions, 12 deletions
| @@ -885,6 +885,10 @@ collection). | |||
| 885 | +++ | 885 | +++ |
| 886 | ** 'car' and 'cdr' compositions 'cXXXr' and 'cXXXXr' are now part of Elisp. | 886 | ** 'car' and 'cdr' compositions 'cXXXr' and 'cXXXXr' are now part of Elisp. |
| 887 | 887 | ||
| 888 | --- | ||
| 889 | ** 'if-let*', 'when-let*', and 'and-let*' are new in subr-x.el. | ||
| 890 | The incumbent 'if-let' and 'when-let' are now aliases. | ||
| 891 | |||
| 888 | +++ | 892 | +++ |
| 889 | ** The new functions 'make-nearby-temp-file' and 'temporary-file-directory' | 893 | ** The new functions 'make-nearby-temp-file' and 'temporary-file-directory' |
| 890 | can be used for creation of temporary files of remote or mounted directories. | 894 | can be used for creation of temporary files of remote or mounted directories. |
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index 52331b9ad36..f7a846927c0 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el | |||
| @@ -115,12 +115,16 @@ threading." | |||
| 115 | binding)) | 115 | binding)) |
| 116 | bindings))) | 116 | bindings))) |
| 117 | 117 | ||
| 118 | (defmacro if-let (bindings then &rest else) | 118 | (defmacro if-let* (bindings then &rest else) |
| 119 | "Process BINDINGS and if all values are non-nil eval THEN, else ELSE. | 119 | "Bind variables according to VARLIST and eval THEN or ELSE. |
| 120 | Argument BINDINGS is a list of tuples whose car is a symbol to be | 120 | Each binding is evaluated in turn with `let*', and evaluation |
| 121 | bound and (optionally) used in THEN, and its cadr is a sexp to be | 121 | stops if a binding value is nil. If all are non-nil, the value |
| 122 | evalled to set symbol's value. In the special case you only want | 122 | of THEN is returned, or the last form in ELSE is returned. |
| 123 | to bind a single value, BINDINGS can just be a plain tuple." | 123 | Each element of VARLIST is a symbol (which is bound to nil) |
| 124 | or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM). | ||
| 125 | In the special case you only want to bind a single value, | ||
| 126 | VARLIST can just be a plain tuple. | ||
| 127 | \n(fn VARLIST THEN ELSE...)" | ||
| 124 | (declare (indent 2) | 128 | (declare (indent 2) |
| 125 | (debug ([&or (&rest (symbolp form)) (symbolp form)] form body))) | 129 | (debug ([&or (&rest (symbolp form)) (symbolp form)] form body))) |
| 126 | (when (and (<= (length bindings) 2) | 130 | (when (and (<= (length bindings) 2) |
| @@ -132,15 +136,23 @@ to bind a single value, BINDINGS can just be a plain tuple." | |||
| 132 | ,then | 136 | ,then |
| 133 | ,@else))) | 137 | ,@else))) |
| 134 | 138 | ||
| 135 | (defmacro when-let (bindings &rest body) | 139 | (defmacro when-let* (bindings &rest body) |
| 136 | "Process BINDINGS and if all values are non-nil eval BODY. | 140 | "Bind variables according to VARLIST and conditionally eval BODY. |
| 137 | Argument BINDINGS is a list of tuples whose car is a symbol to be | 141 | Each binding is evaluated in turn with `let*', and evaluation |
| 138 | bound and (optionally) used in BODY, and its cadr is a sexp to be | 142 | stops if a binding value is nil. If all are non-nil, the value |
| 139 | evalled to set symbol's value. In the special case you only want | 143 | of the last form in BODY is returned. |
| 140 | to bind a single value, BINDINGS can just be a plain tuple." | 144 | Each element of VARLIST is a symbol (which is bound to nil) |
| 145 | or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM). | ||
| 146 | In the special case you only want to bind a single value, | ||
| 147 | VARLIST can just be a plain tuple. | ||
| 148 | \n(fn VARLIST BODY...)" | ||
| 141 | (declare (indent 1) (debug if-let)) | 149 | (declare (indent 1) (debug if-let)) |
| 142 | (list 'if-let bindings (macroexp-progn body))) | 150 | (list 'if-let bindings (macroexp-progn body))) |
| 143 | 151 | ||
| 152 | (defalias 'if-let 'if-let*) | ||
| 153 | (defalias 'when-let 'when-let*) | ||
| 154 | (defalias 'and-let* 'when-let*) | ||
| 155 | |||
| 144 | (defsubst hash-table-empty-p (hash-table) | 156 | (defsubst hash-table-empty-p (hash-table) |
| 145 | "Check whether HASH-TABLE is empty (has 0 elements)." | 157 | "Check whether HASH-TABLE is empty (has 0 elements)." |
| 146 | (zerop (hash-table-count hash-table))) | 158 | (zerop (hash-table-count hash-table))) |