comparison lisp/files.el @ 71646:4a2a2f40a43f

(abbreviate-file-name): Add save-match-data.
author Richard M. Stallman <rms@gnu.org>
date Wed, 05 Jul 2006 17:13:28 +0000
parents d9b9f70ec91a
children 5a4a7b32f980 138ce2701550
comparison
equal deleted inserted replaced
71645:0fc55b1cc3c9 71646:4a2a2f40a43f
1273 (defun abbreviate-file-name (filename) 1273 (defun abbreviate-file-name (filename)
1274 "Return a version of FILENAME shortened using `directory-abbrev-alist'. 1274 "Return a version of FILENAME shortened using `directory-abbrev-alist'.
1275 This also substitutes \"~\" for the user's home directory and 1275 This also substitutes \"~\" for the user's home directory and
1276 removes automounter prefixes (see the variable `automount-dir-prefix')." 1276 removes automounter prefixes (see the variable `automount-dir-prefix')."
1277 ;; Get rid of the prefixes added by the automounter. 1277 ;; Get rid of the prefixes added by the automounter.
1278 (if (and automount-dir-prefix 1278 (save-match-data
1279 (string-match automount-dir-prefix filename) 1279 (if (and automount-dir-prefix
1280 (file-exists-p (file-name-directory 1280 (string-match automount-dir-prefix filename)
1281 (substring filename (1- (match-end 0)))))) 1281 (file-exists-p (file-name-directory
1282 (setq filename (substring filename (1- (match-end 0))))) 1282 (substring filename (1- (match-end 0))))))
1283 (let ((tail directory-abbrev-alist)) 1283 (setq filename (substring filename (1- (match-end 0)))))
1284 ;; If any elt of directory-abbrev-alist matches this name, 1284 (let ((tail directory-abbrev-alist))
1285 ;; abbreviate accordingly. 1285 ;; If any elt of directory-abbrev-alist matches this name,
1286 (while tail 1286 ;; abbreviate accordingly.
1287 (if (string-match (car (car tail)) filename) 1287 (while tail
1288 (if (string-match (car (car tail)) filename)
1289 (setq filename
1290 (concat (cdr (car tail)) (substring filename (match-end 0)))))
1291 (setq tail (cdr tail)))
1292 ;; Compute and save the abbreviated homedir name.
1293 ;; We defer computing this until the first time it's needed, to
1294 ;; give time for directory-abbrev-alist to be set properly.
1295 ;; We include a slash at the end, to avoid spurious matches
1296 ;; such as `/usr/foobar' when the home dir is `/usr/foo'.
1297 (or abbreviated-home-dir
1298 (setq abbreviated-home-dir
1299 (let ((abbreviated-home-dir "$foo"))
1300 (concat "^" (abbreviate-file-name (expand-file-name "~"))
1301 "\\(/\\|$\\)"))))
1302
1303 ;; If FILENAME starts with the abbreviated homedir,
1304 ;; make it start with `~' instead.
1305 (if (and (string-match abbreviated-home-dir filename)
1306 ;; If the home dir is just /, don't change it.
1307 (not (and (= (match-end 0) 1)
1308 (= (aref filename 0) ?/)))
1309 ;; MS-DOS root directories can come with a drive letter;
1310 ;; Novell Netware allows drive letters beyond `Z:'.
1311 (not (and (or (eq system-type 'ms-dos)
1312 (eq system-type 'cygwin)
1313 (eq system-type 'windows-nt))
1314 (save-match-data
1315 (string-match "^[a-zA-`]:/$" filename)))))
1288 (setq filename 1316 (setq filename
1289 (concat (cdr (car tail)) (substring filename (match-end 0))))) 1317 (concat "~"
1290 (setq tail (cdr tail))) 1318 (match-string 1 filename)
1291 ;; Compute and save the abbreviated homedir name. 1319 (substring filename (match-end 0)))))
1292 ;; We defer computing this until the first time it's needed, to 1320 filename)))
1293 ;; give time for directory-abbrev-alist to be set properly.
1294 ;; We include a slash at the end, to avoid spurious matches
1295 ;; such as `/usr/foobar' when the home dir is `/usr/foo'.
1296 (or abbreviated-home-dir
1297 (setq abbreviated-home-dir
1298 (let ((abbreviated-home-dir "$foo"))
1299 (concat "^" (abbreviate-file-name (expand-file-name "~"))
1300 "\\(/\\|$\\)"))))
1301
1302 ;; If FILENAME starts with the abbreviated homedir,
1303 ;; make it start with `~' instead.
1304 (if (and (string-match abbreviated-home-dir filename)
1305 ;; If the home dir is just /, don't change it.
1306 (not (and (= (match-end 0) 1)
1307 (= (aref filename 0) ?/)))
1308 ;; MS-DOS root directories can come with a drive letter;
1309 ;; Novell Netware allows drive letters beyond `Z:'.
1310 (not (and (or (eq system-type 'ms-dos)
1311 (eq system-type 'cygwin)
1312 (eq system-type 'windows-nt))
1313 (save-match-data
1314 (string-match "^[a-zA-`]:/$" filename)))))
1315 (setq filename
1316 (concat "~"
1317 (match-string 1 filename)
1318 (substring filename (match-end 0)))))
1319 filename))
1320 1321
1321 (defcustom find-file-not-true-dirname-list nil 1322 (defcustom find-file-not-true-dirname-list nil
1322 "*List of logical names for which visiting shouldn't save the true dirname. 1323 "*List of logical names for which visiting shouldn't save the true dirname.
1323 On VMS, when you visit a file using a logical name that searches a path, 1324 On VMS, when you visit a file using a logical name that searches a path,
1324 you may or may not want the visited file name to record the specific 1325 you may or may not want the visited file name to record the specific