Next: Relative File Names, Previous: File Name Components, Up: File Names [Contents][Index]
A directory name is the name of a directory. A directory is a kind of file, and it has a file name, which is related to the directory name but not identical to it. This is not quite the same as the usual Unix terminology. These two different names for the same entity are related by a syntactic transformation. On Unix, this is simple: a directory name ends in a slash, whereas the directory’s name as a file lacks that slash.
The difference between a directory name and its name as a file is subtle but crucial. When a SXEmacs variable or function argument is described as being a directory name, a file name of a directory is not acceptable.
The following two functions convert between directory names and file names. They do nothing special with environment variable substitutions such as ‘$HOME’, and the constructs ‘~’, and ‘..’.
This function returns a string representing filename in a form that the operating system will interpret as the name of a directory. In Unix, this means appending a slash to the string.
(file-name-as-directory "~rms/lewis") ⇒ "~rms/lewis/"
This function returns a string representing dirname in a form that the operating system will interpret as the name of a file. On Unix, this means removing a final slash from the string.
(directory-file-name "~lewis/") ⇒ "~lewis"
Directory name abbreviations are useful for directories that are normally accessed through symbolic links. Sometimes the users recognize primarily the link’s name as “the name” of the directory, and find it annoying to see the directory’s “real” name. If you define the link name as an abbreviation for the “real” name, SXEmacs shows users the abbreviation instead.
If you wish to convert a directory name to its abbreviation, use this function:
This function applies abbreviations from directory-abbrev-alist
to its argument, and substitutes ‘~’ for the user’s home
directory.
If hack-homedir is non-nil
, then this also substitutes
‘~’ for the user’s home directory.
The variable directory-abbrev-alist
contains an alist of
abbreviations to use for file directories. Each element has the form
(from . to)
, and says to replace from with
to when it appears in a directory name. The from string is
actually a regular expression; it should always start with ‘^’.
The function abbreviate-file-name
performs these substitutions.
You can set this variable in site-init.el to describe the abbreviations appropriate for your site.
Here’s an example, from a system on which file system /home/fsf and so on are normally accessed through symbolic links named /fsf and so on.
(("^/home/fsf" . "/fsf") ("^/home/gp" . "/gp") ("^/home/gd" . "/gd"))
To convert a directory name to its abbreviation, use this function:
This function applies abbreviations from directory-abbrev-alist
to its argument, and substitutes ‘~’ for the user’s home
directory.
Next: Relative File Names, Previous: File Name Components, Up: File Names [Contents][Index]