diff options
Diffstat (limited to 'lisp/emacs-lisp/subr-x.el')
| -rw-r--r-- | lisp/emacs-lisp/subr-x.el | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index 7736225b5fa..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))) |
| @@ -214,6 +226,11 @@ user enters `recenter', `scroll-up', or `scroll-down' responses, | |||
| 214 | perform the requested window recentering or scrolling and ask | 226 | perform the requested window recentering or scrolling and ask |
| 215 | again. | 227 | again. |
| 216 | 228 | ||
| 229 | When `use-dialog-box' is t (the default), this function can pop | ||
| 230 | up a dialog window to collect the user input. That functionality | ||
| 231 | requires `display-popup-menus-p' to return t. Otherwise, a text | ||
| 232 | dialog will be used. | ||
| 233 | |||
| 217 | The return value is the matching entry from the CHOICES list. | 234 | The return value is the matching entry from the CHOICES list. |
| 218 | 235 | ||
| 219 | Usage example: | 236 | Usage example: |