tags:

views:

29

answers:

2

I want to modify csharp-mode.el so that it includes the appropriate error regex's (regexi?) for the .NET csc.exe compiler.

How should a well-behaved progmode do this?

+2  A: 

A well-behaved Emacs user should probably add the regexp to compilation-error-regexp-alist-alist and provide the patch to Emacs so it'll get used by all in subsequent releases.

The variable defined in compile.el and can be found via

M-x find-variable compilation-error-regexp-alist-alist RET

I don't think it makes sense for the csharp-mode major mode change the regexp. If anything, it should set the local value of compilation-error-regexp-alist to contain the new symbol you added in the ...-alist-alist variable.

That said, it could modify the ...-alist-alist variable by just checking to see if the symbol c# (or whatever you add) is a part of the list already, and add it if not. Note: the compilation-error-regexp-alist is defined apriori, so you'll want to double check that variable's contents to ensure it also contains the c# symbol.

Trey Jackson
Just a follow up; it doesn't work to add things to the two *-alist variables, inside the compilation-mode-hook. The hook runs *after* the parse, therefore, when you first do `M-x compile`, the necessary regexp will not be on the list. Subsequent `M-x compile` will have the regexp. It is appropriate to just call `add-to-list` with the right values, inside the hook for the programming mode.
Cheeso
A: 

Here's what I did inside csharp-mode:

(if (boundp 'compilation-error-regexp-alist-alist)
    (progn
      (add-to-list
       'compilation-error-regexp-alist-alist
       '(ms-csharp 
         "^[ \t]*\\([A-Za-z0-9_][^(]*\\.cs\\)(\\([0-9]+\\)[,]\\([0-9]+\\)) ?: \\(error\\|warning\\) CS[0-9]+:" 1 2 3))
      (add-to-list
       'compilation-error-regexp-alist
       'ms-csharp)))
Cheeso