I have a grep-like script that I run via M-x grep, that changes its working directory, but outputs make-like "Entering directory `/a/b/c/d'" messages (to keep emacs informed).

This has worked fine for many years, but I recently (finally) upgraded to a new Emacs, and grep-mode no longer supports matching these magic strings in the output of the grep command (see http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8895).

(This manifests as hitting next-error to go to the fine and line of the hit, and getting prompted by emacs about where to find the file since its confused about what the relative path is relative to.)

How can I get my "Entering directory" messages to be honored again?

1 Answer 1


The linked bug report pointed out that grep-mode was explicitly overriding the compilation-mode support for matching "Entering directory ..." and grep-mode-hook could be used to restore it. I bit Frankenstein coding via cut-and-paste got me this:

(setq real-directory-matcher compilation-directory-matcher)

(defun grep-mode-enable-enter-dir ()
  "Enable matching 'Entering directory ..' text in grep output"
  (setq compilation-directory-matcher real-directory-matcher)

(add-hook 'grep-mode-hook 'grep-mode-enable-enter-dir)

I put this in my emacs initialization code and it seems to restore the old behavior for me.

  • You may want to consider accepting this answer, if it solves the problem for you. That way the system does not think the question is still in need of an answer. Jul 13, 2017 at 4:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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