diff options
| author | Richard M. Stallman | 2006-02-19 23:39:55 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2006-02-19 23:39:55 +0000 |
| commit | 240e8be5a3709e265633dfb1015fe58f376ed865 (patch) | |
| tree | 2570a18208d83fac9044829c89f68a2ea0406a5b | |
| parent | df36a07ef048613d662365af32566abf392ffdf7 (diff) | |
| download | emacs-240e8be5a3709e265633dfb1015fe58f376ed865.tar.gz emacs-240e8be5a3709e265633dfb1015fe58f376ed865.zip | |
(Relative File Names): Move file-relative-name here.
(File Name Expansion): From here. Minor clarifications.
| -rw-r--r-- | lispref/files.texi | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/lispref/files.texi b/lispref/files.texi index 36cdfa5d2bd..417bab81360 100644 --- a/lispref/files.texi +++ b/lispref/files.texi | |||
| @@ -1770,6 +1770,32 @@ Unix syntax and VMS syntax. | |||
| 1770 | @end example | 1770 | @end example |
| 1771 | @end defun | 1771 | @end defun |
| 1772 | 1772 | ||
| 1773 | Given a possibly relative file name, you can convert it to an | ||
| 1774 | absolute name using @code{expand-file-name} (@pxref{File Name | ||
| 1775 | Expansion}). This function converts absolute file names to relative | ||
| 1776 | names: | ||
| 1777 | |||
| 1778 | @defun file-relative-name filename &optional directory | ||
| 1779 | This function tries to return a relative name that is equivalent to | ||
| 1780 | @var{filename}, assuming the result will be interpreted relative to | ||
| 1781 | @var{directory} (an absolute directory name or directory file name). | ||
| 1782 | If @var{directory} is omitted or @code{nil}, it defaults to the | ||
| 1783 | current buffer's default directory. | ||
| 1784 | |||
| 1785 | On some operating systems, an absolute file name begins with a device | ||
| 1786 | name. On such systems, @var{filename} has no relative equivalent based | ||
| 1787 | on @var{directory} if they start with two different device names. In | ||
| 1788 | this case, @code{file-relative-name} returns @var{filename} in absolute | ||
| 1789 | form. | ||
| 1790 | |||
| 1791 | @example | ||
| 1792 | (file-relative-name "/foo/bar" "/foo/") | ||
| 1793 | @result{} "bar" | ||
| 1794 | (file-relative-name "/foo/bar" "/hack/") | ||
| 1795 | @result{} "../foo/bar" | ||
| 1796 | @end example | ||
| 1797 | @end defun | ||
| 1798 | |||
| 1773 | @node Directory Names | 1799 | @node Directory Names |
| 1774 | @comment node-name, next, previous, up | 1800 | @comment node-name, next, previous, up |
| 1775 | @subsection Directory Names | 1801 | @subsection Directory Names |
| @@ -1910,16 +1936,13 @@ you must specify the default directory name as well as the file name to | |||
| 1910 | be expanded. Expansion also simplifies file names by eliminating | 1936 | be expanded. Expansion also simplifies file names by eliminating |
| 1911 | redundancies such as @file{./} and @file{@var{name}/../}. | 1937 | redundancies such as @file{./} and @file{@var{name}/../}. |
| 1912 | 1938 | ||
| 1913 | In the next two functions, the @var{directory} argument can be either | ||
| 1914 | a directory name or a directory file name. @xref{Directory Names}. | ||
| 1915 | |||
| 1916 | @defun expand-file-name filename &optional directory | 1939 | @defun expand-file-name filename &optional directory |
| 1917 | This function converts @var{filename} to an absolute file name. If | 1940 | This function converts @var{filename} to an absolute file name. If |
| 1918 | @var{directory} is supplied, it is the default directory to start with | 1941 | @var{directory} is supplied, it is the default directory to start with |
| 1919 | if @var{filename} is relative. (The value of @var{directory} should | 1942 | if @var{filename} is relative. (The value of @var{directory} should |
| 1920 | itself be an absolute directory name; it may start with @samp{~}.) | 1943 | itself be an absolute directory name or directory file name; it may |
| 1921 | Otherwise, the current buffer's value of @code{default-directory} is | 1944 | start with @samp{~}.) Otherwise, the current buffer's value of |
| 1922 | used. For example: | 1945 | @code{default-directory} is used. For example: |
| 1923 | 1946 | ||
| 1924 | @example | 1947 | @example |
| 1925 | @group | 1948 | @group |
| @@ -1981,27 +2004,6 @@ should make sure to call @code{file-truename} without prior direct or | |||
| 1981 | indirect calls to @code{expand-file-name}. @xref{Truenames}. | 2004 | indirect calls to @code{expand-file-name}. @xref{Truenames}. |
| 1982 | @end defun | 2005 | @end defun |
| 1983 | 2006 | ||
| 1984 | @c Emacs 19 feature | ||
| 1985 | @defun file-relative-name filename &optional directory | ||
| 1986 | This function does the inverse of expansion---it tries to return a | ||
| 1987 | relative name that is equivalent to @var{filename} when interpreted | ||
| 1988 | relative to @var{directory}. If @var{directory} is omitted or | ||
| 1989 | @code{nil}, it defaults to the current buffer's default directory. | ||
| 1990 | |||
| 1991 | On some operating systems, an absolute file name begins with a device | ||
| 1992 | name. On such systems, @var{filename} has no relative equivalent based | ||
| 1993 | on @var{directory} if they start with two different device names. In | ||
| 1994 | this case, @code{file-relative-name} returns @var{filename} in absolute | ||
| 1995 | form. | ||
| 1996 | |||
| 1997 | @example | ||
| 1998 | (file-relative-name "/foo/bar" "/foo/") | ||
| 1999 | @result{} "bar" | ||
| 2000 | (file-relative-name "/foo/bar" "/hack/") | ||
| 2001 | @result{} "../foo/bar" | ||
| 2002 | @end example | ||
| 2003 | @end defun | ||
| 2004 | |||
| 2005 | @defvar default-directory | 2007 | @defvar default-directory |
| 2006 | The value of this buffer-local variable is the default directory for the | 2008 | The value of this buffer-local variable is the default directory for the |
| 2007 | current buffer. It should be an absolute directory name; it may start | 2009 | current buffer. It should be an absolute directory name; it may start |