comparison lisp/files.el @ 359:8e84bee8ddd0 r21-1-9

Import from CVS: tag r21-1-9
author cvs
date Mon, 13 Aug 2007 10:57:55 +0200
parents 182f72e8cd0d
children 7347b34c275b
comparison
equal deleted inserted replaced
358:fed6e0f6a03a 359:8e84bee8ddd0
770 Choose the buffer's name using `generate-new-buffer-name'." 770 Choose the buffer's name using `generate-new-buffer-name'."
771 (get-buffer-create (generate-new-buffer-name name))) 771 (get-buffer-create (generate-new-buffer-name name)))
772 772
773 (defvar abbreviated-home-dir nil 773 (defvar abbreviated-home-dir nil
774 "The user's homedir abbreviated according to `directory-abbrev-alist'.") 774 "The user's homedir abbreviated according to `directory-abbrev-alist'.")
775
776 (defun abbreviate-file-name (filename &optional hack-homedir) 775 (defun abbreviate-file-name (filename &optional hack-homedir)
777 "Return a version of FILENAME shortened using `directory-abbrev-alist'. 776 "Return a version of FILENAME shortened using `directory-abbrev-alist'.
778 See documentation of variable `directory-abbrev-alist' for more information. 777 See documentation of variable `directory-abbrev-alist' for more information.
779 If optional argument HACK-HOMEDIR is non-nil, then this also substitutes 778 If optional argument HACK-HOMEDIR is non-nil, then this also substitutes
780 \"~\" for the user's home directory." 779 \"~\" for the user's home directory."
788 ;; (setq filename (substring filename (1- (match-end 0))))) 787 ;; (setq filename (substring filename (1- (match-end 0)))))
789 (let ((tail directory-abbrev-alist)) 788 (let ((tail directory-abbrev-alist))
790 ;; If any elt of directory-abbrev-alist matches this name, 789 ;; If any elt of directory-abbrev-alist matches this name,
791 ;; abbreviate accordingly. 790 ;; abbreviate accordingly.
792 (while tail 791 (while tail
793 (if (string-match (car (car tail)) filename) 792 (when (string-match (car (car tail)) filename)
794 (setq filename 793 (setq filename
795 (concat (cdr (car tail)) (substring filename (match-end 0))))) 794 (concat (cdr (car tail)) (substring filename (match-end 0)))))
796 (setq tail (cdr tail)))) 795 (setq tail (cdr tail))))
797 (if hack-homedir 796 (when hack-homedir
798 (progn 797 ;; Compute and save the abbreviated homedir name.
799 ;; Compute and save the abbreviated homedir name. 798 ;; We defer computing this until the first time it's needed,
800 ;; We defer computing this until the first time it's needed, to 799 ;; to give time for directory-abbrev-alist to be set properly.
801 ;; give time for directory-abbrev-alist to be set properly. 800 ;; We include the separator at the end, to avoid spurious
802 ;; We include a slash at the end, to avoid spurious matches 801 ;; matches such as `/usr/foobar' when the home dir is
803 ;; such as `/usr/foobar' when the home dir is `/usr/foo'. 802 ;; `/usr/foo'.
804 (or abbreviated-home-dir 803 (or abbreviated-home-dir
805 (setq abbreviated-home-dir 804 (setq abbreviated-home-dir
806 (let ((abbreviated-home-dir "$foo")) 805 (let ((abbreviated-home-dir "$foo"))
807 (concat "\\`" (regexp-quote (abbreviate-file-name 806 (concat "\\`"
808 (expand-file-name "~"))) 807 (regexp-quote
809 "\\(/\\|\\'\\)")))) 808 (abbreviate-file-name (expand-file-name "~")))
810 ;; If FILENAME starts with the abbreviated homedir, 809 "\\("
811 ;; make it start with `~' instead. 810 (regexp-quote (string directory-sep-char))
812 (if (and (string-match abbreviated-home-dir filename) 811 "\\|\\'\\)"))))
813 ;; If the home dir is just /, don't change it. 812 ;; If FILENAME starts with the abbreviated homedir,
814 (not (and (= (match-end 0) 1) ;#### unix-specific 813 ;; make it start with `~' instead.
815 (= (aref filename 0) ?/))) 814 (if (and (string-match abbreviated-home-dir filename)
816 (not (and (or (eq system-type 'ms-dos) 815 ;; If the home dir is just /, don't change it.
817 (eq system-type 'windows-nt)) 816 (not (and (= (match-end 0) 1)
818 (save-match-data 817 (= (aref filename 0) directory-sep-char)))
819 (string-match "^[a-zA-Z]:/$" filename))))) 818 (not (and (eq system-type 'windows-nt)
820 (setq filename 819 (save-match-data
821 (concat "~" 820 (string-match (concat "\\`[a-zA-Z]:"
822 (substring filename 821 (regexp-quote
823 (match-beginning 1) (match-end 1)) 822 (string directory-sep-char))
824 (substring filename (match-end 0))))))) 823 "\\'")
824 filename)))))
825 (setq filename
826 (concat "~"
827 (match-string 1 filename)
828 (substring filename (match-end 0))))))
825 filename))) 829 filename)))
826 830
827 (defcustom find-file-not-true-dirname-list nil 831 (defcustom find-file-not-true-dirname-list nil
828 "*List of logical names for which visiting shouldn't save the true dirname. 832 "*List of logical names for which visiting shouldn't save the true dirname.
829 On VMS, when you visit a file using a logical name that searches a path, 833 On VMS, when you visit a file using a logical name that searches a path,