1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

Show duration of compilation when it stops (bug#65251)

Patch by Helmut Eller, lightly edited.

* lisp/progmodes/compile.el (compilation--start-time): New variable.
(compilation-start): Set it.
(compilation-handle-exit): Display duration.
This commit is contained in:
Mattias Engdegård 2023-08-18 13:23:39 +02:00
parent 02d96e39b2
commit cc533f2338

View file

@ -1862,6 +1862,9 @@ process from additional information inserted by Emacs."
(apply #'insert args)
(put-text-property start (point) 'compilation-annotation t)))
(defvar-local compilation--start-time nil
"The time when the compilation started as returned by `float-time'.")
;;;###autoload
(defun compilation-start (command &optional mode name-function highlight-regexp
continue)
@ -1993,6 +1996,7 @@ Returns the compilation buffer created."
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 @@ commands of Compilation major mode are available. See
(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 ((elapsed (- (float-time) compilation--start-time)))
(cond ((< elapsed 10) (format "%.2f s" elapsed))
((< elapsed 60) (format "%.1f s" elapsed))
(t (format-seconds "%h:%02m:%02s" elapsed)))))
(goto-char (point-max))
;; Prevent that message from being recognized as a compilation error.
(add-text-properties omax (point)