Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!watmath!clyde!cbatt!ihnp4!houxm!genesis!hotlg!nz
From: nz@hotlg.UUCP
Newsgroups: comp.emacs
Subject: Re: notion of current directory (GNUemacs)
Message-ID: <9@hotlg.ATT>
Date: Thu, 8-Jan-87 09:54:22 EST
Article-I.D.: hotlg.9
Posted: Thu Jan  8 09:54:22 1987
Date-Received: Fri, 9-Jan-87 06:50:15 EST
References: <23621@rochester.ARPA>
Reply-To: nz@hotlg.UUCP (Neal Ziring)
Organization: AT&T-BL Dept. 54315
Lines: 75

In article <23621@rochester.ARPA> jpayne@rochester.ARPA (Jonathan Payne) writes:
 > 
 > Is the notion of current directory in GNU emacs PER BUFFER?  And is that
 > what gets changed when you do a cd?  

In the version of GNU I have (17.65) and in all the other version I have
used, it is definitely on a per-buffer basis.  If you look in the source
file ``buffer.h'', and look at the members of struct buffer, you will see
that there is an entry for the directory.  

 > Lots of times I want to find a file
 > in the current directory, namely the one in which I fired up emacs in the
 > first place.  But unless the file currently being visited is in that
 > directory, you have to retype the entire pathname (or whatever's
 > necessary). 

If you never delete the buffer '*scratch*' it will have the same current
directory as the one you started GNU from.  You can then define an Elisp
function to get the old cwd.  Actually, maintaining a shell or env variable
might be easier, but this way stays in Elisp.  On SysV, the variable PWD
always points to the shell's notion of your current /bin/pwd.  Anyhow,
this function returns a string ...

(defun old-default-directory ()
	"get the old . assuming the *scratch* still exists"
	(let ((scrtch (get-buffer "*scratch*")))
	     (if (null scrtch)
		(message "sorry, no *scratch* buffer")
		(set-buffer scrtch)
		default-directory)))
	
... that you can use as follows

	ESC ESC (find-file (concat (old-default-directory) "foo.c"))


 >  You can't just say "./" and you can't delete the entire
 > supplied path name (say in find-file) and say "./" either.  

Deleting the supplied path and saying ./ seems to work fine for me.
However, if you do a M-X cd or any other such command, ./ then points
to that new directory.

 > What I really
 > want to do is find out what the current directory is - I don't care about
 > find-file.  But as far as I can tell, there's no way to find out what the
 > current directory is, short of running /bin/pwd into a buffer.  And I'm
 > not even sure if THAT will work (but it probably would).

Actually, it wouldn't.  When you start up a shell buffer, it inherits
the default directory from whatever buffer you were in when you started
it up.  

 > Am I confused, or is there really no other way to do this?

Now that you have read my who article, the reward is an easy way to do
this.  In your .emacs file, put the following lines of Elisp code.

	(defvar startup-default-directory default-directory
		"default directory GNU invocation time.")

Now that you have an Elisp variable set to the directory
you want, the possibilities are BOUNDLESS!

There are lots of other ways to approach this.  For instance, you
must know that a leading ~ always expands to the rooted full pathname 
of your home directory.  There are other tricks, too, like recursive 
use of the minibuffer, in-line Elisp code evaluation, etc...


-- 
...nz  (Neal Ziring  @  ATT-BL Holmdel, x9229, 2E-315a)
	"You can fit an infinite number of wires into this junction box,
	but we usually don't go that far in practice."
					London Electric Co. Worker, 1880s