[comp.emacs] Why can't I set default-directory ?

cje@elbereth.rutgers.edu (Cthulhu's Jersey Epopt) (08/11/90)

If I run an emacs session from my main directory, whenever I use find-file or
visit-file, it assumes the file's in that directory.  If I want to go to a file
in a subdirectory, I just add the subdir to the dir tree in the file name.
All well and good.

Now let's say I want to look at another directory's files -- /usr/local/lib/tex
for example.  I can edit the filename in the minibuffer, and there I am.  Now
when I use find-file, I get /usr/local/lib/tex .  Also well and good.

But all this stuff is apparently stored in the default-directory variable.
Emacs will happily change the value of d-d if I edit the minibuffer, but it
won't let me change it via set-variable -- it doesn't recognize d-d (though
describe-variable does).

Why can't I set this directly?  (I guess I'm envisioning setting keys that
will switch to commonly used directories such as .../tex .)
-- 
Yog-Sothoth Neblod Zin,                Addending the HPL Centennial on 8/18?
                                       Look for me!
Chris Jarocha-Ernst
UUCP: {ames, att, harvard, moss, seismo}!rutgers!elbereth.rutgers.edu!cje
ARPA: JAROCHAERNST@CANCER.RUTGERS.EDU
CCIS, Rutgers University, Piscataway, NJ 08855-0879

sdk@ata.twinsun.com (Scott D Kalter) (08/12/90)

First of all, I suspect you realize that default-directory is a buffer
local variable.  Each buffer has its own copy of this variable and may
have a unique value.  Normally, this variable gets set when you find a
file to the directory that file is in.  It seems slightly odd that you
want to change this variable, in a specific buffer, to other random
directories.

However, as not to get in the way of experimentation, the problem that
you are experiencing is that the variable is not interactive.  In
other words, it isn't meant to be modified by the user via
set-variable.  You can bypass this by setting it in lisp code like:

	(setq default-directory '"/tmp/")

Therefore, you can write your own routine that modifies this variable,
make the routine interactive, and bind it to a key.

Hope this helps,

-sdk		<sdk@twinsun.com>

jbw@zeb.uswest.com (Joe Wells) (08/12/90)

cje@elbereth.rutgers.edu (Cthulhu's Jersey Epopt) writes:

   If I run an emacs session from my main directory, whenever I use
   find-file or visit-file, it assumes the file's in that directory.  If I
   want to go to a file in a subdirectory, I just add the subdir to the
   dir tree in the file name.  All well and good.

   [stuff deleted here]

   But all this stuff is apparently stored in the default-directory
   variable.  Emacs will happily change the value of d-d if I edit the
   minibuffer, but it won't let me change it via set-variable -- it
   doesn't recognize d-d (though describe-variable does).

There is a separate value of default-directory for each Emacs buffer.
When you start Emacs, the value of default-directory for the *scratch*
buffer is taken from the value of the PWD environment variable or from
the current directory of the process from which you started Emacs.  The
default directory of the *scratch* buffer is used for finding files you
specify on the command line.

   Why can't I set this directly?  (I guess I'm envisioning setting keys
   that will switch to commonly used directories such as .../tex .)

You mean set it directly using set-variable?  set-variable uses
read-variable to get the name of the variable from the user.  And
according to the documentation for read-variable, it won't accept the
names of variables that are not considered "user variables":

    read-variable:
    One arg PROMPT, a string.  Read the name of a user variable and return
    it as a symbol.  Prompts with PROMPT.
    A user variable is one whose documentation starts with a "*" character.

There is however, a convenient interface provided to change the default
directory for the current-buffer.  Simply use the cd command (invoked by
M-x cd):

    cd:
    Make DIR become the current buffer's default directory.

-- 
Joe Wells <jbw@uswest.com>

meissner@osf.org (Michael Meissner) (08/13/90)

In article <SDK.90Aug11112409@ata.twinsun.com> sdk@ata.twinsun.com
(Scott D Kalter) writes:

| However, as not to get in the way of experimentation, the problem that
| you are experiencing is that the variable is not interactive.  In
| other words, it isn't meant to be modified by the user via
| set-variable.  You can bypass this by setting it in lisp code like:
| 
| 	(setq default-directory '"/tmp/")
| 
| Therefore, you can write your own routine that modifies this variable,
| make the routine interactive, and bind it to a key.

Another way to set default-directory, is to call the cd function
(change directory), which sets default-directory, and is interactive.
--
Michael Meissner	email: meissner@osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

Do apple growers tell their kids money doesn't grow on bushes?

sasdjb@unx.sas.com (David Biesack) (08/16/90)

In article <Aug.10.14.50.19.1990.19931@elbereth.rutgers.edu> cje@elbereth.rutgers.edu (Cthulhu's Jersey Epopt) writes:
> 
> But all this stuff is apparently stored in the default-directory variable.
> Emacs will happily change the value of d-d if I edit the minibuffer, but it
> won't let me change it via set-variable -- it doesn't recognize d-d (though
> describe-variable does).

Each buffer has its own local value of default-directory, so that doing
a find-file from a buffer defaults to the same directory. You probably do not
want to change this.

> Why can't I set this directly?  (I guess I'm envisioning setting keys that
> will switch to commonly used directories such as .../tex .)

Use M-x cd to change a buffer's default-directory.. but again, I caution
against doing so for file buffers. If you have a directory you work in very
often, then do a find-file from one of the file buffers in that directory.
Or, you can create a non-file buffer and do your find-files from there:
Use C-x b (switch-to-buffer) to switch to a buffer named tex (enter the string
"tex" at the "Switch to buffer:" prompt.) 
This creates a new buffer named "tex" if you do not already have a 
buffer named "tex".
Use M-x cd to change the default-directory of the buffer "tex" to
/usr/local/lib/tex/ or whatever path you want. cd may ask you to confirm
the directory.  From there, you can always switch to the tex buffer
and when you do a find-file from that buffer, the default-directory
will be /usr/loca/lib/tex/

> -- 
> Yog-Sothoth Neblod Zin,                Addending the HPL Centennial on 8/18?
>                                        Look for me!
> Chris Jarocha-Ernst
> UUCP: {ames, att, harvard, moss, seismo}!rutgers!elbereth.rutgers.edu!cje
> ARPA: JAROCHAERNST@CANCER.RUTGERS.EDU
> CCIS, Rutgers University, Piscataway, NJ 08855-0879

djb

-- 
David J. Biesack			SAS Institute, Inc.     
Object Programming Technology           SAS Campus Drive        
sasdjb@dev.sas.com                      Cary, NC 27513-2414     
rti!sas!sasdjb                          (919) 677-8000 ext. 7771

heiby@mcdchg.chg.mcd.mot.com (Ron Heiby) (08/18/90)

I found that I was constantly annoyed when editing an outgoing news or
email message, which was being stored temporarily in /tmp or /usr/tmp,
that whenever I tried to include a file, like with 'CTRL-x i', it
would start out with a default of that /tmp or /usr/tmp directory.
Most often, the file I wanted to include in the outgoing message was
somewhere under my current directory, so I added the following hack to
my .emacs to change the default directory for a buffer to be my
current directory if the current default would be /tmp or /usr/tmp.  I
use the Korn Shell, which keeps $PWD set to the current directory.  I
suppose users of other shells could execute the pwd command to get the
same information.  If someone has any suggestions on improvements, I'd
be glad to hear about them.

;;-------- (defun
rwh-find-file-hooker ()
  "Make sure we're not set up with /tmp as default-directory."
  (if (or (equal default-directory "/tmp/")
          (equal default-directory "/usr/tmp/")
	  )
      (setq default-directory (file-name-as-directory (getenv "PWD")))
    )
  )

(defvar find-file-hooks nil)
(or (memq 'rwh-find-file-hooker find-file-hooks)
    (setq find-file-hooks (cons 'rwh-find-file-hooker find-file-hooks)))
;;--------
-- 
Ron Heiby, heiby@chg.mcd.mot.com	Moderator: comp.newprod
"Mandatory Drug Testing?  Just Say NO!!!"