Skip to content

Commit 846870e

Browse files
committed
Show number of errors in compilation-mode mode-line
Bug#25354 * lisp/progmodes/compile.el (compilation-num-errors-found): Provide default value. (compilation-num-warnings-found, compilation-num-infos-found): New defvars. (compilation-mode-line-errors): New defconst. (compilation-face): Remove. (compilation-type, compilation--note-type): New functions. (compilation-parse-errors): Call compilation--note-type. (compilation-start): Include compilation-mode-line-errors in mode-line-process. (compilation-setup): Initialize compilation-num-* variables to 0. (compilation-handle-exit): Include compilation-mode-line-errors in mode-line-process. * doc/emacs/building.texi (Compilation): Document new feature.
1 parent c3445ae commit 846870e

File tree

3 files changed

+64
-23
lines changed

3 files changed

+64
-23
lines changed

doc/emacs/building.texi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ inserted above point, which remains at the end. Otherwise, point
9090
remains fixed while compilation output is added at the end of the
9191
buffer.
9292

93+
While compilation proceeds, the mode line is updated to show the
94+
number of errors, warnings, and informational messages that have been
95+
seen so far.
96+
9397
@cindex compilation buffer, keeping point at end
9498
@vindex compilation-scroll-output
9599
If you change the variable @code{compilation-scroll-output} to a

etc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,11 @@ where to place point after C-c M-r and C-c M-s.
740740
---
741741
*** Messages from CMake are now recognized.
742742

743+
+++
744+
*** The number of errors, warnings, and informational messages is now
745+
displayed in the mode line. These are updated as compilation
746+
proceeds.
747+
743748
+++
744749
*** A new option 'dired-always-read-filesystem' default to nil.
745750
If non-nil, buffers visiting files are reverted before search them;

lisp/progmodes/compile.el

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,21 @@ and a string describing how the process finished.")
127127
(defvar compilation-arguments nil
128128
"Arguments that were given to `compilation-start'.")
129129

130-
(defvar compilation-num-errors-found)
130+
(defvar compilation-num-errors-found 0)
131+
(defvar compilation-num-warnings-found 0)
132+
(defvar compilation-num-infos-found 0)
133+
134+
(defconst compilation-mode-line-errors
135+
'(" [" (:propertize (:eval (int-to-string compilation-num-errors-found))
136+
face compilation-error
137+
help-echo "Number of errors so far")
138+
" " (:propertize (:eval (int-to-string compilation-num-warnings-found))
139+
face compilation-warning
140+
help-echo "Number of warnings so far")
141+
" " (:propertize (:eval (int-to-string compilation-num-infos-found))
142+
face compilation-info
143+
help-echo "Number of informational messages so far")
144+
"]"))
131145

132146
;; If you make any changes to `compilation-error-regexp-alist-alist',
133147
;; be sure to run the ERT test in test/lisp/progmodes/compile-tests.el.
@@ -886,10 +900,10 @@ from a different message."
886900
:group 'compilation
887901
:version "22.1")
888902

889-
(defun compilation-face (type)
890-
(or (and (car type) (match-end (car type)) compilation-warning-face)
891-
(and (cdr type) (match-end (cdr type)) compilation-info-face)
892-
compilation-error-face))
903+
(defun compilation-type (type)
904+
(or (and (car type) (match-end (car type)) 1)
905+
(and (cdr type) (match-end (cdr type)) 0)
906+
2))
893907

894908
;; LOC (or location) is a list of (COLUMN LINE FILE-STRUCTURE nil nil)
895909

@@ -1334,6 +1348,14 @@ FMTS is a list of format specs for transforming the file name.
13341348

13351349
(compilation-parse-errors start end)))
13361350

1351+
(defun compilation--note-type (type)
1352+
"Note that a new message with severity TYPE was seen.
1353+
This updates the appropriate variable used by the mode-line."
1354+
(cl-case type
1355+
(0 (cl-incf compilation-num-infos-found))
1356+
(1 (cl-incf compilation-num-warnings-found))
1357+
(2 (cl-incf compilation-num-errors-found))))
1358+
13371359
(defun compilation-parse-errors (start end &rest rules)
13381360
"Parse errors between START and END.
13391361
The errors recognized are the ones specified in RULES which default
@@ -1397,14 +1419,17 @@ to `compilation-error-regexp-alist' if RULES is nil."
13971419
file line end-line col end-col (or type 2) fmt))
13981420

13991421
(when (integerp file)
1422+
(setq type (if (consp type)
1423+
(compilation-type type)
1424+
(or type 2)))
1425+
(compilation--note-type type)
1426+
14001427
(compilation--put-prop
14011428
file 'font-lock-face
1402-
(if (consp type)
1403-
(compilation-face type)
1404-
(symbol-value (aref [compilation-info-face
1405-
compilation-warning-face
1406-
compilation-error-face]
1407-
(or type 2))))))
1429+
(symbol-value (aref [compilation-info-face
1430+
compilation-warning-face
1431+
compilation-error-face]
1432+
type))))
14081433

14091434
(compilation--put-prop
14101435
line 'font-lock-face compilation-line-face)
@@ -1768,7 +1793,8 @@ Returns the compilation buffer created."
17681793
outbuf command))))
17691794
;; Make the buffer's mode line show process state.
17701795
(setq mode-line-process
1771-
'(:propertize ":%s" face compilation-mode-line-run))
1796+
'((:propertize ":%s" face compilation-mode-line-run)
1797+
compilation-mode-line-errors))
17721798

17731799
;; Set the process as killable without query by default.
17741800
;; This allows us to start a new compilation without
@@ -1797,7 +1823,8 @@ Returns the compilation buffer created."
17971823
(message "Executing `%s'..." command)
17981824
;; Fake mode line display as if `start-process' were run.
17991825
(setq mode-line-process
1800-
'(:propertize ":run" face compilation-mode-line-run))
1826+
'((:propertize ":run" face compilation-mode-line-run)
1827+
compilation-mode-line-errors))
18011828
(force-mode-line-update)
18021829
(sit-for 0) ; Force redisplay
18031830
(save-excursion
@@ -2106,6 +2133,9 @@ Optional argument MINOR indicates this is called from
21062133
(make-local-variable 'compilation-messages-start)
21072134
(make-local-variable 'compilation-error-screen-columns)
21082135
(make-local-variable 'overlay-arrow-position)
2136+
(setq-local compilation-num-errors-found 0)
2137+
(setq-local compilation-num-warnings-found 0)
2138+
(setq-local compilation-num-infos-found 0)
21092139
(set (make-local-variable 'overlay-arrow-string) "")
21102140
(setq next-error-overlay-arrow-position nil)
21112141
(add-hook 'kill-buffer-hook
@@ -2195,16 +2225,18 @@ commands of Compilation major mode are available. See
21952225
(add-text-properties omax (point)
21962226
(append '(compilation-handle-exit t) nil))
21972227
(setq mode-line-process
2198-
(let ((out-string (format ":%s [%s]" process-status (cdr status)))
2199-
(msg (format "%s %s" mode-name
2200-
(replace-regexp-in-string "\n?$" ""
2201-
(car status)))))
2202-
(message "%s" msg)
2203-
(propertize out-string
2204-
'help-echo msg
2205-
'face (if (> exit-status 0)
2206-
'compilation-mode-line-fail
2207-
'compilation-mode-line-exit))))
2228+
(list
2229+
(let ((out-string (format ":%s [%s]" process-status (cdr status)))
2230+
(msg (format "%s %s" mode-name
2231+
(replace-regexp-in-string "\n?$" ""
2232+
(car status)))))
2233+
(message "%s" msg)
2234+
(propertize out-string
2235+
'help-echo msg
2236+
'face (if (> exit-status 0)
2237+
'compilation-mode-line-fail
2238+
'compilation-mode-line-exit)))
2239+
compilation-mode-line-errors))
22082240
;; Force mode line redisplay soon.
22092241
(force-mode-line-update)
22102242
(if (and opoint (< opoint omax))

0 commit comments

Comments
 (0)