unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#65251: 30.0.50; Duration in compilation buffer
@ 2023-08-12 18:30 Helmut Eller
  2023-08-16 19:15 ` Mattias Engdegård
  0 siblings, 1 reply; 10+ messages in thread
From: Helmut Eller @ 2023-08-12 18:30 UTC (permalink / raw)
  To: 65251

[-- Attachment #1: Type: text/plain, Size: 274 bytes --]

In the *compilation* buffer, we see timestamps when the compilation
started and finished.  It would be nice to also see how long the
compilation command took.  The attached patch does that.  It looks like
this:

  Compilation finished at Sat Aug 12 20:23:57, 2.52s

Helmut


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-When-a-compilation-finishes-show-how-long-it-took.patch --]
[-- Type: text/x-diff, Size: 2131 bytes --]

From d6bdf293287a5f252de0cf2dd00cfeaff1c02f80 Mon Sep 17 00:00:00 2001
From: Helmut Eller <eller.helmut@gmail.com>
Date: Sat, 12 Aug 2023 19:17:43 +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 | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 6d151db8a83..276c9a5d3e1 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.
+(defvar 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-local compilation--start-time (current-time))
 	(setq thisdir default-directory))
       (set-buffer-modified-p nil))
     ;; Pop up the compilation buffer.
@@ -2480,7 +2484,15 @@ 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)
+     ", "
+     (let* ((secs (float-time (time-since compilation--start-time))))
+       (cond ((< secs 1) (format "%.0fms" (* secs 1000)))
+	     ((< secs 10) (format "%.2fs" secs))
+	     ((< secs 60) (format "%.1fs" secs))
+	     (t (format-seconds "%hh%mm%z%ss" secs)))))
     (goto-char (point-max))
     ;; Prevent that message from being recognized as a compilation error.
     (add-text-properties omax (point)
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-08-19  5:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-12 18:30 bug#65251: 30.0.50; Duration in compilation buffer Helmut Eller
2023-08-16 19:15 ` Mattias Engdegård
2023-08-16 22:36   ` Helmut Eller
2023-08-17  5:33     ` Eli Zaretskii
2023-08-17  5:55       ` Helmut Eller
2023-08-17  6:05         ` Eli Zaretskii
2023-08-17 18:48           ` Helmut Eller
2023-08-18 12:06             ` Mattias Engdegård
2023-08-18 20:55               ` Helmut Eller
2023-08-19  5:54                 ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).