Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

how can I change a default working directory/drive for shell in Emacs (on Windows)?

Normally, shell starts in the same directory as the file in current buffer. However, when my current file is on D: drive, it starts in c:. Manually changing drive to D: in shell brings me to my directory of course, but I want to avoid this extra step. Is it possible?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

on windows:

  • When you enter M-x shell you are automatically placed in the default directory of emacs. In this case you should modify the default directory of emacs in the .emacs config file.

    (cd "C:/Users/username/directory/path")

  • However if you have a file open and you enter M-x shell from that window you will be placed in the directory of that file.

share|improve this answer
    
Re: second point - that's not what I observe when I edit a file on a D: drive. I'm placed in the C:\ root directory; when I manually change it to D: I'm indeed in the directory of my file. –  Victor K. May 17 '10 at 3:28
    
Your cursor has to be in the same window. If you are editing a file on D:... and you enter "M-x shell" you will be brought to a shell that is in that directory. I just tested it again. It really works. Other issue can be if you have some default values set in your .emacs configuration file. –  Dlf May 17 '10 at 14:04
    
My test environment: Windows Vista + Emacs 23.1.1 + my .emacs configuration file does not modify default directory for the shell. It works for me this way. What is your environment? –  Dlf May 17 '10 at 15:06

I use eshell with esh-toggle loaded, and I have eshell-toggle-cd bound to a handy key.

Hit it once, you get a shell in the same directory as the file you have open. Hit it again, the shell buffer goes away and you're back to your original buffer.

Since most of my 'swap to shell' interruptions involve the file/directory in the current buffer, this saves a surprising amount of time.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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