1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-25 07:28:20 +00:00

* lisp/files.el: Only message when saving if save-silently is nil

(save-silently): New variable.
(files--message): New function.

(find-file-noselect, save-buffer, basic-save-buffer)
(basic-save-buffer-2, save-some-buffers, not-modified)
(append-to-file): Use them.
This commit is contained in:
Artur Malabarba 2015-04-12 14:36:54 +01:00
parent 2e47de365b
commit 5fb807efcd

View File

@ -573,6 +573,12 @@ using \\[read-only-mode]."
Maximum length of the history list is determined by the value
of `history-length', which see.")
(defvar save-silently nil
"If non-nil, avoid messages when saving files.
Error-related messages will still be printed, but all other
messages will not.")
(put 'ange-ftp-completion-hook-function 'safe-magic t)
(defun ange-ftp-completion-hook-function (op &rest args)
@ -1865,6 +1871,13 @@ If that fails, try to open it with `find-file-literally'
out-of-memory-warning-percentage
(file-size-human-readable (* total-free-memory 1024)))))))))
(defun files--message (format &rest args)
"Like `message', except sometimes don't print to minibuffer.
If the variable `save-silently' is non-nil, the message is not
displayed on the minibuffer."
(apply #'message format args)
(when save-silently (message nil)))
(defun find-file-noselect (filename &optional nowarn rawfile wildcards)
"Read file FILENAME into a buffer and return the buffer.
If a buffer exists visiting FILENAME, return that one, but
@ -1910,8 +1923,8 @@ the various files."
(or nowarn
find-file-suppress-same-file-warnings
(string-equal filename (buffer-file-name other))
(message "%s and %s are the same file"
filename (buffer-file-name other)))
(files--message "%s and %s are the same file"
filename (buffer-file-name other)))
;; Optionally also find that buffer.
(if (or find-file-existing-other-name find-file-visit-truename)
(setq buf other))))
@ -4641,7 +4654,10 @@ See the subroutine `basic-save-buffer' for more information."
;; then Rmail-mbox never displays it due to buffer swapping. If
;; the test is ever re-introduced, be sure to handle saving of
;; Rmail files.
(if (and modp (buffer-file-name) (not noninteractive))
(if (and modp
(buffer-file-name)
(not noninteractive)
(not save-silently))
(message "Saving file %s..." (buffer-file-name)))
(basic-save-buffer)
(and modp (memq arg '(4 64)) (setq buffer-backed-up nil))))
@ -4785,7 +4801,7 @@ Before and after saving the buffer, this function runs
(run-hooks 'after-save-hook))
(or noninteractive
(not (called-interactively-p 'any))
(message "(No changes need to be saved)")))))
(files--message "(No changes need to be saved)")))))
;; This does the "real job" of writing a buffer into its visited file
;; and making a backup file. This is what is normally done
@ -4858,9 +4874,10 @@ Before and after saving the buffer, this function runs
;; Pass in nil&nil rather than point-min&max
;; cause we're saving the whole buffer.
;; write-region-annotate-functions may use it.
(write-region nil nil
tempname nil realname
buffer-file-truename 'excl)
(write-region nil nil
tempname nil realname
buffer-file-truename 'excl)
(when save-silently (message nil))
nil)
(file-already-exists t))
;; The file was somehow created by someone else between
@ -4905,8 +4922,9 @@ Before and after saving the buffer, this function runs
;; Pass in nil&nil rather than point-min&max to indicate
;; we're saving the buffer rather than just a region.
;; write-region-annotate-functions may make us of it.
(write-region nil nil
buffer-file-name nil t buffer-file-truename)
(write-region nil nil
buffer-file-name nil t buffer-file-truename)
(when save-silently (message nil))
(setq success t))
;; If we get an error writing the new file, and we made
;; the backup by renaming, undo the backing-up.
@ -5027,13 +5045,13 @@ change the additional actions you can take on files."
(cond
((null autosaved-buffers)
(when (called-interactively-p 'any)
(message "(No files need saving)")))
(files--message "(No files need saving)")))
((= (length autosaved-buffers) 1)
(message "(Saved %s)" (car autosaved-buffers)))
(files--message "(Saved %s)" (car autosaved-buffers)))
(t
(message "(Saved %d files: %s)"
(length autosaved-buffers)
(mapconcat 'identity autosaved-buffers ", "))))))))
(files--message "(Saved %d files: %s)"
(length autosaved-buffers)
(mapconcat 'identity autosaved-buffers ", "))))))))
(defun clear-visited-file-modtime ()
"Clear out records of last mod time of visited file.
@ -5048,8 +5066,8 @@ It is not a good idea to use this function in Lisp programs, because it
prints a message in the minibuffer. Instead, use `set-buffer-modified-p'."
(declare (interactive-only set-buffer-modified-p))
(interactive "P")
(message (if arg "Modification-flag set"
"Modification-flag cleared"))
(files--message (if arg "Modification-flag set"
"Modification-flag cleared"))
(set-buffer-modified-p arg))
(defun toggle-read-only (&optional arg interactive)
@ -5083,7 +5101,8 @@ instead of any buffer contents; END is ignored.
This does character code conversion and applies annotations
like `write-region' does."
(interactive "r\nFAppend to file: ")
(write-region start end filename t))
(prog1 (write-region start end filename t)
(when save-silently (message nil))))
(defun file-newest-backup (filename)
"Return most recent backup file for FILENAME or nil if no backups exist."