GNU bug report logs - #65251
30.0.50; Duration in compilation buffer

Previous Next

Package: emacs;

Reported by: Helmut Eller <eller.helmut <at> gmail.com>

Date: Sat, 12 Aug 2023 18:32:02 UTC

Severity: normal

Found in version 30.0.50

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


Message #23 received at 65251 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: mattias.engdegard <at> gmail.com, 65251 <at> debbugs.gnu.org
Subject: Re: bug#65251: 30.0.50; Duration in compilation buffer
Date: Thu, 17 Aug 2023 20:48:22 +0200
[Message part 1 (text/plain, inline)]
On Thu, Aug 17 2023, Eli Zaretskii wrote:

> I intended to install this once there are no more review comments, as
> I think this could be a useful addition.  I believe Mattias also
> thought the idea was a good one.  So my preference is for you to post
> an updated patch, yes.

Here it is:

[0001-When-a-compilation-finishes-show-how-long-it-took.patch (text/x-diff, inline)]
From 3f41a75a61a08c1e2850bf3e3e4d1d2d137aeedd Mon Sep 17 00:00:00 2001
From: Helmut Eller <eller.helmut <at> gmail.com>
Date: Thu, 17 Aug 2023 20:46:05 +0200
Subject: [PATCH] When a compilation finishes, show how long it took

Insert the duration, not just the timestamp.

* lisp/progmodes/compile.el (compilation--start-time): New variable.
(compilation-start): Set it.
(compilation-handle-exit): Use it to compute the duration and insert
it in human readable form.
---
 lisp/progmodes/compile.el | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 6d151db8a83..a41fca7de1e 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -1862,6 +1862,9 @@ compilation-insert-annotation
     (apply #'insert args)
     (put-text-property start (point) 'compilation-annotation t)))
 
+;; The time when the compilation started as returned by `float-time'.
+(defvar-local compilation--start-time nil)
+
 ;;;###autoload
 (defun compilation-start (command &optional mode name-function highlight-regexp
                                   continue)
@@ -1993,6 +1996,7 @@ compilation-start
                  mode-name
 		 (substring (current-time-string) 0 19))
 	 command "\n")
+        (setq compilation--start-time (float-time))
 	(setq thisdir default-directory))
       (set-buffer-modified-p nil))
     ;; Pop up the compilation buffer.
@@ -2480,7 +2484,14 @@ compilation-handle-exit
 	(message "%s" (cdr status)))
     (if (bolp)
 	(forward-char -1))
-    (compilation-insert-annotation " at " (substring (current-time-string) 0 19))
+    (compilation-insert-annotation
+     " at "
+     (substring (current-time-string) 0 19)
+     ", duration "
+     (let* ((secs (- (float-time) compilation--start-time)))
+       (cond ((< secs 10) (format "%.2f s" secs))
+	     ((< secs 60) (format "%.1f s" secs))
+	     (t (format-seconds "%h:%m:%s" secs)))))
     (goto-char (point-max))
     ;; Prevent that message from being recognized as a compilation error.
     (add-text-properties omax (point)
-- 
2.39.2


This bug report was last modified 1 year and 305 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.