comparison lisp/files.el @ 444:576fb035e263 r21-2-37

Import from CVS: tag r21-2-37
author cvs
date Mon, 13 Aug 2007 11:36:19 +0200
parents abe6d1db359e
children 5aa1854ad537
comparison
equal deleted inserted replaced
443:a8296e22da4e 444:576fb035e263
289 ;; #### think about this (added by Sun). 289 ;; #### think about this (added by Sun).
290 (put 'after-set-visited-file-name-hooks 'permanent-local t) 290 (put 'after-set-visited-file-name-hooks 'permanent-local t)
291 (defvar after-set-visited-file-name-hooks nil 291 (defvar after-set-visited-file-name-hooks nil
292 "List of functions to be called after \\[set-visited-file-name] 292 "List of functions to be called after \\[set-visited-file-name]
293 or during \\[write-file]. 293 or during \\[write-file].
294 You can use this hook to restore local values of write-file-hooks, 294 You can use this hook to restore local values of `write-file-hooks',
295 after-save-hook, and revert-buffer-function, which pertain 295 `after-save-hook', and `revert-buffer-function', which pertain
296 to a specific file and therefore are normally killed by a rename. 296 to a specific file and therefore are normally killed by a rename.
297 Put hooks pertaining to the buffer contents on write-contents-hooks 297 Put hooks pertaining to the buffer contents on `write-contents-hooks'
298 and revert-buffer-insert-file-contents-function.") 298 and `revert-buffer-insert-file-contents-function'.")
299 299
300 (defvar write-contents-hooks nil 300 (defvar write-contents-hooks nil
301 "List of functions to be called before writing out a buffer to a file. 301 "List of functions to be called before writing out a buffer to a file.
302 If one of them returns non-nil, the file is considered already written 302 If one of them returns non-nil, the file is considered already written
303 and the rest are not called. 303 and the rest are not called.
868 number)) 868 number))
869 (setq found (car list)))) 869 (setq found (car list))))
870 (setq list (cdr list)))) 870 (setq list (cdr list))))
871 found)))) 871 found))))
872 872
873 (defun insert-file-contents-literally (filename &optional visit beg end replace) 873 (defun insert-file-contents-literally (filename &optional visit start end replace)
874 "Like `insert-file-contents', q.v., but only reads in the file. 874 "Like `insert-file-contents', q.v., but only reads in the file.
875 A buffer may be modified in several ways after reading into the buffer due 875 A buffer may be modified in several ways after reading into the buffer due
876 to advanced Emacs features, such as format decoding, character code 876 to advanced Emacs features, such as format decoding, character code
877 conversion,find-file-hooks, automatic uncompression, etc. 877 conversion, find-file-hooks, automatic uncompression, etc.
878 878
879 This function ensures that none of these modifications will take place." 879 This function ensures that none of these modifications will take place."
880 (let ((wrap-func (find-file-name-handler filename 880 (let ((wrap-func (find-file-name-handler filename
881 'insert-file-contents-literally))) 881 'insert-file-contents-literally)))
882 (if wrap-func 882 (if wrap-func
883 (funcall wrap-func 'insert-file-contents-literally filename 883 (funcall wrap-func 'insert-file-contents-literally filename
884 visit beg end replace) 884 visit start end replace)
885 (let ((file-name-handler-alist nil) 885 (let ((file-name-handler-alist nil)
886 (format-alist nil) 886 (format-alist nil)
887 (after-insert-file-functions nil) 887 (after-insert-file-functions nil)
888 (coding-system-for-read 'binary) 888 (coding-system-for-read 'binary)
889 (coding-system-for-write 'binary) 889 (coding-system-for-write 'binary)
892 (symbol-function 'find-buffer-file-type) 892 (symbol-function 'find-buffer-file-type)
893 nil))) 893 nil)))
894 (unwind-protect 894 (unwind-protect
895 (progn 895 (progn
896 (fset 'find-buffer-file-type (lambda (filename) t)) 896 (fset 'find-buffer-file-type (lambda (filename) t))
897 (insert-file-contents filename visit beg end replace)) 897 (insert-file-contents filename visit start end replace))
898 (if find-buffer-file-type-function 898 (if find-buffer-file-type-function
899 (fset 'find-buffer-file-type find-buffer-file-type-function) 899 (fset 'find-buffer-file-type find-buffer-file-type-function)
900 (fmakunbound 'find-buffer-file-type))))))) 900 (fmakunbound 'find-buffer-file-type)))))))
901 901
902 (defun find-file-noselect (filename &optional nowarn rawfile) 902 (defun find-file-noselect (filename &optional nowarn rawfile)
1171 ("\\.e\\'" . eiffel-mode) 1171 ("\\.e\\'" . eiffel-mode)
1172 ("\\.mss\\'" . scribe-mode) 1172 ("\\.mss\\'" . scribe-mode)
1173 ("\\.m\\(?:[mes]\\|an\\)\\'" . nroff-mode) 1173 ("\\.m\\(?:[mes]\\|an\\)\\'" . nroff-mode)
1174 ("\\.icn\\'" . icon-mode) 1174 ("\\.icn\\'" . icon-mode)
1175 ("\\.\\(?:[ckz]?sh\\|shar\\)\\'" . sh-mode) 1175 ("\\.\\(?:[ckz]?sh\\|shar\\)\\'" . sh-mode)
1176 ("\\.pro\\'" . idlwave-mode) 1176 ("\\.[Pp][Rr][Oo]\\'" . idlwave-mode)
1177 ;; #### Unix-specific! 1177 ;; #### Unix-specific!
1178 ("/\\.\\(?:bash_\\|z\\)?\\(profile\\|login\\|logout\\)\\'" . sh-mode) 1178 ("/\\.\\(?:bash_\\|z\\)?\\(profile\\|login\\|logout\\)\\'" . sh-mode)
1179 ("/\\.\\(?:[ckz]sh\\|bash\\|tcsh\\|es\\|xinit\\|startx\\)rc\\'" . sh-mode) 1179 ("/\\.\\(?:[ckz]sh\\|bash\\|tcsh\\|es\\|xinit\\|startx\\)rc\\'" . sh-mode)
1180 ("/\\.\\(?:[kz]shenv\\|xsession\\)\\'" . sh-mode) 1180 ("/\\.\\(?:[kz]shenv\\|xsession\\)\\'" . sh-mode)
1181 ("\\.m?spec$" .sh-mode) 1181 ("\\.m?spec$" .sh-mode)
1204 ("\\.m\\'" . objc-mode) 1204 ("\\.m\\'" . objc-mode)
1205 ("\\.oak\\'" . scheme-mode) 1205 ("\\.oak\\'" . scheme-mode)
1206 ("\\.[sj]?html?\\'" . html-mode) 1206 ("\\.[sj]?html?\\'" . html-mode)
1207 ("\\.jsp\\'" . html-mode) 1207 ("\\.jsp\\'" . html-mode)
1208 ("\\.xml\\'" . xml-mode) 1208 ("\\.xml\\'" . xml-mode)
1209 ("\\.htm?l?3\\'" . html3-mode)
1210 ("\\.\\(?:sgml?\\|dtd\\)\\'" . sgml-mode) 1209 ("\\.\\(?:sgml?\\|dtd\\)\\'" . sgml-mode)
1211 ("\\.c?ps\\'" . postscript-mode) 1210 ("\\.c?ps\\'" . postscript-mode)
1212 ;; .emacs following a directory delimiter in either Unix or 1211 ;; .emacs following a directory delimiter in either Unix or
1213 ;; Windows syntax. 1212 ;; Windows syntax.
1214 ("[/\\][._].*emacs\\'" . emacs-lisp-mode) 1213 ("[/\\][._].*emacs\\'" . emacs-lisp-mode)
1258 The car of each element is a regular expression which is compared 1257 The car of each element is a regular expression which is compared
1259 with the name of the interpreter specified in the first line. 1258 with the name of the interpreter specified in the first line.
1260 If it matches, mode MODE is selected.") 1259 If it matches, mode MODE is selected.")
1261 1260
1262 (defvar binary-file-regexps 1261 (defvar binary-file-regexps
1263 (purecopy 1262 '("\\.\\(?:bz2\\|elc\\|g\\(if\\|z\\)\\|jp\\(eg\\|g\\)\\|png\\|t\\(ar\\|gz\\|iff\\)\\|[Zo]\\)\\'")
1264 '("\\.\\(?:bz2\\|elc\\|g\\(if\\|z\\)\\|jp\\(eg\\|g\\)\\|png\\|t\\(ar\\|gz\\|iff\\)\\|[Zo]\\)\\'"))
1265 "List of regexps of filenames containing binary (non-text) data.") 1263 "List of regexps of filenames containing binary (non-text) data.")
1266 1264
1267 ; (eval-when-compile 1265 ; (eval-when-compile
1268 ; (require 'regexp-opt) 1266 ; (require 'regexp-opt)
1269 ; (list 1267 ; (list
1279 ; "png" 1277 ; "png"
1280 ; "gif" 1278 ; "gif"
1281 ; "tiff" 1279 ; "tiff"
1282 ; "jpg" 1280 ; "jpg"
1283 ; "jpeg")))))) 1281 ; "jpeg"))))))
1284 1282
1285 (defvar inhibit-first-line-modes-regexps 1283 (defvar inhibit-first-line-modes-regexps
1286 (purecopy binary-file-regexps) 1284 binary-file-regexps
1287 "List of regexps; if one matches a file name, don't look for `-*-'.") 1285 "List of regexps; if one matches a file name, don't look for `-*-'.")
1288 1286
1289 (defvar inhibit-first-line-modes-suffixes nil 1287 (defvar inhibit-first-line-modes-suffixes nil
1290 "List of regexps for what to ignore, for `inhibit-first-line-modes-regexps'. 1288 "List of regexps for what to ignore, for `inhibit-first-line-modes-regexps'.
1291 When checking `inhibit-first-line-modes-regexps', we first discard 1289 When checking `inhibit-first-line-modes-regexps', we first discard
1479 (if (let ((case-fold-search t)) 1477 (if (let ((case-fold-search t))
1480 (and (search-forward "Local Variables:" nil t) 1478 (and (search-forward "Local Variables:" nil t)
1481 (or force 1479 (or force
1482 (hack-local-variables-p nil)))) 1480 (hack-local-variables-p nil))))
1483 (let ((continue t) 1481 (let ((continue t)
1484 prefix prefixlen suffix beg 1482 prefix prefixlen suffix start
1485 (enable-local-eval enable-local-eval)) 1483 (enable-local-eval enable-local-eval))
1486 ;; The prefix is what comes before "local variables:" in its line. 1484 ;; The prefix is what comes before "local variables:" in its line.
1487 ;; The suffix is what comes after "local variables:" in its line. 1485 ;; The suffix is what comes after "local variables:" in its line.
1488 (skip-chars-forward " \t") 1486 (skip-chars-forward " \t")
1489 (or (eolp) 1487 (or (eolp)
1506 (if (looking-at prefix) 1504 (if (looking-at prefix)
1507 (forward-char prefixlen) 1505 (forward-char prefixlen)
1508 (error "Local variables entry is missing the prefix"))) 1506 (error "Local variables entry is missing the prefix")))
1509 ;; Find the variable name; strip whitespace. 1507 ;; Find the variable name; strip whitespace.
1510 (skip-chars-forward " \t") 1508 (skip-chars-forward " \t")
1511 (setq beg (point)) 1509 (setq start (point))
1512 (skip-chars-forward "^:\n") 1510 (skip-chars-forward "^:\n")
1513 (if (eolp) (error "Missing colon in local variables entry")) 1511 (if (eolp) (error "Missing colon in local variables entry"))
1514 (skip-chars-backward " \t") 1512 (skip-chars-backward " \t")
1515 (let* ((str (buffer-substring beg (point))) 1513 (let* ((str (buffer-substring start (point)))
1516 (var (read str)) 1514 (var (read str))
1517 val) 1515 val)
1518 ;; Setting variable named "end" means end of list. 1516 ;; Setting variable named "end" means end of list.
1519 (if (string-equal (downcase str) "end") 1517 (if (string-equal (downcase str) "end")
1520 (setq continue nil) 1518 (setq continue nil)
2243 (buffer-name)))))) 2241 (buffer-name))))))
2244 (save-excursion 2242 (save-excursion
2245 (goto-char (point-max)) 2243 (goto-char (point-max))
2246 (insert ?\n))) 2244 (insert ?\n)))
2247 2245
2248 ;; Run the write-file-hooks until one returns non-null. 2246 ;; Run the write-file-hooks until one returns non-nil.
2249 ;; Bind after-save-hook to nil while running the 2247 ;; Bind after-save-hook to nil while running the
2250 ;; write-file-hooks so that if this function is called 2248 ;; write-file-hooks so that if this function is called
2251 ;; recursively (from inside a write-file-hook) the 2249 ;; recursively (from inside a write-file-hook) the
2252 ;; after-hooks will only get run once (from the 2250 ;; after-hooks will only get run once (from the
2253 ;; outermost call). 2251 ;; outermost call).
2359 ;; XEmacs change, from Sun 2357 ;; XEmacs change, from Sun
2360 (defun continue-save-buffer () 2358 (defun continue-save-buffer ()
2361 "Provide a clean way for a write-file-hook to wrap AROUND 2359 "Provide a clean way for a write-file-hook to wrap AROUND
2362 the execution of the remaining hooks and writing to disk. 2360 the execution of the remaining hooks and writing to disk.
2363 Do not call this function except from a functions 2361 Do not call this function except from a functions
2364 on the write-file-hooks or write-contents-hooks list. 2362 on the `write-file-hooks' or `write-contents-hooks' list.
2365 A hook that calls this function must return non-nil, 2363 A hook that calls this function must return non-nil,
2366 to signal completion to its caller. continue-save-buffer 2364 to signal completion to its caller. `continue-save-buffer'
2367 always returns non-nil." 2365 always returns non-nil."
2368 (let ((hooks (cdr (or continue-save-buffer-hooks-tail 2366 (let ((hooks (cdr (or continue-save-buffer-hooks-tail
2369 (error 2367 (error
2370 "continue-save-buffer called outside a write-file-hook!")))) 2368 "continue-save-buffer called outside a write-file-hook!"))))
2371 (done nil)) 2369 (done nil))
3163 (let ((default-directory 3161 (let ((default-directory
3164 (if (file-name-absolute-p file) 3162 (if (file-name-absolute-p file)
3165 (file-name-directory file) 3163 (file-name-directory file)
3166 (file-name-directory (expand-file-name file)))) 3164 (file-name-directory (expand-file-name file))))
3167 (pattern (file-name-nondirectory file)) 3165 (pattern (file-name-nondirectory file))
3168 (beg 0)) 3166 (start 0))
3169 ;; Quote some characters that have special meanings in shells; 3167 ;; Quote some characters that have special meanings in shells;
3170 ;; but don't quote the wildcards--we want them to be special. 3168 ;; but don't quote the wildcards--we want them to be special.
3171 ;; We also currently don't quote the quoting characters 3169 ;; We also currently don't quote the quoting characters
3172 ;; in case people want to use them explicitly to quote 3170 ;; in case people want to use them explicitly to quote
3173 ;; wildcard characters. 3171 ;; wildcard characters.
3174 ;;#### Unix-specific 3172 ;;#### Unix-specific
3175 (while (string-match "[ \t\n;<>&|()#$]" pattern beg) 3173 (while (string-match "[ \t\n;<>&|()#$]" pattern start)
3176 (setq pattern 3174 (setq pattern
3177 (concat (substring pattern 0 (match-beginning 0)) 3175 (concat (substring pattern 0 (match-beginning 0))
3178 "\\" 3176 "\\"
3179 (substring pattern (match-beginning 0))) 3177 (substring pattern (match-beginning 0)))
3180 beg (1+ (match-end 0)))) 3178 start (1+ (match-end 0))))
3181 (call-process shell-file-name nil t nil 3179 (call-process shell-file-name nil t nil
3182 "-c" (concat "\\" ;; Disregard shell aliases! 3180 "-c" (concat "\\" ;; Disregard shell aliases!
3183 insert-directory-program 3181 insert-directory-program
3184 " -d " 3182 " -d "
3185 (if (stringp switches) 3183 (if (stringp switches)