commit 12a79dc3cea50435bbd331dc5ec4c12816f1c1b5 (HEAD, refs/remotes/origin/master) Author: Eli Zaretskii Date: Sat Feb 4 11:33:54 2017 +0200 Document 'save-some-buffers-default-predicate' * doc/lispref/files.texi (Saving Buffers): * doc/emacs/files.texi (Save Commands): Document save-some-buffers-default-predicate. diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index 5c582e571e..2b09c69945 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -417,6 +417,12 @@ changes you would be saving. This calls the command Display a help message about these options. @end table +@noindent +@vindex save-some-buffers-default-predicate +You can customize the value of +@code{save-some-buffers-default-predicate} to control which buffers +Emacs will ask about. + @kbd{C-x C-c}, the key sequence to exit Emacs, invokes @code{save-some-buffers} and therefore asks the same questions. diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi index 853e84477e..ef37321141 100644 --- a/doc/lispref/files.texi +++ b/doc/lispref/files.texi @@ -368,17 +368,21 @@ asks the user about each buffer. But if @var{save-silently-p} is non-@code{nil}, it saves all the file-visiting buffers without querying the user. -The optional @var{pred} argument controls which buffers to ask about -(or to save silently if @var{save-silently-p} is non-@code{nil}). -If it is @code{nil}, that means to ask only about file-visiting buffers. -If it is @code{t}, that means also offer to save certain other non-file -buffers---those that have a non-@code{nil} buffer-local value of -@code{buffer-offer-save} (@pxref{Killing Buffers}). A user who says -@samp{yes} to saving a non-file buffer is asked to specify the file -name to use. The @code{save-buffers-kill-emacs} function passes the -value @code{t} for @var{pred}. - -If @var{pred} is neither @code{t} nor @code{nil}, then it should be +@vindex save-some-buffers-default-predicate +The optional @var{pred} argument provides a predicate that controls +which buffers to ask about (or to save silently if +@var{save-silently-p} is non-@code{nil}). If @var{pred} is +@code{nil}, that means to use the value of +@code{save-some-buffers-default-predicate} instead of @var{pred}. If +the result is @code{nil}, it means ask only about file-visiting +buffers. If it is @code{t}, that means also offer to save certain +other non-file buffers---those that have a non-@code{nil} buffer-local +value of @code{buffer-offer-save} (@pxref{Killing Buffers}). A user +who says @samp{yes} to saving a non-file buffer is asked to specify +the file name to use. The @code{save-buffers-kill-emacs} function +passes the value @code{t} for @var{pred}. + +If the predicate is neither @code{t} nor @code{nil}, then it should be a function of no arguments. It will be called in each buffer to decide whether to offer to save that buffer. If it returns a non-@code{nil} value in a certain buffer, that means do offer to save that buffer. diff --git a/etc/NEWS b/etc/NEWS index 25e1d6e836..270f8803d5 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -758,6 +758,7 @@ instead. * Lisp Changes in Emacs 26.1 ++++ ** 'save-some-buffers' now uses 'save-some-buffers-default-predicate' to decide which buffers to ask about, if the PRED argument is nil. The default value of 'save-some-buffers-default-predicate' is nil, commit 6db5582479bdf6b7b090c5b450534999ef284aa8 Author: Richard Stallman Date: Sat Feb 4 11:16:55 2017 +0200 New defcustom 'save-some-buffers-default-predicate' * lisp/files.el (save-some-buffers-default-predicate): New defcustom. (save-some-buffers): Use it when PRED is nil or omitted. diff --git a/etc/NEWS b/etc/NEWS index 930e1c893b..25e1d6e836 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -758,6 +758,11 @@ instead. * Lisp Changes in Emacs 26.1 +** 'save-some-buffers' now uses 'save-some-buffers-default-predicate' +to decide which buffers to ask about, if the PRED argument is nil. +The default value of 'save-some-buffers-default-predicate' is nil, +which means ask about all file-visiting buffers. + ** string-(to|as|make)-(uni|multi)byte are now declared obsolete. ** New variable 'while-no-input-ignore-events' which allow setting which special events 'while-no-input' should ignore. diff --git a/lisp/files.el b/lisp/files.el index 25392fdcc7..2833ec5c12 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5134,6 +5134,13 @@ Before and after saving the buffer, this function runs "Non-nil means `save-some-buffers' should save this buffer without asking.") (make-variable-buffer-local 'buffer-save-without-query) +(defcustom save-some-buffers-default-predicate nil + "Default predicate for `save-some-buffers'. +This allows you to stop `save-some-buffers' from asking +about certain files that you'd usually rather not save." + :group 'auto-save + :type 'function) + (defun save-some-buffers (&optional arg pred) "Save some modified file-visiting buffers. Asks user about each one. You can answer `y' to save, `n' not to save, `C-r' to look at the @@ -5149,10 +5156,13 @@ If PRED is nil, all the file-visiting buffers are considered. If PRED is t, then certain non-file buffers will also be considered. If PRED is a zero-argument function, it indicates for each buffer whether to consider it or not when called with that buffer current. +PRED defaults to the value of `save-some-buffers-default-predicate'. See `save-some-buffers-action-alist' if you want to change the additional actions you can take on files." (interactive "P") + (unless pred + (setq pred save-some-buffers-default-predicate)) (save-window-excursion (let* (queried autosaved-buffers files-done abbrevs-done) @@ -6812,6 +6822,8 @@ asks whether processes should be killed. Runs the members of `kill-emacs-query-functions' in turn and stops if any returns nil. If `confirm-kill-emacs' is non-nil, calls it." (interactive "P") + ;; Don't use save-some-buffers-default-predicate, because we want + ;; to ask about all the buffers before killing Emacs. (save-some-buffers arg t) (let ((confirm confirm-kill-emacs)) (and commit be10c00d3d64d53a7f31441d42f6c5b1f75b9916 Author: Mark Oteiza Date: Fri Feb 3 21:42:42 2017 -0500 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. diff --git a/etc/NEWS b/etc/NEWS index 617f39f9b4..930e1c893b 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -885,6 +885,10 @@ collection). +++ ** 'car' and 'cdr' compositions 'cXXXr' and 'cXXXXr' are now part of Elisp. +--- +** 'if-let*', 'when-let*', and 'and-let*' are new in subr-x.el. +The incumbent 'if-let' and 'when-let' are now aliases. + +++ ** The new functions 'make-nearby-temp-file' and 'temporary-file-directory' 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 52331b9ad3..f7a846927c 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -115,12 +115,16 @@ threading." binding)) bindings))) -(defmacro if-let (bindings then &rest else) - "Process BINDINGS and if all values are non-nil eval THEN, else ELSE. -Argument BINDINGS is a list of tuples whose car is a symbol to be -bound and (optionally) used in THEN, and its cadr is a sexp to be -evalled to set symbol's value. In the special case you only want -to bind a single value, BINDINGS can just be a plain tuple." +(defmacro if-let* (bindings then &rest else) + "Bind variables according to VARLIST and eval THEN or ELSE. +Each binding is evaluated in turn with `let*', and evaluation +stops if a binding value is nil. If all are non-nil, the value +of THEN is returned, or the last form in ELSE is returned. +Each element of VARLIST is a symbol (which is bound to nil) +or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM). +In the special case you only want to bind a single value, +VARLIST can just be a plain tuple. +\n(fn VARLIST THEN ELSE...)" (declare (indent 2) (debug ([&or (&rest (symbolp form)) (symbolp form)] form body))) (when (and (<= (length bindings) 2) @@ -132,15 +136,23 @@ to bind a single value, BINDINGS can just be a plain tuple." ,then ,@else))) -(defmacro when-let (bindings &rest body) - "Process BINDINGS and if all values are non-nil eval BODY. -Argument BINDINGS is a list of tuples whose car is a symbol to be -bound and (optionally) used in BODY, and its cadr is a sexp to be -evalled to set symbol's value. In the special case you only want -to bind a single value, BINDINGS can just be a plain tuple." +(defmacro when-let* (bindings &rest body) + "Bind variables according to VARLIST and conditionally eval BODY. +Each binding is evaluated in turn with `let*', and evaluation +stops if a binding value is nil. If all are non-nil, the value +of the last form in BODY is returned. +Each element of VARLIST is a symbol (which is bound to nil) +or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM). +In the special case you only want to bind a single value, +VARLIST can just be a plain tuple. +\n(fn VARLIST BODY...)" (declare (indent 1) (debug if-let)) (list 'if-let bindings (macroexp-progn body))) +(defalias 'if-let 'if-let*) +(defalias 'when-let 'when-let*) +(defalias 'and-let* 'when-let*) + (defsubst hash-table-empty-p (hash-table) "Check whether HASH-TABLE is empty (has 0 elements)." (zerop (hash-table-count hash-table)))