aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Malabarba2015-04-12 14:36:54 +0100
committerArtur Malabarba2015-04-12 16:16:05 +0100
commit5fb807efcd6dda113c0cfade9811070e45c36a2f (patch)
treeb626c14937914f6bf7f426bf258bb09fda80085e
parent2e47de365b4dcec6781f6150cea977fa8d8a94f2 (diff)
downloademacs-5fb807efcd6dda113c0cfade9811070e45c36a2f.tar.gz
emacs-5fb807efcd6dda113c0cfade9811070e45c36a2f.zip
* 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.
-rw-r--r--lisp/files.el53
1 files changed, 36 insertions, 17 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 7a662594bb6..5ef7318ca45 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -573,6 +573,12 @@ using \\[read-only-mode]."
573 573
574Maximum length of the history list is determined by the value 574Maximum length of the history list is determined by the value
575of `history-length', which see.") 575of `history-length', which see.")
576
577(defvar save-silently nil
578 "If non-nil, avoid messages when saving files.
579Error-related messages will still be printed, but all other
580messages will not.")
581
576 582
577(put 'ange-ftp-completion-hook-function 'safe-magic t) 583(put 'ange-ftp-completion-hook-function 'safe-magic t)
578(defun ange-ftp-completion-hook-function (op &rest args) 584(defun ange-ftp-completion-hook-function (op &rest args)
@@ -1865,6 +1871,13 @@ If that fails, try to open it with `find-file-literally'
1865 out-of-memory-warning-percentage 1871 out-of-memory-warning-percentage
1866 (file-size-human-readable (* total-free-memory 1024))))))))) 1872 (file-size-human-readable (* total-free-memory 1024)))))))))
1867 1873
1874(defun files--message (format &rest args)
1875 "Like `message', except sometimes don't print to minibuffer.
1876If the variable `save-silently' is non-nil, the message is not
1877displayed on the minibuffer."
1878 (apply #'message format args)
1879 (when save-silently (message nil)))
1880
1868(defun find-file-noselect (filename &optional nowarn rawfile wildcards) 1881(defun find-file-noselect (filename &optional nowarn rawfile wildcards)
1869 "Read file FILENAME into a buffer and return the buffer. 1882 "Read file FILENAME into a buffer and return the buffer.
1870If a buffer exists visiting FILENAME, return that one, but 1883If a buffer exists visiting FILENAME, return that one, but
@@ -1910,8 +1923,8 @@ the various files."
1910 (or nowarn 1923 (or nowarn
1911 find-file-suppress-same-file-warnings 1924 find-file-suppress-same-file-warnings
1912 (string-equal filename (buffer-file-name other)) 1925 (string-equal filename (buffer-file-name other))
1913 (message "%s and %s are the same file" 1926 (files--message "%s and %s are the same file"
1914 filename (buffer-file-name other))) 1927 filename (buffer-file-name other)))
1915 ;; Optionally also find that buffer. 1928 ;; Optionally also find that buffer.
1916 (if (or find-file-existing-other-name find-file-visit-truename) 1929 (if (or find-file-existing-other-name find-file-visit-truename)
1917 (setq buf other)))) 1930 (setq buf other))))
@@ -4641,7 +4654,10 @@ See the subroutine `basic-save-buffer' for more information."
4641 ;; then Rmail-mbox never displays it due to buffer swapping. If 4654 ;; then Rmail-mbox never displays it due to buffer swapping. If
4642 ;; the test is ever re-introduced, be sure to handle saving of 4655 ;; the test is ever re-introduced, be sure to handle saving of
4643 ;; Rmail files. 4656 ;; Rmail files.
4644 (if (and modp (buffer-file-name) (not noninteractive)) 4657 (if (and modp
4658 (buffer-file-name)
4659 (not noninteractive)
4660 (not save-silently))
4645 (message "Saving file %s..." (buffer-file-name))) 4661 (message "Saving file %s..." (buffer-file-name)))
4646 (basic-save-buffer) 4662 (basic-save-buffer)
4647 (and modp (memq arg '(4 64)) (setq buffer-backed-up nil)))) 4663 (and modp (memq arg '(4 64)) (setq buffer-backed-up nil))))
@@ -4785,7 +4801,7 @@ Before and after saving the buffer, this function runs
4785 (run-hooks 'after-save-hook)) 4801 (run-hooks 'after-save-hook))
4786 (or noninteractive 4802 (or noninteractive
4787 (not (called-interactively-p 'any)) 4803 (not (called-interactively-p 'any))
4788 (message "(No changes need to be saved)"))))) 4804 (files--message "(No changes need to be saved)")))))
4789 4805
4790;; This does the "real job" of writing a buffer into its visited file 4806;; This does the "real job" of writing a buffer into its visited file
4791;; and making a backup file. This is what is normally done 4807;; and making a backup file. This is what is normally done
@@ -4858,9 +4874,10 @@ Before and after saving the buffer, this function runs
4858 ;; Pass in nil&nil rather than point-min&max 4874 ;; Pass in nil&nil rather than point-min&max
4859 ;; cause we're saving the whole buffer. 4875 ;; cause we're saving the whole buffer.
4860 ;; write-region-annotate-functions may use it. 4876 ;; write-region-annotate-functions may use it.
4861 (write-region nil nil 4877 (write-region nil nil
4862 tempname nil realname 4878 tempname nil realname
4863 buffer-file-truename 'excl) 4879 buffer-file-truename 'excl)
4880 (when save-silently (message nil))
4864 nil) 4881 nil)
4865 (file-already-exists t)) 4882 (file-already-exists t))
4866 ;; The file was somehow created by someone else between 4883 ;; The file was somehow created by someone else between
@@ -4905,8 +4922,9 @@ Before and after saving the buffer, this function runs
4905 ;; Pass in nil&nil rather than point-min&max to indicate 4922 ;; Pass in nil&nil rather than point-min&max to indicate
4906 ;; we're saving the buffer rather than just a region. 4923 ;; we're saving the buffer rather than just a region.
4907 ;; write-region-annotate-functions may make us of it. 4924 ;; write-region-annotate-functions may make us of it.
4908 (write-region nil nil 4925 (write-region nil nil
4909 buffer-file-name nil t buffer-file-truename) 4926 buffer-file-name nil t buffer-file-truename)
4927 (when save-silently (message nil))
4910 (setq success t)) 4928 (setq success t))
4911 ;; If we get an error writing the new file, and we made 4929 ;; If we get an error writing the new file, and we made
4912 ;; the backup by renaming, undo the backing-up. 4930 ;; the backup by renaming, undo the backing-up.
@@ -5027,13 +5045,13 @@ change the additional actions you can take on files."
5027 (cond 5045 (cond
5028 ((null autosaved-buffers) 5046 ((null autosaved-buffers)
5029 (when (called-interactively-p 'any) 5047 (when (called-interactively-p 'any)
5030 (message "(No files need saving)"))) 5048 (files--message "(No files need saving)")))
5031 ((= (length autosaved-buffers) 1) 5049 ((= (length autosaved-buffers) 1)
5032 (message "(Saved %s)" (car autosaved-buffers))) 5050 (files--message "(Saved %s)" (car autosaved-buffers)))
5033 (t 5051 (t
5034 (message "(Saved %d files: %s)" 5052 (files--message "(Saved %d files: %s)"
5035 (length autosaved-buffers) 5053 (length autosaved-buffers)
5036 (mapconcat 'identity autosaved-buffers ", ")))))))) 5054 (mapconcat 'identity autosaved-buffers ", "))))))))
5037 5055
5038(defun clear-visited-file-modtime () 5056(defun clear-visited-file-modtime ()
5039 "Clear out records of last mod time of visited file. 5057 "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
5048prints a message in the minibuffer. Instead, use `set-buffer-modified-p'." 5066prints a message in the minibuffer. Instead, use `set-buffer-modified-p'."
5049 (declare (interactive-only set-buffer-modified-p)) 5067 (declare (interactive-only set-buffer-modified-p))
5050 (interactive "P") 5068 (interactive "P")
5051 (message (if arg "Modification-flag set" 5069 (files--message (if arg "Modification-flag set"
5052 "Modification-flag cleared")) 5070 "Modification-flag cleared"))
5053 (set-buffer-modified-p arg)) 5071 (set-buffer-modified-p arg))
5054 5072
5055(defun toggle-read-only (&optional arg interactive) 5073(defun toggle-read-only (&optional arg interactive)
@@ -5083,7 +5101,8 @@ instead of any buffer contents; END is ignored.
5083This does character code conversion and applies annotations 5101This does character code conversion and applies annotations
5084like `write-region' does." 5102like `write-region' does."
5085 (interactive "r\nFAppend to file: ") 5103 (interactive "r\nFAppend to file: ")
5086 (write-region start end filename t)) 5104 (prog1 (write-region start end filename t)
5105 (when save-silently (message nil))))
5087 5106
5088(defun file-newest-backup (filename) 5107(defun file-newest-backup (filename)
5089 "Return most recent backup file for FILENAME or nil if no backups exist." 5108 "Return most recent backup file for FILENAME or nil if no backups exist."