6

I love using emacs to compile my C++ project using compilation mode and next-error to jump to the warnings and errors in the source. However, I find it highly annoying that next-error brings me to every #include for the lines "In file included from" in the compilation output. I know you can use compilation-skip-threshold to skip warnings, but I don't want to skip warnings, and these include lines show up as warnings.

To me this seems to be a bug in compilation mode (these aren't warnings), but this bug was closed as "not a bug"

Specifically, for an output that looks like this:

In file included from /path/to/file1.h:linenum1:
In file included from /path/to/file2.h:linenum2:
In file included from /path/to/file3.h:linenum3:
/path/to/file4.h:linenum4:columnnum4: warning: you are bad at c++

I want next-error to take me right to file4.h, instead of stopping in files 1 through 3 on the way.

Thanks!

stokastic
  • 986
  • 2
  • 7
  • 19

2 Answers2

5

I tried it for myself. We seem to have different gcc versions, because my output looks like this:

g++ test.cc 
In file included from file3.h:1:0,
                 from file2.h:1,
                 from file1.h:2,
                 from test.cc:2:
file4.h:1:2: warning: #warning "you are bad at c++" [-Wcpp]

But I still see the problem. Apparently, it's the 'gcc-include regexp that breaks things. In my situation, all those "from" lines match correctly but the last one. The problem is that it ends in a colon and this somehow makes it a warning. I'm a bit lazy now to check what possible gcc output message does such matching target (there should be a reason for it, huh?), so I'll just answer the question:

;; This element is what controls the matching behaviour: according to
;; `compilation-error-regexp-alist` doc, it means if subexpression 4 of the
;; regexp matches, it's a warning, if subexpression 5 matches, it's an info.
(nth 5 (assoc 'gcc-include compilation-error-regexp-alist-alist))
(4 . 5)

;; We could try and tinker with the regexp, but it's simpler to just set it as
;; "always match as info".
(setf (nth 5 (assoc 'gcc-include compilation-error-regexp-alist-alist)) 0)

This snippet stopped compilation mode from highlighting last "from" line as a warning for me.

immerrr
  • 1,251
  • 7
  • 13
  • Awesome thanks! Turns out someone switched the project to use clang instead of gcc, so that's why the messages look different, but your command worked. I got an error with `setf` though, but by changing it to `(setcar (nthcdr 5 (assoc 'gcc-include compilation-error-regexp-alist-alist)) 0)` I got it to work. I'm very inexperienced with lisp and elisp, so maybe I did something dumb, but it seems to work – stokastic Mar 19 '13 at 17:49
  • @stokastic, no, I don't think it's you. This issue has been bugging me for ages and it survived several reincarnations of my init-file and couple of Emacs versions. – immerrr Mar 19 '13 at 20:15
  • A correction: actually, both 'gnu and 'gcc-include match the OP's output. That's why DrC's suggestion to remove 'gcc-include doesn't suffice. Since your idea to use 'gcc-include to mark those lines as info works, it must be that marking them as info prevents them from being marked as error later. Note that, for this to work, it's important that 'gcc-include comes before 'gnu on the list. – User123abc Jul 09 '13 at 22:44
2

Configure compilation-skip-threshold.

Stefan
  • 27,908
  • 4
  • 53
  • 82