import xemacs-21.2.37
[chise/xemacs-chise.git.1] / lisp / files.el
index 7a64a89..05d60f6 100644 (file)
@@ -291,11 +291,11 @@ changing the major mode does not clear it.  However, calling
 (defvar after-set-visited-file-name-hooks nil
   "List of functions to be called after \\[set-visited-file-name]
 or during \\[write-file].
-You can use this hook to restore local values of write-file-hooks,
-after-save-hook, and revert-buffer-function, which pertain
+You can use this hook to restore local values of `write-file-hooks',
+`after-save-hook', and `revert-buffer-function', which pertain
 to a specific file and therefore are normally killed by a rename.
-Put hooks pertaining to the buffer contents on write-contents-hooks
-and revert-buffer-insert-file-contents-function.")
+Put hooks pertaining to the buffer contents on `write-contents-hooks'
+and `revert-buffer-insert-file-contents-function'.")
 
 (defvar write-contents-hooks nil
   "List of functions to be called before writing out a buffer to a file.
@@ -870,26 +870,34 @@ If there is no such live buffer, return nil."
                 (setq list (cdr list))))
          found))))
 
-(defun insert-file-contents-literally (filename &optional visit beg end replace)
+(defun insert-file-contents-literally (filename &optional visit start end replace)
   "Like `insert-file-contents', q.v., but only reads in the file.
 A buffer may be modified in several ways after reading into the buffer due
-to advanced Emacs features, such as file-name-handlers, format decoding,
-find-file-hooks, etc.
+to advanced Emacs features, such as format decoding, character code
+conversion, find-file-hooks, automatic uncompression, etc.
+
   This function ensures that none of these modifications will take place."
-  (let ((file-name-handler-alist nil)
-       (format-alist nil)
-       (after-insert-file-functions nil)
-       (find-buffer-file-type-function
-        (if (fboundp 'find-buffer-file-type)
-            (symbol-function 'find-buffer-file-type)
-          nil)))
-    (unwind-protect
-       (progn
-         (fset 'find-buffer-file-type (lambda (filename) t))
-         (insert-file-contents filename visit beg end replace))
-      (if find-buffer-file-type-function
-         (fset 'find-buffer-file-type find-buffer-file-type-function)
-       (fmakunbound 'find-buffer-file-type)))))
+  (let ((wrap-func (find-file-name-handler filename
+                                          'insert-file-contents-literally)))
+    (if wrap-func
+       (funcall wrap-func 'insert-file-contents-literally filename
+                visit start end replace)
+      (let ((file-name-handler-alist nil)
+           (format-alist nil)
+           (after-insert-file-functions nil)
+           (coding-system-for-read 'binary)
+           (coding-system-for-write 'binary)
+           (find-buffer-file-type-function
+            (if (fboundp 'find-buffer-file-type)
+                (symbol-function 'find-buffer-file-type)
+              nil)))
+       (unwind-protect
+           (progn
+             (fset 'find-buffer-file-type (lambda (filename) t))
+             (insert-file-contents filename visit start end replace))
+         (if find-buffer-file-type-function
+             (fset 'find-buffer-file-type find-buffer-file-type-function)
+           (fmakunbound 'find-buffer-file-type)))))))
 
 (defun find-file-noselect (filename &optional nowarn rawfile)
   "Read file FILENAME into a buffer and return the buffer.
@@ -1165,11 +1173,12 @@ run `normal-mode' explicitly."
     ("\\.m\\(?:[mes]\\|an\\)\\'" . nroff-mode)
     ("\\.icn\\'" . icon-mode)
     ("\\.\\(?:[ckz]?sh\\|shar\\)\\'" . sh-mode)
-    ("\\.pro\\'" . idlwave-mode)
+    ("\\.[Pp][Rr][Oo]\\'" . idlwave-mode)
     ;; #### Unix-specific!
     ("/\\.\\(?:bash_\\|z\\)?\\(profile\\|login\\|logout\\)\\'" . sh-mode)
     ("/\\.\\(?:[ckz]sh\\|bash\\|tcsh\\|es\\|xinit\\|startx\\)rc\\'" . sh-mode)
     ("/\\.\\(?:[kz]shenv\\|xsession\\)\\'" . sh-mode)
+    ("\\.m?spec$" .sh-mode)
     ;; The following come after the ChangeLog pattern for the sake of
     ;; ChangeLog.1, etc. and after the .scm.[0-9] pattern too.
     ("\\.[12345678]\\'" . nroff-mode)
@@ -1197,7 +1206,6 @@ run `normal-mode' explicitly."
     ("\\.[sj]?html?\\'" . html-mode)
     ("\\.jsp\\'" . html-mode)
     ("\\.xml\\'" . xml-mode)
-    ("\\.htm?l?3\\'" . html3-mode)
     ("\\.\\(?:sgml?\\|dtd\\)\\'" . sgml-mode)
     ("\\.c?ps\\'" . postscript-mode)
     ;; .emacs following a directory delimiter in either Unix or
@@ -1206,7 +1214,7 @@ run `normal-mode' explicitly."
     ("\\.m4\\'" . autoconf-mode)
     ("configure\\.in\\'" . autoconf-mode)
     ("\\.ml\\'" . lisp-mode)
-    ("\\.ma?k\\'" . makefile-mode)
+    ("\\.ma?ke?\\'" . makefile-mode)
     ("[Mm]akefile\\(\\.\\|\\'\\)" . makefile-mode)
     ("\\.X\\(defaults\\|environment\\|resources\\|modmap\\)\\'" . xrdb-mode)
     ;; #### The following three are Unix-specific (but do we care?)
@@ -1251,8 +1259,7 @@ with the name of the interpreter specified in the first line.
 If it matches, mode MODE is selected.")
 
 (defvar binary-file-regexps
-  (purecopy
-   '("\\.\\(?:bz2\\|elc\\|g\\(if\\|z\\)\\|jp\\(eg\\|g\\)\\|png\\|t\\(ar\\|gz\\|iff\\)\\|[Zo]\\)\\'"))
+  '("\\.\\(?:bz2\\|elc\\|g\\(if\\|z\\)\\|jp\\(eg\\|g\\)\\|png\\|t\\(ar\\|gz\\|iff\\)\\|[Zo]\\)\\'")
   "List of regexps of filenames containing binary (non-text) data.")
 
 ;   (eval-when-compile
@@ -1272,9 +1279,9 @@ If it matches, mode MODE is selected.")
 ;               "tiff"
 ;               "jpg"
 ;               "jpeg"))))))
-  
+
 (defvar inhibit-first-line-modes-regexps
-  (purecopy binary-file-regexps)
+  binary-file-regexps
   "List of regexps; if one matches a file name, don't look for `-*-'.")
 
 (defvar inhibit-first-line-modes-suffixes nil
@@ -1472,7 +1479,7 @@ for current buffer."
               (or force
                    (hack-local-variables-p nil))))
        (let ((continue t)
-             prefix prefixlen suffix beg
+             prefix prefixlen suffix start
               (enable-local-eval enable-local-eval))
          ;; The prefix is what comes before "local variables:" in its line.
          ;; The suffix is what comes after "local variables:" in its line.
@@ -1499,11 +1506,11 @@ for current buffer."
                  (error "Local variables entry is missing the prefix")))
            ;; Find the variable name; strip whitespace.
            (skip-chars-forward " \t")
-           (setq beg (point))
+           (setq start (point))
            (skip-chars-forward "^:\n")
            (if (eolp) (error "Missing colon in local variables entry"))
            (skip-chars-backward " \t")
-           (let* ((str (buffer-substring beg (point)))
+           (let* ((str (buffer-substring start (point)))
                   (var (read str))
                  val)
              ;; Setting variable named "end" means end of list.
@@ -2083,9 +2090,8 @@ If the value is nil, don't make a backup."
   "Convert FILENAME to be relative to DIRECTORY (default: default-directory).
 This function returns a relative file name which is equivalent to FILENAME
 when used with that default directory as the default.
-If this is impossible (which can happen on MSDOS and Windows
-when the file name and directory use different drive names)
-then it returns FILENAME."
+If this is impossible (which can happen on MS Windows when the file name
+and directory use different drive names) then it returns FILENAME."
   (save-match-data
     (let ((fname (expand-file-name filename)))
       (setq directory (file-name-as-directory
@@ -2237,7 +2243,7 @@ After saving the buffer, run `after-save-hook'."
                (goto-char (point-max))
                (insert ?\n)))
 
-           ;; Run the write-file-hooks until one returns non-null.
+           ;; Run the write-file-hooks until one returns non-nil.
            ;; Bind after-save-hook to nil while running the
            ;; write-file-hooks so that if this function is called
            ;; recursively (from inside a write-file-hook) the
@@ -2353,9 +2359,9 @@ After saving the buffer, run `after-save-hook'."
   "Provide a clean way for a write-file-hook to wrap AROUND
 the execution of the remaining hooks and writing to disk.
 Do not call this function except from a functions
-on the write-file-hooks or write-contents-hooks list.
+on the `write-file-hooks' or `write-contents-hooks' list.
 A hook that calls this function must return non-nil,
-to signal completion to its caller.  continue-save-buffer
+to signal completion to its caller.  `continue-save-buffer'
 always returns non-nil."
   (let ((hooks (cdr (or continue-save-buffer-hooks-tail
                        (error
@@ -3157,19 +3163,19 @@ If WILDCARD, it also runs the shell specified by `shell-file-name'."
                           (file-name-directory file)
                           (file-name-directory (expand-file-name file))))
                  (pattern (file-name-nondirectory file))
-                 (beg 0))
+                 (start 0))
              ;; Quote some characters that have special meanings in shells;
              ;; but don't quote the wildcards--we want them to be special.
              ;; We also currently don't quote the quoting characters
              ;; in case people want to use them explicitly to quote
              ;; wildcard characters.
               ;;#### Unix-specific
-             (while (string-match "[ \t\n;<>&|()#$]" pattern beg)
+             (while (string-match "[ \t\n;<>&|()#$]" pattern start)
                (setq pattern
                      (concat (substring pattern 0 (match-beginning 0))
                              "\\"
                              (substring pattern (match-beginning 0)))
-                     beg (1+ (match-end 0))))
+                     start (1+ (match-end 0))))
              (call-process shell-file-name nil t nil
                            "-c" (concat "\\"  ;; Disregard shell aliases!
                                         insert-directory-program