Subject: Re: bug#354: "Added (how many lines, bytes?!) to file.txt"

From: [email-masked]
Date: Mon, 13 Mar 2017 20:58:59 -0400

tags 354 patch
quit

Jeff Clough <[email-masked]> writes:

> Updated patch at the end of this message.

Looks like this patch was forgotten.  It still applies cleanly apart
from the NEWS and ChangeLog changes, so I'll push to master in a week or
so if there are no objections.

Reformatted with git format-patch (I made a few whitespace changes to
the patch as well).

>From fd1c97f4d9f417d4ded4ec40b52daac70f15137c Mon Sep 17 00:00:00 2001
From: Jeff Clough <[email-masked]>
Date: Fri, 27 Feb 2015 08:52:12 -0500
Subject: [PATCH] Output number of characters added to file (Bug#354)

* fileio.c (write_region):
* epa-file.el (epa-file-write-region):
* jka-compr.el (jka-compr-write-region):
* ange-ftp.el (ange-ftp-write-region):
* tramp-gvfs.el (tramp-gvfs-handle-write-region):
* tramp-sh.el (tramp-sh-handle-write-region):
* mm-util.el (mm-append-to-file): Functions now output
characters written in addition to file name.
* files.texi: Added documentation to write-region and
append-to-file describing their output.
---
 doc/emacs/files.texi   |  8 +++++---
 etc/NEWS               |  5 +++++
 lisp/epa-file.el       |  2 +-
 lisp/gnus/mm-util.el   |  2 +-
 lisp/jka-compr.el      |  2 +-
 lisp/net/ange-ftp.el   |  2 +-
 lisp/net/tramp-gvfs.el |  2 +-
 lisp/net/tramp-sh.el   |  3 ++-
 src/fileio.c           | 13 +++++++------
 9 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi
index 2b09c69945..d3116730ee 100644
--- a/doc/emacs/files.texi
+++ b/doc/emacs/files.texi
@@ -1639,9 +1639,11 @@ Misc File Ops
   @kbd{M-x write-region} is the inverse of @kbd{M-x insert-file}; it
 copies the contents of the region into the specified file.  @kbd{M-x
 append-to-file} adds the text of the region to the end of the
-specified file.  @xref{Accumulating Text}.  The variable
-@code{write-region-inhibit-fsync} applies to these commands, as well
-as saving files; see @ref{Customize Save}.
+specified file.  @xref{Accumulating Text}.  When called interactively,
+these commands will print a message in the echo area giving the name
+of the file affected as well as the number of characters which were
+added.  The variable @code{write-region-inhibit-fsync} applies to
+these commands, as well as saving files; see @ref{Customize Save}.
 
 @findex set-file-modes
 @cindex file modes
diff --git a/etc/NEWS b/etc/NEWS
index fde18ed391..d83572958b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -91,6 +91,11 @@ required capabilities are found in terminfo.  See the FAQ node
 
 * Changes in Emacs 26.1
 
++++
+** The functions write-region, append-to-file, and the like now output
+the number of characters added in addition to the name of the file
+affected.
+
 ** The variable 'emacs-version' no longer includes the build number.
 This is now stored separately in a new variable, 'emacs-build-number'.
 
diff --git a/lisp/epa-file.el b/lisp/epa-file.el
index c97acb837a..bc97992b5f 100644
--- a/lisp/epa-file.el
+++ b/lisp/epa-file.el
@@ -290,7 +290,7 @@ epa-file-write-region
     (if (or (eq visit t)
 	    (eq visit nil)
 	    (stringp visit))
-	(message "Wrote %s" buffer-file-name))))
+	(message "Wrote %d characters to %s" (- end start) buffer-file-name))))
 (put 'write-region 'epa-file 'epa-file-write-region)
 
 (defun epa-file-select-keys ()
diff --git a/lisp/gnus/mm-util.el b/lisp/gnus/mm-util.el
index 89f397e3ed..5a58ed15b9 100644
--- a/lisp/gnus/mm-util.el
+++ b/lisp/gnus/mm-util.el
@@ -736,7 +736,7 @@ mm-append-to-file
 		     inhibit-file-name-handlers)
 	   inhibit-file-name-handlers)))
     (write-region start end filename t 'no-message)
-    (message "Appended to %s" filename)))
+    (message "Appended %d characters to %s" (- end start) filename)))
 
 (defun mm-write-region (start end filename &optional append visit lockname
 			      coding-system inhibit)
diff --git a/lisp/jka-compr.el b/lisp/jka-compr.el
index 26a7cf506f..0be349f0fd 100644
--- a/lisp/jka-compr.el
+++ b/lisp/jka-compr.el
@@ -357,7 +357,7 @@ jka-compr-write-region
 	  (and (or (eq visit t)
 		   (eq visit nil)
 		   (stringp visit))
-	       (message "Wrote %s" visit-file))
+	       (message "Wrote %d characters to %s" (- end start) visit-file))
 
 	  ;; ensure `last-coding-system-used' has an appropriate value
 	  (setq last-coding-system-used coding-system-used)
diff --git a/lisp/net/ange-ftp.el b/lisp/net/ange-ftp.el
index cafdb3ecb0..54ffa3551f 100644
--- a/lisp/net/ange-ftp.el
+++ b/lisp/net/ange-ftp.el
@@ -3284,7 +3284,7 @@ ange-ftp-write-region
 		(set-buffer-modified-p nil)))
 	  ;; ensure `last-coding-system-used' has an appropriate value
 	  (setq last-coding-system-used coding-system-used)
-	  (ange-ftp-message "Wrote %s" abbr)
+	  (ange-ftp-message "Wrote %d characters to %s" (- end start) abbr)
 	  (ange-ftp-add-file-entry filename))
       (ange-ftp-real-write-region start end filename append visit))))
 
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el
index dd42d9c983..0a952dcca1 100644
--- a/lisp/net/tramp-gvfs.el
+++ b/lisp/net/tramp-gvfs.el
@@ -1224,7 +1224,7 @@ tramp-gvfs-handle-write-region
 
     ;; The end.
     (when (or (eq visit t) (null visit) (stringp visit))
-      (tramp-message v 0 "Wrote %s" filename))
+      (tramp-message v 0 "Wrote %d characters to %s" (- end start) filename))
     (run-hooks 'tramp-handle-write-region-hook)))
 
 
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 6cd52ae4e0..d1ef1448bb 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -3414,7 +3414,8 @@ tramp-sh-handle-write-region
         (when need-chown
           (tramp-set-file-uid-gid filename uid gid))
 	(when (or (eq visit t) (null visit) (stringp visit))
-	  (tramp-message v 0 "Wrote %s" filename))
+          (tramp-message v 0 "Wrote %d characters to %s"
+                         (- end start) filename))
 	(run-hooks 'tramp-handle-write-region-hook)))))
 
 (defvar tramp-vc-registered-file-names nil
diff --git a/src/fileio.c b/src/fileio.c
index acbf76e0d8..bc99ee236c 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -5150,12 +5150,13 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
     }
 
   if (!auto_saving && !noninteractive)
-    message_with_string ((NUMBERP (append)
-			  ? "Updated %s"
-			  : ! NILP (append)
-			  ? "Added to %s"
-			  : "Wrote %s"),
-			 visit_file, 1);
+    message ((NUMBERP (append)
+              ? "Updated %"pI"d characters of %s"
+              : ! NILP (append)
+              ? "Added %"pI"d characters to %s"
+              : "Wrote %"pI"d characters to %s"),
+             XINT (end) - XINT (start),
+             SDATA (ENCODE_SYSTEM (visit_file)));
 
   return Qnil;
 }
-- 
2.11.1