'How to detect exceptions as errors in emacs *compilation* buffer?
I'm running (c++ / gtest / bazel) unit-tests within emacs (ver 26.3) with results displayed in the *compilation* buffer. I would like unexpected exceptions to be detected there as errors. Exceptions start with "C++ exception with description" and it's easy to add it compilation error regex:
(add-to-list 'compilation-error-regexp-alist '("^C\\+\\+ exception with description"))
The exception lines are properly recognized as indicated by the underline.
First problem: since exceptions don't report file and line numbers, running M-] (next-error) now prompts for a file in the minibuffer. I would like it to just mark the line in the *compilation* buffer.
Second problem: even tough the regex detects the exception it's not reported in the mode line as error. In the status fragment (Compilation: exit [3] [1 0 0]
the last part should be [3 0 0]
.
Solution 1:[1]
To solve the first problem I had to use the full format of the regex list element:
(REGEXP FILE [LINE COLUMN TYPE HYPERLINK HIGHLIGHT...])
and set the HYPERLINK to non-existing captured sub-expression. See below:
(add-to-list 'compilation-error-regexp-alist
'("^\\(C\\+\\+ exception with description\\) .*thrown in the test body\\."
nil nil nil ;; file line column
2 ;; type (2-error, 1-warning, 0-info)
99 ;; hyperlink
(1 compilation-error-face)
))
Unfortunately, even explicitly setting the type TYPE to 2 didn't make it count as error in the status line; so the second problem still stands.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | GrzegDev |