home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 32.8 Rational Searches Chapter 32
GNU Emacs
Next: 32.10 Inserting Binary Characters into Files
 

32.9 Unset PWD Before Using Emacs

I've seen a number of strange situations in which Emacs can't find files unless you type a complete ("absolute") pathname (1.21 ) , starting from the root (/  ). When you try to "visit" a file, you'll get the message File not found and directory doesn't exist .

In my experience, this usually means that the C shell's PWD environment variable (6.3 ) has gotten set incorrectly. There are a few (relatively pathological) ways of tricking the C shell into making a mistake. More commonly though, I've seen a few systems on which the C shell sticks an extra slash into PWD : that is, its value will be something like /home/mike//Mail rather than /home/mike/Mail . UNIX doesn't care; it lets you stack up extra slashes without trouble. But Emacs interprets // as the root directory - that is, it discards everything to the left of the double slash. So if you're trying to edit the file /home/mike//Mail/output.txt , Emacs will look for /Mail/output.txt . Even if this file exists, it's not what you want. [This also happens when Emacs is called from a (Bourne) shell script that has changed its current directory without changing PWD . -JP  ]

This problem is particularly annoying because the shell will automatically reset PWD every time you change directories - so the obvious solution, sticking unsetenv PWD in your .cshrc file, doesn't do any good.

What will work is defining an alias (10.1 ) :

(..)
 
alias gmacs "(unsetenv PWD; emacs \!*)"

A better solution might be to switch to another shell that doesn't have this problem. The Bourne shell (sh ) obviously doesn't, since it doesn't keep track of your current directory.

- ML


Previous: 32.8 Rational Searches UNIX Power Tools Next: 32.10 Inserting Binary Characters into Files
32.8 Rational Searches Book Index 32.10 Inserting Binary Characters into Files

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System