Subject: bug#24861: [PATCH] Fix annoying "Parsing...done" message in c++-mode

From: Hong Xu <[email-masked]>
Date: Fri, 18 Nov 2016 11:55:28 -0800

On 11/18/2016 01:39 AM, Eli Zaretskii wrote:
>> From: Hong Xu <[email-masked]>
>> Cc: [email-masked]
>> Date: Tue, 15 Nov 2016 16:03:19 -0800
>>
>> Can you still consider this patch?
> 
> I'm okay with accepting this for the master branch, but the patch
> needs some more work to fix the following issues:
> 
>  . The first line of each doc string should be a complete sentence.
>  . The doc string of cpp-progress-message should mention
>    cpp-message-min-time-interval.
>  . The defcustom you are adding should have a :version tag.
>  . The calculation in cpp-progress-message should be fixed to
>    calculate the time difference between the current time and the time
>    of the previous progress message, and compare that with the value
>    of cpp-message-min-time-interval.  The old code just looked at the
>    2nd member of the list returned by current-time, but that is no
>    longer TRT when you need to compare the time difference, because
>    that member can go back to zero.  You need to use time-subtract.
>  . Last, but not least: please include ChangeLog-style commit log
>    message for the changes.
> 

Allow users to customize the maximum frequency that
`cpp-progress-message' prints messages.

	* progmodes/cpp.el (cpp-message-min-time-interval)
	(cpp-progress-message): Add variable
	`cpp-message-min-time-interval' to indicate the minimum time
	interval in seconds that `cpp-progress-message' prints messages.

	* progmodes/cpp.el (cpp-progress-time): Initialize to '(0 0 0 0) instead of
	0 and improve the documentation.

	* progmodes/cpp.el (cpp-highlight-buffer): Use
	`cpp-progress-message' instead of `message'.

Thanks.
diff --git a/lisp/progmodes/cpp.el b/lisp/progmodes/cpp.el
index 7d641ab47f09..41b7fc968a2d 100644
--- a/lisp/progmodes/cpp.el
+++ b/lisp/progmodes/cpp.el
@@ -104,6 +104,14 @@ cpp-edit-list
 			       (const :tag "Both branches writable" both))))
   :group 'cpp)
 
+(defcustom cpp-message-min-time-interval 1.0
+  "Indicate the minimum time interval in seconds that
+`cpp-progress-message' should print messages.
+`cpp-progress-message' prints no message if it is set to nil."
+  :type 'float
+  :group 'cpp
+  :version "26.1")
+
 (defvar cpp-overlay-list nil)
 ;; List of cpp overlays active in the current buffer.
 (make-variable-buffer-local 'cpp-overlay-list)
@@ -278,7 +286,7 @@ cpp-highlight-buffer
 			  (cpp-parse-close from to))
 			 (t
 			  (cpp-parse-error "Parser error"))))))))
-      (message "Parsing...done"))
+      (cpp-progress-message "Parsing...done"))
     (if cpp-state-stack
       (save-excursion
 	(goto-char (nth 3 (car cpp-state-stack)))
@@ -819,16 +827,21 @@ cpp-face-name
 
 ;;; Utilities:
 
-(defvar cpp-progress-time 0)
-;; Last time we issued a progress message.
+(defvar cpp-progress-time '(0 0 0 0)
+  "Indicate the last time `cpp-progress-message' issued a
+  progress message.")
 
 (defun cpp-progress-message (&rest args)
-  ;; Report progress at most once a second.  Take same ARGS as `message'.
-  (let ((time (nth 1 (current-time))))
-    (if (= time cpp-progress-time)
-	()
-      (setq cpp-progress-time time)
-      (apply 'message args))))
+  "Report progress by printing messages at most once every
+`cpp-message-min-time-interval' seconds for functions whose names
+start with \"cpp-\".  If `cpp-message-min-time-interval' is nil,
+it prints no message.  The ARGS are the same as in `message'."
+  (when cpp-message-min-time-interval
+    (let ((time (current-time)))
+      (when (>= (float-time (time-subtract time cpp-progress-time))
+                cpp-message-min-time-interval)
+        (setq cpp-progress-time time)
+        (apply 'message args)))))
 
 (provide 'cpp)