From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sam Peterson Newsgroups: gmane.emacs.help Subject: Re: current directory Date: Fri, 20 Oct 2006 09:46:44 -0700 Organization: University of California, Davis Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1161378856 32037 80.91.229.2 (20 Oct 2006 21:14:16 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 20 Oct 2006 21:14:16 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Oct 20 23:14:13 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Gb1gr-0000M5-4M for geh-help-gnu-emacs@m.gmane.org; Fri, 20 Oct 2006 23:14:05 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Gb1gq-0001Pw-Qd for geh-help-gnu-emacs@m.gmane.org; Fri, 20 Oct 2006 17:14:04 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!newsfeed.news.ucla.edu!ucdavis!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 55 Original-NNTP-Posting-Host: moobilenet-59-116.ucdavis.edu Original-X-Trace: skeeter.ucdavis.edu 1161362782 15179 128.120.59.116 (20 Oct 2006 16:46:22 GMT) Original-X-Complaints-To: usenet@ucdavis.edu Original-NNTP-Posting-Date: Fri, 20 Oct 2006 16:46:22 +0000 (UTC) User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin) Cancel-Lock: sha1:k5496whR+MpiKxEAgx5b2P9agB4= Original-Xref: shelby.stanford.edu gnu.emacs.help:142525 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:38146 Archived-At: >>>>> "help-gnu-emacs" == help-gnu-emacs writes: > This is about unix-like environment. > Say I start emacs with a file in a certain directory, say > /a/b/c: > cd ~ emacs /a/b/c/file > then, while in emacs, I open another file, say /g/d/f/file1. > It looks like after this emacs moves its "current directory" to > /g/d/f. Now, if I start a shell script through call-process, the > shell script's current directory is also /g/d/f, but it depends > on being run somewhere in /a/b/c tree. In fact, it looks like > emacs changes its internal 'current directory' each time I > switch to a file in a different directory, even a previously > opened file. > Is there a way to prevent emacs from changing its current > directory when opening a new file or changing between files > being visited? > TIA, /vb To my knowledge, the working directory of the process is not changed per se, rather, rather the value of the lisp variable default-directory is different in each buffer. There may be a way to set this variable in find-file-hooks, although there's a chance there could be an awful lot of plumbing in Emacs that assumes default-directory contains the name of the directory that the current buffer's file refers to. Worth a shot anyway. (add-hook 'find-file-hooks (lambda () (setq default-directory "dir-name")) This of course statically sets it. I'm sure there's a way through the magic of elisp to set the hook so it uses the dir of the requested file. Any suggestions elisp gurus? The preferred way in the GNU Emacs world is to just deal with shell commands via a shell buffer. If you absolutely need to to use M-! for whatever reason, whether that be to just run something quickly or insert the output in the current buffer, shell-mode plus killing/yanking text via a macro is one way I often go about it. There is almost always a back-door in Emacs. It can require writing an awful lot of elisp sometimes though ;). -- Sam Peterson skpeterson At nospam ucdavis.edu "if programmers were paid to remove code instead of adding it, software would be much better" -- unknown