(require 'shell) enables shell-dirtrack-mode globally in every buffer. Is there a way to disable that behavior?

The only workaround that I have found is to call (shell-dirtrack-mode -1) for each major mode that loads (e.g., via a major-mode hook); and, for fundamental-mode, I created a new function that calls the same thing immediately after calling kill-all-local-variables.

  • 2
    Out of curiosity, why do you want to do this?
    – PythonNut
    Feb 16, 2015 at 21:37
  • @PythonNut -- in general, I prefer that my buffers have only what is needed (without anything extra). This is especially true when I am troubleshooting / bug-fixing / developing a major or minor mode. While many people might be able to tell themselves -- "don't worry about shell-dirtrack-mode, be happy" -- I prefer that it not be there in the first instance. I am obsessive compulsive in that regard. One of the main reasons that I love Emacs and have invested so much time customizing it, is because almost everything is customizable -- I feel in control (colors / shapes / behavior / etc.).
    – lawlist
    Feb 16, 2015 at 22:36

1 Answer 1


The shell-dirtrack-mode is an alias to shell-dirtrackp. The shell-dirtrackp is initialized with the value of t in shell.el.

So this variable and thus the minor mode shell-dirtrack-mode gets a global value of t. So this mode state is always on in a fresh buffer unless you actively disable it.

The solution is to change the default value of the shell-dirtrackp variable after it is initialized in shell.el:

(require 'shell)
(setq-default shell-dirtrackp nil)


  • After turning off global-shell-dirtrack-mode, the creation of new buffers still default to shell-dirtrack-mode being enabled -- e.g., (get-buffer-create "*foo*") will have shell-dirtrack-mode active in buffer *foo* even though (global-shell-dirtrack-mode -1) was previously evaluated.
    – lawlist
    Feb 16, 2015 at 22:19
  • Hmm, you will have to edebug to figure out what is calling shell-dirtrack-mode. Above is a solution to only disable that mode globally in all the buffers. It does not prevent that mode from getting enabled again. Probably some hook is re-enabling this mode. Feb 16, 2015 at 22:25
  • After some digging out, the kill-all-local-variables function is the one that resets the state of shell-dirtrack-mode. That function is implemented in src/buffer.c. But looks like the local var reset is the cause of this.. Feb 16, 2015 at 23:20
  • @lawlist Phew, that was hell of a debug. Try out this updated solution now. It boiled down to modifying the default value of the local variable (minor mode var) and disabling the minor mode globally. After that, the mode stays off even after creating new buffers. Feb 17, 2015 at 0:35
  • Based on your hard work, I see that just (require 'shell) (setq-default shell-dirtrackp nil) resolves the issue. There is no need to create a global mode. This will also suffice: (require 'shell) (setq-default shell-dirtrack-mode nil)
    – lawlist
    Feb 17, 2015 at 1:00

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.