I'm using native windows emacs together with mingw. When there's a compile error, the *compilation* buffer looks like this:

make -C ..
make: Entering directory `/c/Users/m.grunwald/Documents/Projects/aaaa/bbbb/cccc/dddd'
compiling Update.c
../Source/Update.c: In function 'SetMessage':
../Source/Update.c:52:1: error: 'd' undeclared (first use in this     function)

When I use (next-error), emacs prompts me to "Find this error in...:" and the path it suggests is


Now this is neither a valid windows nor a valid mingw path and it makes compiling tideous. How do I get rid of the leading "C:" ?

Please note that the path that "make" prompts in the 2nd line is correct.

The linked topic "C:/c/user/...my-folder/ isn't an existing directory" error is about the same problem, but fixes it only in magit. I have no idea where I should tackle the problem for compile-mode and this is the wrong aproach, IMHO. It should be possible to fix this in emacs itself and only once, not once in each mode...

  • 3
    Related: emacs.stackexchange.com/questions/12593/…, not sure offhand how to fix it for compilation mode though.
    – npostavs
    Jan 14 '16 at 15:22
  • I strongly suggest that you do not mix native Windows Emacs with POSIX-y tools.
    – nanny
    Jan 14 '16 at 17:15
  • @nanny: Difficult. Emacs on cygwin works well, but is slow as molassis compared to the native one. I don't want to give up this speed!
    – Markus
    Jan 22 '16 at 12:15
  • @Markus In my opinion, it's definitely worth it to use Cygwin. Another alternative is to use an X server on Windows (e.g. VcXsrv) with Putty, and forward Emacs from a gnu/linux server.
    – nanny
    Jan 22 '16 at 14:17
  • 1
    maybe cygwin-mount.el would help? gnu.org/software/emacs/manual/html_node/efaq-w32/…
    – npostavs
    Jan 22 '16 at 14:53

It looks like cygwin-mount.el only works for cygwin names. Emacs already comes with unmsys--file-name to convert msys names, so I used it to write an msys file name handler for expand-file-name and substitute-in-file-name (it's unclear to me how to know which operations are important, so I just followed cygwin-mount.el's lead. The code below seems to work for me).

(defun msys-file-name-handler (operation &rest args)
  "Call `unmsys--file-name' on file names."
  (let ((inhibit-file-name-handlers
         (cons 'msys-file-name-handler
               (and (eq inhibit-file-name-operation operation)
        (inhibit-file-name-operation operation))
    (pcase (cons operation args)
      (`(expand-file-name ,name . ,(or `(,directory) directory))
       (expand-file-name (unmsys--file-name name) (if directory (unmsys--file-name directory))))
      (`(substitute-in-file-name ,name)
       (substitute-in-file-name (unmsys--file-name name)))
      (_ (apply operation args)))))

(add-to-list 'file-name-handler-alist '("\\`/[a-zA-Z]/" . msys-file-name-handler))

;; Work around apparent bug in `compilation-parse-errors'.
(defun save-match-data-advice (fun &rest args)
  "Add this as `:around' advice to save the match-data."
    (apply fun args)))

(advice-add 'compilation-error-properties :around #'save-match-data-advice)
  • Unfortunately it breaks next-error and previous-error, if I include your code...
    – Markus
    Feb 24 '17 at 9:13
  • @Markus Oh, I had only tried applying the code after running M-x compile, it does indeed break subsequent compiles. It looks like a bug in the Emacs code that doesn't save match data; I've now added some advising code to the answer to work around it.
    – npostavs
    Feb 24 '17 at 19:09
  • You, sir npostavs are my saviour! Since 1½ years I had to manually workaround this and now it works... thank you so much!
    – Markus
    Feb 27 '17 at 6:04

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.