From: Mattias EngdegÄrd Date: Fri, 18 Aug 2023 11:23:39 +0000 (+0200) Subject: Show duration of compilation when it stops (bug#65251) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=cc533f23386984bc3bb2c98d227d7e56e4b7b7a7;p=emacs.git 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. --- diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el index 6d151db8a83..f85cc0909dd 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el @@ -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)