diff options
| author | Richard M. Stallman | 1992-12-26 08:46:31 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1992-12-26 08:46:31 +0000 |
| commit | ffb3a4db3c2ff0426e416e7f9260c3c1cf2e3ee9 (patch) | |
| tree | 2b614336cdb86b71d0435a3c7ee900d42cd91cac | |
| parent | 21ccfb5cf150f3b9bcb7a80381ecdc924b216809 (diff) | |
| download | emacs-ffb3a4db3c2ff0426e416e7f9260c3c1cf2e3ee9.tar.gz emacs-ffb3a4db3c2ff0426e416e7f9260c3c1cf2e3ee9.zip | |
(abbreviated-home-dir): New variable.
(abbreviate-file-name): Properly convert abbreviated homedir to ~.
| -rw-r--r-- | lisp/files.el | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lisp/files.el b/lisp/files.el index de949be7d16..31ce9acc129 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -395,6 +395,9 @@ Choose the buffer's name using `generate-new-buffer-name'." | |||
| 395 | (defconst automount-dir-prefix "^/tmp_mnt/" | 395 | (defconst automount-dir-prefix "^/tmp_mnt/" |
| 396 | "Regexp to match the automounter prefix in a directory name.") | 396 | "Regexp to match the automounter prefix in a directory name.") |
| 397 | 397 | ||
| 398 | (defvar abbreviated-home-dir nil | ||
| 399 | "The the user's homedir abbreviated according to `directory-abbrev-list'.") | ||
| 400 | |||
| 398 | (defun abbreviate-file-name (filename) | 401 | (defun abbreviate-file-name (filename) |
| 399 | "Return a version of FILENAME shortened using `directory-abbrev-alist'. | 402 | "Return a version of FILENAME shortened using `directory-abbrev-alist'. |
| 400 | This also substitutes \"~\" for the user's home directory. | 403 | This also substitutes \"~\" for the user's home directory. |
| @@ -405,12 +408,23 @@ Type \\[describe-variable] directory-abbrev-alist RET for more information." | |||
| 405 | (substring filename (1- (match-end 0)))))) | 408 | (substring filename (1- (match-end 0)))))) |
| 406 | (setq filename (substring filename (1- (match-end 0))))) | 409 | (setq filename (substring filename (1- (match-end 0))))) |
| 407 | (let ((tail directory-abbrev-alist)) | 410 | (let ((tail directory-abbrev-alist)) |
| 411 | ;; If any elt of directory-abbrev-alist matches this name, | ||
| 412 | ;; abbreviate accordingly. | ||
| 408 | (while tail | 413 | (while tail |
| 409 | (if (string-match (car (car tail)) filename) | 414 | (if (string-match (car (car tail)) filename) |
| 410 | (setq filename | 415 | (setq filename |
| 411 | (concat (cdr (car tail)) (substring filename (match-end 0))))) | 416 | (concat (cdr (car tail)) (substring filename (match-end 0))))) |
| 412 | (setq tail (cdr tail))) | 417 | (setq tail (cdr tail))) |
| 413 | (if (string-match (concat "^" (expand-file-name "~")) filename) | 418 | ;; Compute and save the abbreviated homedir name. |
| 419 | ;; We defer computing this until the first time it's needed, to | ||
| 420 | ;; give time for directory-abbrev-alist to be set properly. | ||
| 421 | (or abbreviated-home-dir | ||
| 422 | (setq abbreviated-home-dir | ||
| 423 | (let ((abbreviated-home-dir "$foo")) | ||
| 424 | (concat "^" (abbreviate-file-name (expand-file-name "~")))))) | ||
| 425 | ;; If FILENAME starts with the abbreviated homedir, | ||
| 426 | ;; make it start with `~' instead. | ||
| 427 | (if (string-match abbreviated-home-dir filename) | ||
| 414 | (setq filename | 428 | (setq filename |
| 415 | (concat "~" (substring filename (match-end 0))))) | 429 | (concat "~" (substring filename (match-end 0))))) |
| 416 | filename)) | 430 | filename)) |