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


Unix Power ToolsUnix Power ToolsSearch this book

19.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 ( Section 1.16), 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 (Section 35.5) has been incorrectly set. 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 any 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. The obvious solution, sticking unsetenv PWD in your .cshrc file, doesn't do any good.

What will work is defining an alias (Section 29.1):

(..) Section 43.7

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



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.