5

I try to define a custom coloring of the compilation buffer, but I can not get the highlight correctly.

(add-to-list 'compilation-error-regexp-alist 'my-message)
(add-to-list 'compilation-error-regexp-alist-alist
  '(my-message
    "^\\(\\(ERRR\\|CRIT\\|ALRT\\|EMRG\\)\\|\\(WARN\\|NTCE\\)\\|\\(INFO\\|DEBG\\)\\) .*\\[\\(\\([^ \n]+\\):\\([0-9]+\\)\\)\\]$"
    6 7 nil (3 . 4) 5))

This correctly colors the hyperlink:

enter image description here

But I can not get the beginning of the line right. I would like the tags WARN, INFO, NTCE, DEBG and ERRR to have the same color as the hyperlink. But everything I tried did not work. I get either the error, that the match does not exists of the color for all lines is fixed.

How to color the beginning of the line in the same color like the hyperlink?

3

Adding some additional HIGHLIGHT parameters to your list should do it. As stated in Emacs' documentation for the variable compilation-error-regexp-alist:

Additional HIGHLIGHTs take the shape (SUBMATCH FACE), where SUBMATCH is the number of a submatch and FACE is an expression which evaluates to a face name (a symbol or string).


In your case, it should reduce to something like the following:

(add-to-list 'compilation-error-regexp-alist-alist
             '(my-message
               "^\\(\\(ERRR\\|CRIT\\|ALRT\\|EMRG\\)\\|\\(WARN\\|NTCE\\)\\|\\(INFO\\|DEBG\\)\\) .*\\[\\(\\([^ \n]+\\):\\([0-9]+\\)\\)\\]$"
               6 7 nil (3 . 4) 5
               (2 compilation-error-face)
               (3 compilation-warning-face)
               (4 compilation-info-face)))

Another, more verbose solution might be to define multiple regular expressions for your different levels, so that all groups always match.

(add-to-list 'compilation-error-regexp-alist 'my-message-error)
(add-to-list 'compilation-error-regexp-alist 'my-message-warning)
(add-to-list 'compilation-error-regexp-alist 'my-message-info)
(add-to-list 'compilation-error-regexp-alist-alist
     '(my-message-error
       "^\\(ERRR\\|CRIT\\|ALRT\\|EMRG\\) .*\\[\\(\\([^ \n]+\\):\\([0-9]+\\)\\)\\]$"
       3 4 nil nil 2
       (1 compilation-error-face)))
(add-to-list 'compilation-error-regexp-alist-alist
     '(my-message-warning
       "^\\(WARN\\|NTCE\\) .*\\[\\(\\([^ \n]+\\):\\([0-9]+\\)\\)\\]$"
       3 4 nil 1 2
       (1 compilation-warning-face)))
(add-to-list 'compilation-error-regexp-alist-alist
     '(my-message-info
       "^\\(INFO\\|DEBG\\) .*\\[\\(\\([^ \n]+\\):\\([0-9]+\\)\\)\\]$"
       3 4 nil 0 2
       (1 compilation-info-face)))
  • Yes I tried that. But it is always just one match defined of the matches 2, 3 and 4. The others are undefined. And in that case Emacs complains about the fact, that I have specified a highlighting definition for an undefined match. – ceving Sep 1 '15 at 13:01
  • Well, it works in my settings (emacs 24.5.1). Which version are you using? Have you tried using emacs -q to check whether some setting in your init file might be responsible for this behaviour? – Francesco Sep 1 '15 at 14:50
  • You are right. I thought I did it as you told me, but obviously I did something different. – ceving Sep 4 '15 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.