changeset 1725:ac890f97e78b

(abbreviated-home-dir): New variable. (abbreviate-file-name): Properly convert abbreviated homedir to ~.
author Richard M. Stallman <rms@gnu.org>
date Sat, 26 Dec 1992 08:46:31 +0000
parents 2dccfada2107
children e44b2de1b698
files lisp/files.el
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/files.el	Thu Dec 24 22:42:05 1992 +0000
+++ b/lisp/files.el	Sat Dec 26 08:46:31 1992 +0000
@@ -395,6 +395,9 @@
 (defconst automount-dir-prefix "^/tmp_mnt/"
   "Regexp to match the automounter prefix in a directory name.")
 
+(defvar abbreviated-home-dir nil
+  "The the user's homedir abbreviated according to `directory-abbrev-list'.")
+
 (defun abbreviate-file-name (filename)
   "Return a version of FILENAME shortened using `directory-abbrev-alist'.
 This also substitutes \"~\" for the user's home directory.
@@ -405,12 +408,23 @@
 			   (substring filename (1- (match-end 0))))))
       (setq filename (substring filename (1- (match-end 0)))))
   (let ((tail directory-abbrev-alist))
+    ;; If any elt of directory-abbrev-alist matches this name,
+    ;; abbreviate accordingly.
     (while tail
       (if (string-match (car (car tail)) filename)
 	  (setq filename
 		(concat (cdr (car tail)) (substring filename (match-end 0)))))
       (setq tail (cdr tail)))
-    (if (string-match (concat "^" (expand-file-name "~")) filename)
+    ;; Compute and save the abbreviated homedir name.
+    ;; We defer computing this until the first time it's needed, to
+    ;; give time for directory-abbrev-alist to be set properly.
+    (or abbreviated-home-dir
+	(setq abbreviated-home-dir
+	      (let ((abbreviated-home-dir "$foo"))
+		(concat "^" (abbreviate-file-name (expand-file-name "~"))))))
+    ;; If FILENAME starts with the abbreviated homedir,
+    ;; make it start with `~' instead.
+    (if (string-match abbreviated-home-dir filename)
 	(setq filename
 	      (concat "~" (substring filename (match-end 0)))))
     filename))