diff options
| author | Richard M. Stallman | 1992-09-28 13:02:52 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1992-09-28 13:02:52 +0000 |
| commit | 46fa307385d0d53b3c32cbb006fe6a3d7ad4b7c4 (patch) | |
| tree | d0ed9a0224cf7168e89da8f7c785f808f72fbb57 | |
| parent | 3bcbd523b28a572022af20fc6988ce2efde3494e (diff) | |
| download | emacs-46fa307385d0d53b3c32cbb006fe6a3d7ad4b7c4.tar.gz emacs-46fa307385d0d53b3c32cbb006fe6a3d7ad4b7c4.zip | |
(file-relative-name-1): New function split out.
(file-relative-name): Use it.
| -rw-r--r-- | lisp/files.el | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/lisp/files.el b/lisp/files.el index db50e86dccb..f12609bdc96 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -937,23 +937,23 @@ Value is a list whose car is the name for the backup file | |||
| 937 | "Return number of names file FILENAME has." | 937 | "Return number of names file FILENAME has." |
| 938 | (car (cdr (file-attributes filename)))) | 938 | (car (cdr (file-attributes filename)))) |
| 939 | 939 | ||
| 940 | (defun file-relative-name-1 (directory) | ||
| 941 | (cond ((string= directory "/") | ||
| 942 | filename) | ||
| 943 | ((string-match (concat "^" (regexp-quote directory)) | ||
| 944 | filename) | ||
| 945 | (substring filename (match-end 0))) | ||
| 946 | (t | ||
| 947 | (file-relative-name-1 | ||
| 948 | (file-name-directory (substring directory 0 -1)))))) | ||
| 949 | |||
| 940 | (defun file-relative-name (filename &optional directory) | 950 | (defun file-relative-name (filename &optional directory) |
| 941 | "Convert FILENAME to be relative to DIRECTORY (default: default-directory)." | 951 | "Convert FILENAME to be relative to DIRECTORY (default: default-directory)." |
| 942 | (setq filename (expand-file-name filename) | 952 | (setq filename (expand-file-name filename) |
| 943 | directory (file-name-as-directory (if directory | 953 | directory (file-name-as-directory (if directory |
| 944 | (expand-file-name directory) | 954 | (expand-file-name directory) |
| 945 | default-directory))) | 955 | default-directory))) |
| 946 | (let ((strip (lambda (directory) | 956 | (file-relative-name-1 directory)) |
| 947 | (cond ((string= directory "/") | ||
| 948 | filename) | ||
| 949 | ((string-match (concat "^" (regexp-quote directory)) | ||
| 950 | filename) | ||
| 951 | (substring filename (match-end 0))) | ||
| 952 | (t | ||
| 953 | (funcall strip | ||
| 954 | (file-name-directory (substring directory | ||
| 955 | 0 -1)))))))) | ||
| 956 | (funcall strip directory))) | ||
| 957 | 957 | ||
| 958 | (defun save-buffer (&optional args) | 958 | (defun save-buffer (&optional args) |
| 959 | "Save current buffer in visited file if modified. Versions described below. | 959 | "Save current buffer in visited file if modified. Versions described below. |