[net.emacs] Suspend

sundar@cwruecmp.UUCP (Sundar R. Iyengar) (02/06/86)

Here are two functions that I find very useful.  After login I
usually start a emacs process which stays alive until I log out.
Everytime I restarted the emacs process, I wanted it know where
in the directory structure I was in the assumption that I 
wanted to examine some of files in the current directory (which is
almost always true).  The following functions switch the emacs
current buffer to *scratch* and change its default directory to
the current shell's directory if the directory of the buffer you
were last using before you stopped emacs is not the same as the shell's
current directory.  The change helps in file name completion which
is helpful if you are in some directory that has a long path name.
Unfortunately there is no easy of finding the shell's current
working directory (you have to run around process tables chasing data).
Instead I have aliased my "cd" to update a file ("~/.cwd")
(alias cd 'cd \!*; echo $cwd > ~/.cwd) and the "cwd" function below
reads this file.
	
---------------------------------------------------------

(defun suspend ()
"Suspend Emacs.  If it is woken up in a directory different from
what it was when Emacs was put to sleep, switch to *scratch* buffer and
change its default-directory to the current working shell directory.
This is done in the anticipation that the future find-files will find
their files in the new directory.  Changing value of default directory
helps during file-name-completion.  The file ~/.cwd is expected to contain
the name of the current directory.  sundar@case"
  (interactive)
  (suspend-emacs)
  (let ((cdir (cwd)))
    (if (string-equal cdir default-directory)
	nil
      (switch-to-buffer (get-buffer-create "*scratch*"))
      (cd cdir))))			;change its default-directory


(defun cwd ()
"Current Working Directory.  Returns the contents of the file
~/.cwd as a string.  This file is expected contain an one line
information about the shell's current working directory.  sundar@case"
  (interactive)
  (let ((buf))
    (save-excursion
      (set-buffer (find-file-noselect (expand-file-name "~/.cwd")))
      (setq buf (buffer-substring (dot-min) (- (dot-max) 1)))
      (kill-buffer (buffer-name)))
    (concat buf "/")))

-----------------------------------------------------
sundar r. iyengar		

arpa:  sundar%case@csnet-relay     531, crwaford hall
csnet: sundar@case		   case western reserve university
uucp:  decvax!cwruecmp!sundar	   cleveland, oh 44106