Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

matching different line number format in grep-mode

23 views
Skip to first unread message

Jim Newton

unread,
Jun 21, 2012, 8:55:10 AM6/21/12
to
I have an application which prints line number information not in the standard grep format but as follows.

at line 302 in file /full/path/to/file.ext

Is there something I can do to the variable compilation-error-regexp-alist-alist
which will cause grep-mode to also find these lines?

I see the pattern when I look at the variable, but what's the flow to make either grep-mode or some other mode actually find these lines on next-error ?

Jim

Stefan Monnier

unread,
Jun 25, 2012, 12:04:57 PM6/25/12
to
> I have an application which prints line number information not in the
> standard grep format but as follows.

> at line 302 in file /full/path/to/file.ext

> Is there something I can do to the variable compilation-error-regexp-alist-alist
> which will cause grep-mode to also find these lines?

Does it have to be grep-mode? If you can use compilation-mode, than
adding the relevant regexp to compilation-error-regexp-alist should
be sufficient. Otherwise you might want to use define-compilation-mode.


Stefan

Jim Newton

unread,
Jun 27, 2012, 4:31:37 AM6/27/12
to
Thanks Stephan, this is on the right track.

can you show me how to do this with define-compilation-mode?

Jim

Aurélien Aptel

unread,
Jun 27, 2012, 7:41:38 AM6/27/12
to Jim Newton, help-gn...@gnu.org
On Wed, Jun 27, 2012 at 10:31 AM, Jim Newton
<jimka....@googlemail.com> wrote:
> can you show me how to do this with define-compilation-mode?

I don't know what define-compilation-mode is, but why can't you use
the compilation-mode and the compilation-error-regexp-alist variable?

Eval this in your scratch buffer (select everything and run M-x eval-region):

(require 'compile)
(add-to-list 'compilation-error-regexp-alist '("^at line
\\([0-9]+\\) in file \\(.+\\)$" 2 1))

I've used this as a test (it works):
M-x compile RET echo at line 42 in file /foo/bar RET

To make it permanent you can add this to your .emacs:

(eval-after-load "compile"
'(add-to-list 'compilation-error-regexp-alist '("^at line
\\([0-9]+\\) in file \\(.+\\)$" 2 1)))

You have to use eval-after-load in your .emacs because the variable
compilation-...-alist is defined only once compile.el is loaded. And
it is automatically loaded when you call M-x compile or any autoloaded
function in compile.el (the ones with the ;;;###autoload cookie
above).

Alternatively you could just copy what you've pasted in *scratch* in
your .emacs but it load compile.el every time you start emacs i.e. it
will slightly slowdown your emacs startup time.

I'm sorry if all of this is obvious to you.

Stefan Monnier

unread,
Jun 27, 2012, 11:53:06 AM6/27/12
to
> can you show me how to do this with define-compilation-mode?

I'd suggest you try: C-h f grep-mode RET and then to click on "grep.el"
to jump to the definition of grep-mode, which is done with
define-compilation-mode and should be a good example to copy.


Stefan
0 new messages