comparison lisp/files.el @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children 95016f13131a
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
792 (setq filename 792 (setq filename
793 (concat (cdr (car tail)) (substring filename (match-end 0))))) 793 (concat (cdr (car tail)) (substring filename (match-end 0)))))
794 (setq tail (cdr tail)))) 794 (setq tail (cdr tail))))
795 (when hack-homedir 795 (when hack-homedir
796 ;; Compute and save the abbreviated homedir name. 796 ;; Compute and save the abbreviated homedir name.
797 ;; We defer computing this until the first time it's needed, 797 ;; We defer computing this until the first time it's needed, to
798 ;; to give time for directory-abbrev-alist to be set properly. 798 ;; give time for directory-abbrev-alist to be set properly.
799 ;; We include the separator at the end, to avoid spurious 799 ;; We include a slash at the end, to avoid spurious matches
800 ;; matches such as `/usr/foobar' when the home dir is 800 ;; such as `/usr/foobar' when the home dir is `/usr/foo'.
801 ;; `/usr/foo'.
802 (or abbreviated-home-dir 801 (or abbreviated-home-dir
803 (setq abbreviated-home-dir 802 (setq abbreviated-home-dir
804 (let ((abbreviated-home-dir "$foo")) 803 (let ((abbreviated-home-dir "$foo"))
805 (concat "\\`" 804 (concat "\\`" (regexp-quote (abbreviate-file-name
806 (regexp-quote 805 (expand-file-name "~")))
807 (abbreviate-file-name (expand-file-name "~"))) 806 "\\(/\\|\\'\\)"))))
808 "\\("
809 (regexp-quote (string directory-sep-char))
810 "\\|\\'\\)"))))
811 ;; If FILENAME starts with the abbreviated homedir, 807 ;; If FILENAME starts with the abbreviated homedir,
812 ;; make it start with `~' instead. 808 ;; make it start with `~' instead.
813 (if (and (string-match abbreviated-home-dir filename) 809 (if (and (string-match abbreviated-home-dir filename)
814 ;; If the home dir is just /, don't change it. 810 ;; If the home dir is just /, don't change it.
815 (not (and (= (match-end 0) 1) 811 (not (and (= (match-end 0) 1) ;#### unix-specific
816 (= (aref filename 0) directory-sep-char))) 812 (= (aref filename 0) ?/)))
817 (not (and (eq system-type 'windows-nt) 813 (not (and (memq system-type '(ms-dos windows-nt))
818 (save-match-data 814 (save-match-data
819 (string-match (concat "\\`[a-zA-Z]:" 815 (string-match "^[a-zA-Z]:/$" filename)))))
820 (regexp-quote
821 (string directory-sep-char))
822 "\\'")
823 filename)))))
824 (setq filename 816 (setq filename
825 (concat "~" 817 (concat "~"
826 (match-string 1 filename) 818 (substring filename
819 (match-beginning 1) (match-end 1))
827 (substring filename (match-end 0)))))) 820 (substring filename (match-end 0))))))
828 filename))) 821 filename)))
829 822
830 (defcustom find-file-not-true-dirname-list nil 823 (defcustom find-file-not-true-dirname-list nil
831 "*List of logical names for which visiting shouldn't save the true dirname." 824 "*List of logical names for which visiting shouldn't save the true dirname."
1026 nil 1019 nil
1027 (after-find-file error (not nowarn)) 1020 (after-find-file error (not nowarn))
1028 (setq buf (current-buffer)))) 1021 (setq buf (current-buffer))))
1029 (t 1022 (t
1030 (kill-buffer buf) 1023 (kill-buffer buf)
1031 (signal (car data) (cdr data)))) 1024 (signal (car data) (cdr data))))))
1032 ))
1033 buf))) 1025 buf)))
1034 1026
1035 ;; FSF has `insert-file-literally' and `find-file-literally' here. 1027 ;; FSF has `insert-file-literally' and `find-file-literally' here.
1036 1028
1037 (defvar after-find-file-from-revert-buffer nil) 1029 (defvar after-find-file-from-revert-buffer nil)
1163 ("\\.e\\'" . eiffel-mode) 1155 ("\\.e\\'" . eiffel-mode)
1164 ("\\.mss\\'" . scribe-mode) 1156 ("\\.mss\\'" . scribe-mode)
1165 ("\\.m\\(?:[mes]\\|an\\)\\'" . nroff-mode) 1157 ("\\.m\\(?:[mes]\\|an\\)\\'" . nroff-mode)
1166 ("\\.icn\\'" . icon-mode) 1158 ("\\.icn\\'" . icon-mode)
1167 ("\\.\\(?:[ckz]?sh\\|shar\\)\\'" . sh-mode) 1159 ("\\.\\(?:[ckz]?sh\\|shar\\)\\'" . sh-mode)
1168 ("\\.pro\\'" . idlwave-mode)
1169 ;; #### Unix-specific! 1160 ;; #### Unix-specific!
1170 ("/\\.\\(?:bash_\\|z\\)?\\(profile\\|login\\|logout\\)\\'" . sh-mode) 1161 ("/\\.\\(?:bash_\\|z\\)?\\(profile\\|login\\|logout\\)\\'" . sh-mode)
1171 ("/\\.\\(?:[ckz]sh\\|bash\\|tcsh\\|es\\|xinit\\|startx\\)rc\\'" . sh-mode) 1162 ("/\\.\\(?:[ckz]sh\\|bash\\|tcsh\\|es\\|xinit\\|startx\\)rc\\'" . sh-mode)
1172 ("/\\.\\(?:[kz]shenv\\|xsession\\)\\'" . sh-mode) 1163 ("/\\.\\(?:[kz]shenv\\|xsession\\)\\'" . sh-mode)
1173 ;; The following come after the ChangeLog pattern for the sake of 1164 ;; The following come after the ChangeLog pattern for the sake of
1192 ("^/tmp/fol/" . text-mode) 1183 ("^/tmp/fol/" . text-mode)
1193 ("\\.y\\'" . c-mode) 1184 ("\\.y\\'" . c-mode)
1194 ("\\.lex\\'" . c-mode) 1185 ("\\.lex\\'" . c-mode)
1195 ("\\.m\\'" . objc-mode) 1186 ("\\.m\\'" . objc-mode)
1196 ("\\.oak\\'" . scheme-mode) 1187 ("\\.oak\\'" . scheme-mode)
1197 ("\\.[sj]?html?\\'" . html-mode) 1188 ("\\.s?html?\\'" . html-mode)
1198 ("\\.jsp\\'" . html-mode)
1199 ("\\.xml\\'" . xml-mode)
1200 ("\\.htm?l?3\\'" . html3-mode) 1189 ("\\.htm?l?3\\'" . html3-mode)
1201 ("\\.\\(?:sgml?\\|dtd\\)\\'" . sgml-mode) 1190 ("\\.\\(?:sgml?\\|dtd\\)\\'" . sgml-mode)
1202 ("\\.c?ps\\'" . postscript-mode) 1191 ("\\.c?ps\\'" . postscript-mode)
1203 ;; .emacs following a directory delimiter in either Unix or 1192 ;; .emacs following a directory delimiter in either Unix or
1204 ;; Windows syntax. 1193 ;; Windows syntax.
1205 ("[/\\][._].*emacs\\'" . emacs-lisp-mode) 1194 ("[/\\][._].*emacs\\'" . emacs-lisp-mode)
1206 ("\\.m4\\'" . autoconf-mode) 1195 ("\\.m4\\'" . autoconf-mode)
1207 ("configure\\.in\\'" . autoconf-mode) 1196 ("configure\\.in\\'" . autoconf-mode)
1208 ("\\.ml\\'" . lisp-mode) 1197 ("\\.ml\\'" . lisp-mode)
1209 ("\\.ma?ke?\\'" . makefile-mode) 1198 ("\\.ma?k\\'" . makefile-mode)
1210 ("[Mm]akefile\\(\\.\\|\\'\\)" . makefile-mode) 1199 ("[Mm]akefile\\(\\.\\|\\'\\)" . makefile-mode)
1211 ("\\.X\\(defaults\\|environment\\|resources\\|modmap\\)\\'" . xrdb-mode) 1200 ("\\.X\\(defaults\\|environment\\|resources\\|modmap\\)\\'" . xrdb-mode)
1212 ;; #### The following three are Unix-specific (but do we care?) 1201 ;; #### The following three are Unix-specific (but do we care?)
1213 ("/app-defaults/" . xrdb-mode) 1202 ("/app-defaults/" . xrdb-mode)
1214 ("\\.[^/]*wm2?\\(?:rc\\)?\\'" . winmgr-mode) 1203 ("\\.[^/]*wm2?\\(?:rc\\)?\\'" . winmgr-mode)
1230 ("^#!.*sh\\b" . sh-mode) 1219 ("^#!.*sh\\b" . sh-mode)
1231 ("perl" . perl-mode) 1220 ("perl" . perl-mode)
1232 ("python" . python-mode) 1221 ("python" . python-mode)
1233 ("awk\\b" . awk-mode) 1222 ("awk\\b" . awk-mode)
1234 ("rexx" . rexx-mode) 1223 ("rexx" . rexx-mode)
1235 ("scm\\|guile" . scheme-mode) 1224 ("scm" . scheme-mode)
1236 ("emacs" . emacs-lisp-mode)
1237 ("make" . makefile-mode)
1238 ("^:" . sh-mode)) 1225 ("^:" . sh-mode))
1239 "Alist mapping interpreter names to major modes. 1226 "Alist mapping interpreter names to major modes.
1240 This alist is used to guess the major mode of a file based on the 1227 This alist is used to guess the major mode of a file based on the
1241 contents of the first line. This line often contains something like: 1228 contents of the first line. This line often contains something like:
1242 #!/bin/sh 1229 #!/bin/sh
1281 "List of regexps for what to ignore, for `inhibit-first-line-modes-regexps'. 1268 "List of regexps for what to ignore, for `inhibit-first-line-modes-regexps'.
1282 When checking `inhibit-first-line-modes-regexps', we first discard 1269 When checking `inhibit-first-line-modes-regexps', we first discard
1283 from the end of the file name anything that matches one of these regexps.") 1270 from the end of the file name anything that matches one of these regexps.")
1284 1271
1285 (defvar user-init-file 1272 (defvar user-init-file
1286 nil ; set by command-line 1273 "" ; set by command-line
1287 "File name including directory of user's initialization file.") 1274 "File name including directory of user's initialization file.")
1288 1275
1289 (defun set-auto-mode (&optional just-from-file-name) 1276 (defun set-auto-mode (&optional just-from-file-name)
1290 "Select major mode appropriate for current buffer. 1277 "Select major mode appropriate for current buffer.
1291 This checks for a -*- mode tag in the buffer's text, 1278 This checks for a -*- mode tag in the buffer's text,
1320 (keep-going t)) 1307 (keep-going t))
1321 (while keep-going 1308 (while keep-going
1322 (setq keep-going nil) 1309 (setq keep-going nil)
1323 (let ((alist auto-mode-alist) 1310 (let ((alist auto-mode-alist)
1324 (mode nil)) 1311 (mode nil))
1325
1326 ;; Find first matching alist entry. 1312 ;; Find first matching alist entry.
1327
1328 ;; #### This is incorrect. In NT, case sensitivity is a volume
1329 ;; property. For instance, NFS mounts *are* case sensitive.
1330 ;; Need internal function (file-name-case-sensitive f), F
1331 ;; being file or directory name. - kkm
1332 (let ((case-fold-search 1313 (let ((case-fold-search
1333 (eq system-type 'windows-nt))) 1314 (memq system-type '(windows-nt))))
1334 (while (and (not mode) alist) 1315 (while (and (not mode) alist)
1335 (if (string-match (car (car alist)) name) 1316 (if (string-match (car (car alist)) name)
1336 (if (and (consp (cdr (car alist))) 1317 (if (and (consp (cdr (car alist)))
1337 (nth 2 (car alist))) 1318 (nth 2 (car alist)))
1338 (progn 1319 (progn
1540 (point)))) 1521 (point))))
1541 ;; Parse the -*- line into the `result' alist. 1522 ;; Parse the -*- line into the `result' alist.
1542 (cond ((not (search-forward "-*-" end t)) 1523 (cond ((not (search-forward "-*-" end t))
1543 ;; doesn't have one. 1524 ;; doesn't have one.
1544 (setq force t)) 1525 (setq force t))
1545 ((looking-at "[ \t]*\\([^ \t\n\r:;]+?\\)\\([ \t]*-\\*-\\)") 1526 ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)")
1546 ;; Antiquated form: "-*- ModeName -*-". 1527 ;; Antiquated form: "-*- ModeName -*-".
1547 (setq result 1528 (setq result
1548 (list (cons 'mode 1529 (list (cons 'mode
1549 (intern (buffer-substring 1530 (intern (buffer-substring
1550 (match-beginning 1) 1531 (match-beginning 1)
1832 (read-file-name "Write file: " 1813 (read-file-name "Write file: "
1833 (cdr (assq 'default-directory 1814 (cdr (assq 'default-directory
1834 (buffer-local-variables))) 1815 (buffer-local-variables)))
1835 nil nil (buffer-name))) 1816 nil nil (buffer-name)))
1836 t 1817 t
1837 (if (and current-prefix-arg (featurep 'file-coding)) 1818 (if (and current-prefix-arg (featurep 'mule))
1838 (read-coding-system "Coding system: ")))) 1819 (read-coding-system "Coding system: "))))
1839 (and (eq (current-buffer) mouse-grabbed-buffer) 1820 (and (eq (current-buffer) mouse-grabbed-buffer)
1840 (error "Can't write minibuffer window")) 1821 (error "Can't write minibuffer window"))
1841 (or (null filename) (string-equal filename "") 1822 (or (null filename) (string-equal filename "")
1842 (progn 1823 (progn
1886 (if backup-info 1867 (if backup-info
1887 (condition-case () 1868 (condition-case ()
1888 (let ((delete-old-versions 1869 (let ((delete-old-versions
1889 ;; If have old versions to maybe delete, 1870 ;; If have old versions to maybe delete,
1890 ;; ask the user to confirm now, before doing anything. 1871 ;; ask the user to confirm now, before doing anything.
1891 ;; But don't actually delete till later. 1872 ;; But don't actually delete til later.
1892 (and targets 1873 (and targets
1893 (or (eq delete-old-versions t) 1874 (or (eq delete-old-versions t)
1894 (eq delete-old-versions nil)) 1875 (eq delete-old-versions nil))
1895 (or delete-old-versions 1876 (or delete-old-versions
1896 (y-or-n-p (format "Delete excess backup versions of %s? " 1877 (y-or-n-p (format "Delete excess backup versions of %s? "
2004 ""))))) 1985 "")))))
2005 1986
2006 (defun make-backup-file-name (file) 1987 (defun make-backup-file-name (file)
2007 "Create the non-numeric backup file name for FILE. 1988 "Create the non-numeric backup file name for FILE.
2008 This is a separate function so you can redefine it for customization." 1989 This is a separate function so you can redefine it for customization."
2009 (concat file "~")) 1990 (if (eq system-type 'ms-dos)
1991 (let ((fn (file-name-nondirectory file)))
1992 (concat (file-name-directory file)
1993 (if (string-match "\\([^.]*\\)\\(\\..*\\)?" fn)
1994 (substring fn 0 (match-end 1)))
1995 ".bak"))
1996 (concat file "~")))
2010 1997
2011 (defun backup-file-name-p (file) 1998 (defun backup-file-name-p (file)
2012 "Return non-nil if FILE is a backup file name (numeric or not). 1999 "Return non-nil if FILE is a backup file name (numeric or not).
2013 This is a separate function so you can redefine it for customization. 2000 This is a separate function so you can redefine it for customization.
2014 You may need to redefine `file-name-sans-versions' as well." 2001 You may need to redefine `file-name-sans-versions' as well."
2015 (string-match "~\\'" file)) 2002 (if (eq system-type 'ms-dos)
2003 (string-match "\\.bak\\'" file)
2004 (string-match "~\\'" file)))
2016 2005
2017 ;; This is used in various files. 2006 ;; This is used in various files.
2018 ;; The usage of bv-length is not very clean, 2007 ;; The usage of bv-length is not very clean,
2019 ;; but I can't see a good alternative, 2008 ;; but I can't see a good alternative,
2020 ;; so as of now I am leaving it alone. 2009 ;; so as of now I am leaving it alone.
2081 2070
2082 (defun file-relative-name (filename &optional directory) 2071 (defun file-relative-name (filename &optional directory)
2083 "Convert FILENAME to be relative to DIRECTORY (default: default-directory). 2072 "Convert FILENAME to be relative to DIRECTORY (default: default-directory).
2084 This function returns a relative file name which is equivalent to FILENAME 2073 This function returns a relative file name which is equivalent to FILENAME
2085 when used with that default directory as the default. 2074 when used with that default directory as the default.
2086 If this is impossible (which can happen on MS Windows when the file name 2075 If this is impossible (which can happen on MSDOS and Windows
2087 and directory use different drive names) then it returns FILENAME." 2076 when the file name and directory use different drive names)
2077 then it returns FILENAME."
2088 (save-match-data 2078 (save-match-data
2089 (let ((fname (expand-file-name filename))) 2079 (let ((fname (expand-file-name filename)))
2090 (setq directory (file-name-as-directory 2080 (setq directory (file-name-as-directory
2091 (expand-file-name (or directory default-directory)))) 2081 (expand-file-name (or directory default-directory))))
2092 ;; On Microsoft OSes, if FILENAME and DIRECTORY have different 2082 ;; On Microsoft OSes, if FILENAME and DIRECTORY have different
2093 ;; drive names, they can't be relative, so return the absolute name. 2083 ;; drive names, they can't be relative, so return the absolute name.
2094 (if (and (eq system-type 'windows-nt) 2084 (if (and (memq system-type '(ms-dos windows-nt))
2095 (not (string-equal (substring fname 0 2) 2085 (not (string-equal (substring fname 0 2)
2096 (substring directory 0 2)))) 2086 (substring directory 0 2))))
2097 filename 2087 filename
2098 (let ((ancestor ".") 2088 (let ((ancestor ".")
2099 (fname-dir (file-name-as-directory fname))) 2089 (fname-dir (file-name-as-directory fname)))
2219 (format "%s has changed since visited or saved. Save anyway? " 2209 (format "%s has changed since visited or saved. Save anyway? "
2220 (file-name-nondirectory buffer-file-name))) 2210 (file-name-nondirectory buffer-file-name)))
2221 (error "Save not confirmed")) 2211 (error "Save not confirmed"))
2222 (save-restriction 2212 (save-restriction
2223 (widen) 2213 (widen)
2224 2214 (and (> (point-max) 1)
2225 ;; Add final newline if required. See `require-final-newline'. 2215 (/= (char-after (1- (point-max))) ?\n)
2226 (when (and (not (eq (char-before (point-max)) ?\n)) ; common case 2216 (not (and (eq selective-display t)
2227 (char-before (point-max)) ; empty buffer? 2217 (= (char-after (1- (point-max))) ?\r)))
2228 (not (and (eq selective-display t) 2218 (or (eq require-final-newline t)
2229 (eq (char-before (point-max)) ?\r))) 2219 (and require-final-newline
2230 (or (eq require-final-newline t) 2220 (y-or-n-p
2231 (and require-final-newline 2221 (format "Buffer %s does not end in newline. Add one? "
2232 (y-or-n-p 2222 (buffer-name)))))
2233 (format "Buffer %s does not end in newline. Add one? " 2223 (save-excursion
2234 (buffer-name)))))) 2224 (goto-char (point-max))
2235 (save-excursion 2225 (insert ?\n)))
2236 (goto-char (point-max)) 2226 ;;
2237 (insert ?\n)))
2238
2239 ;; Run the write-file-hooks until one returns non-null. 2227 ;; Run the write-file-hooks until one returns non-null.
2240 ;; Bind after-save-hook to nil while running the 2228 ;; Bind after-save-hook to nil while running the
2241 ;; write-file-hooks so that if this function is called 2229 ;; write-file-hooks so that if this function is called
2242 ;; recursively (from inside a write-file-hook) the 2230 ;; recursively (from inside a write-file-hook) the
2243 ;; after-hooks will only get run once (from the 2231 ;; after-hooks will only get run once (from the
2459 (lambda (ignore) 2447 (lambda (ignore)
2460 (exit-recursive-edit))) 2448 (exit-recursive-edit)))
2461 (recursive-edit) 2449 (recursive-edit)
2462 ;; Return nil to ask about BUF again. 2450 ;; Return nil to ask about BUF again.
2463 nil) 2451 nil)
2464 "%_Display Buffer")))) 2452 "display the current buffer"))))
2465 (abbrevs-done 2453 (abbrevs-done
2466 (and save-abbrevs abbrevs-changed 2454 (and save-abbrevs abbrevs-changed
2467 (progn 2455 (progn
2468 (if (or arg 2456 (if (or arg
2469 (y-or-n-p (format "Save abbrevs in %s? " abbrev-file-name))) 2457 (y-or-n-p (format "Save abbrevs in %s? " abbrev-file-name)))
2690 (setq found t))))) 2678 (setq found t)))))
2691 (yes-or-no-p (format "Revert buffer from file %s? " 2679 (yes-or-no-p (format "Revert buffer from file %s? "
2692 file-name))) 2680 file-name)))
2693 (run-hooks 'before-revert-hook) 2681 (run-hooks 'before-revert-hook)
2694 ;; If file was backed up but has changed since, 2682 ;; If file was backed up but has changed since,
2695 ;; we should make another backup. 2683 ;; we shd make another backup.
2696 (and (not auto-save-p) 2684 (and (not auto-save-p)
2697 (not (verify-visited-file-modtime (current-buffer))) 2685 (not (verify-visited-file-modtime (current-buffer)))
2698 (setq buffer-backed-up nil)) 2686 (setq buffer-backed-up nil))
2699 ;; Get rid of all undo records for this buffer. 2687 ;; Get rid of all undo records for this buffer.
2700 (or (eq buffer-undo-list t) 2688 (or (eq buffer-undo-list t)
2761 (cond ((if (file-exists-p file) 2749 (cond ((if (file-exists-p file)
2762 (not (file-newer-than-file-p file-name file)) 2750 (not (file-newer-than-file-p file-name file))
2763 (not (file-exists-p file-name))) 2751 (not (file-exists-p file-name)))
2764 (error "Auto-save file %s not current" file-name)) 2752 (error "Auto-save file %s not current" file-name))
2765 ((save-window-excursion 2753 ((save-window-excursion
2766 (if (not (eq system-type 'windows-nt)) 2754 (with-output-to-temp-buffer "*Directory*"
2767 (with-output-to-temp-buffer "*Directory*" 2755 (buffer-disable-undo standard-output)
2768 (buffer-disable-undo standard-output) 2756 (call-process "ls" nil standard-output nil
2769 (call-process "ls" nil standard-output nil 2757 (if (file-symlink-p file) "-lL" "-l")
2770 (if (file-symlink-p file) "-lL" "-l") 2758 file file-name))
2771 file file-name)))
2772 (yes-or-no-p (format "Recover auto save file %s? " file-name))) 2759 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
2773 (switch-to-buffer (find-file-noselect file t)) 2760 (switch-to-buffer (find-file-noselect file t))
2774 (let ((buffer-read-only nil)) 2761 (let ((buffer-read-only nil))
2775 (erase-buffer) 2762 (erase-buffer)
2776 (insert-file-contents file-name nil)) 2763 (insert-file-contents file-name nil))
3141 'insert-directory))) 3128 'insert-directory)))
3142 (if handler 3129 (if handler
3143 (funcall handler 'insert-directory file switches 3130 (funcall handler 'insert-directory file switches
3144 wildcard full-directory-p) 3131 wildcard full-directory-p)
3145 (cond 3132 (cond
3146 ;; #### mswindows-insert-directory should be called
3147 ;; nt-insert-directory - kkm.
3148 ((and (fboundp 'mswindows-insert-directory) 3133 ((and (fboundp 'mswindows-insert-directory)
3149 (eq system-type 'windows-nt)) 3134 (eq system-type 'windows-nt))
3150 (mswindows-insert-directory file switches wildcard full-directory-p)) 3135 (mswindows-insert-directory file switches wildcard full-directory-p))
3151 (t 3136 (t
3152 (if wildcard 3137 (if wildcard