Subject: 25.1.50; progress-reporter with 2 text messages

From: Tino Calancha <[email-masked]>
Date: Tue, 22 Mar 2016 19:59:32 +0900 (JST)

Adding a second optional message in progress-reporter
provides more control in the output format.
When both, NEW-MESSAGE and NEW-MESAGE2
are provided to `progress-reporter-force-update', the
structure of the output string would be as follows:

1) MESSAGE: it may be the operation under course.
2) As before, the status index (i.e., 30%).
3) MESSAGE2: it may be, i.e., the current file being processed.

In following example, the status index changes the position with
every message, which is distracting.

emacs -Q:
(let* ((games '("Mega Man"
 			   "Street Fighter II: The World Warrior"
 			   "Double Dragon"
 			   "Very long game with lot of stages: requires many months to complete"
 			   "The Legend Of Zelda"
 			   "Pac-Man"))
 	   (num-games (length games))
 	   (text "Checking game...")
 	   (prep (make-progress-reporter text 0 num-games)))
   (dotimes (i num-games)
 	(progress-reporter-force-update prep i
 					(format "Checking game... (%s) " (nth i games)))

 	(sit-for (or (and (= i 3) 5) 1)))
   (message "Games check completed!"))

; A second optional string allows to present the information as described in 1-2-3 above:
(progress-reporter-force-update prep i text
 				(format "(%s)" (nth i games)))

; This would display the index string in the same position for each update.

In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 2.24.29)
  of 2016-03-10 built on calancha-pc
Repository revision: 780a605e1d2de4b975e6f1f29b491c9af419dcff

diff --git a/lisp/subr.el b/lisp/subr.el
index cad6319..e5325f4 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -4711,7 +4711,7 @@ progress-reporter-update
     (progress-reporter-do-update reporter value)))
 
 (defun make-progress-reporter (message &optional min-value max-value
-				       current-value min-change min-time)
+				       current-value min-change min-time message2)
   "Return progress reporter object for use with `progress-reporter-update'.
 
 MESSAGE is shown in the echo area, with a status indicator
@@ -4739,7 +4739,9 @@ make-progress-reporter
 echo area updates (default is 0.2 seconds.)  If the function
 `float-time' is not present, time is not tracked at all.  If the
 OS is not capable of measuring fractions of seconds, this
-parameter is effectively rounded up."
+parameter is effectively rounded up.
+Optional MESSAGE2 is a text to follow the status indicator: i.e.
+the current file being processed."
   (when (string-match "[[:alnum:]]\\'" message)
     (setq message (concat message "...")))
   (unless min-time
@@ -4754,18 +4756,22 @@ make-progress-reporter
 		       max-value
 		       message
 		       (if min-change (max (min min-change 50) 1) 1)
-		       min-time))))
+		       min-time
+                       message2))))
     (progress-reporter-update reporter (or current-value min-value))
     reporter))
 
-(defun progress-reporter-force-update (reporter &optional value new-message)
+(defun progress-reporter-force-update (reporter &optional value new-message new-message2)
   "Report progress of an operation in the echo area unconditionally.
 
 The first two arguments are the same as in `progress-reporter-update'.
-NEW-MESSAGE, if non-nil, sets a new message for the reporter."
+NEW-MESSAGE, if non-nil, sets a new message for the reporter.
+NEW-MESSAGE2, if non-nil, sets a new message after the status indicator."
   (let ((parameters (cdr reporter)))
     (when new-message
       (aset parameters 3 new-message))
+    (when new-message2
+      (aset parameters 6 new-message2))
     (when (aref parameters 0)
       (aset parameters 0 (float-time)))
     (progress-reporter-do-update reporter value)))
@@ -4779,6 +4785,7 @@ progress-reporter-do-update
 	 (min-value    (aref parameters 1))
 	 (max-value    (aref parameters 2))
 	 (text         (aref parameters 3))
+	 (text2        (aref parameters 6))
 	 (enough-time-passed
 	  ;; See if enough time has passed since the last update.
 	  (or (not update-time)
@@ -4809,17 +4816,18 @@ progress-reporter-do-update
 	     ;; Only print message if enough time has passed
 	     (when enough-time-passed
 	       (if (> percentage 0)
-		   (message "%s%d%%" text percentage)
-		 (message "%s" text)))))
+		   (message "%s%d%% %s" text percentage (or text2 ""))
+		 (message "%s %s" text (or text2 ""))))))
 	  ;; Pulsing indicator
 	  (enough-time-passed
 	   (let ((index (mod (1+ (car reporter)) 4))
 		 (message-log-max nil))
 	     (setcar reporter index)
-	     (message "%s %s"
+	     (message "%s %s %s"
 		      text
 		      (aref progress-reporter--pulse-characters
-			    index)))))))
+			    index)
+                      (or text2 "")))))))
 
 (defun progress-reporter-done (reporter)
   "Print reporter's message followed by word \"done\" in echo area."