(Fwindow_end): Don't call temp_set_pt_both with
[bpt/emacs.git] / lisp / files.el
index 5383a59..d92313e 100644 (file)
@@ -84,8 +84,9 @@ names that the old file had will now refer to the new (edited) file.
 The file's owner and group are unchanged.
 
 The choice of renaming or copying is controlled by the variables
-`backup-by-copying', `backup-by-copying-when-linked' and
-`backup-by-copying-when-mismatch'.  See also `backup-inhibited'."
+`backup-by-copying', `backup-by-copying-when-linked',
+`backup-by-copying-when-mismatch' and
+`backup-by-copying-when-privileged-mismatch'.  See also `backup-inhibited'."
   :type 'boolean
   :group 'backup)
 
@@ -120,6 +121,18 @@ This variable is relevant only if `backup-by-copying' is nil."
   :type 'boolean
   :group 'backup)
 
+(defcustom backup-by-copying-when-privileged-mismatch 200
+  "*Non-nil means create backups by copying to preserve a privileged owner.
+Renaming may still be used (subject to control of other variables)
+when it would not result in changing the owner of the file or if the owner
+has a user id greater than the value of this variable.  This is useful
+when low-numbered uid's are used for special system users (such as root)
+that must maintain ownership of certain files.
+This variable is relevant only if `backup-by-copying' and
+`backup-by-copying-when-mismatch' are nil."
+  :type '(choice (const nil) integer)
+  :group 'backup)
+
 (defvar backup-enable-predicate
   '(lambda (name)
      (or (< (length name) 5)
@@ -285,7 +298,8 @@ functions are called.")
 If one of them returns non-nil, the file is considered already written
 and the rest are not called.
 These hooks are considered to pertain to the visited file.
-So this list is cleared if you change the visited file name.
+So any buffer-local binding of `write-file-hooks' is
+discarded if you change the visited file name with \\[set-visited-file-name].
 
 Don't make this variable buffer-local; instead, use `local-write-file-hooks'.
 See also `write-contents-hooks'.")
@@ -381,10 +395,11 @@ and ignores this variable."
   "The directory for writing temporary files.")
 
 (defvar small-temporary-file-directory
-  (if (eq system-type 'ms-dos) (getenv "TMPDIR") temporary-file-directory)
+  (if (eq system-type 'ms-dos) (getenv "TMPDIR"))
   "The directory for writing small temporary files.
-This is for systems that have fast storage with limited space,
-such as a RAM disk.")
+If non-nil, this directory is used instead of `temporary-file-directory'
+by programs that create small temporary files.  This is for systems that
+have fast storage with limited space, such as a RAM disk.")
 
 ;; The system null device. (Should reference NULL_DEVICE from C.)
 (defvar null-device "/dev/null" "The system null device.")
@@ -487,10 +502,12 @@ This is an interface to the function `load'."
   (interactive "sLoad library: ")
   (load library))
 
-(defun file-local-copy (file &optional buffer)
+(defun file-local-copy (file)
   "Copy the file FILE into a temporary file on this machine.
 Returns the name of the local copy, or nil, if FILE is directly
 accessible."
+  ;; This formerly had an optional BUFFER argument that wasn't used by
+  ;; anything.
   (let ((handler (find-file-name-handler file 'file-local-copy)))
     (if handler
        (funcall handler 'file-local-copy file)
@@ -926,12 +943,14 @@ that are visiting the various files."
             find-file-wildcards
             (not (string-match "\\`/:" filename))
             (string-match "[[*?]" filename))
-       (let ((files (file-expand-wildcards filename t))
+       (let ((files (condition-case nil
+                        (file-expand-wildcards filename t)
+                      (error (list filename))))
              (find-file-wildcards nil))
          (if (null files)
-             (error "No files match `%s'" filename))
-         (mapcar #'(lambda (fn) (find-file-noselect fn))
-                 files))
+             (find-file-noselect filename)
+           (car (mapcar #'(lambda (fn) (find-file-noselect fn))
+                        files))))
       (let* ((buf (get-file-buffer filename))
             (truename (abbreviate-file-name (file-truename filename)))
             (number (nthcdr 10 (file-attributes truename)))
@@ -1173,7 +1192,7 @@ unless NOMODES is non-nil."
           (msg
            (cond ((and error (file-attributes buffer-file-name))
                   (setq buffer-read-only t)
-                  "File exists, but cannot be read.")
+                  "File exists, but cannot be read")
                  ((not buffer-read-only)
                   (if (and warn
                            (file-newer-than-file-p (make-auto-save-file-name)
@@ -1200,6 +1219,10 @@ unless NOMODES is non-nil."
            (or not-serious (sit-for 1 nil t)))))
     (if (and auto-save-default (not noauto))
        (auto-save-mode t)))
+  ;; Make people do a little extra work (C-x C-q)
+  ;; before altering a backup file.
+  (if (backup-file-name-p buffer-file-name)
+      (setq buffer-read-only t))
   (if nomodes
       nil
     (and view-read-only view-mode
@@ -1352,13 +1375,16 @@ in that case, this function acts as if `enable-local-variables' were t."
     ;; _emacs following a directory delimiter
     ;; in MsDos syntax
     ("[:/]_emacs\\'" . emacs-lisp-mode)
+    ("/crontab\\.X*[0-9]+\\'" . shell-script-mode)
     ("\\.ml\\'" . lisp-mode)
     ("\\.asn$" . snmp-mode)
     ("\\.mib$" . snmp-mode)
     ("\\.smi$" . snmp-mode)
     ("\\.as2$" . snmpv2-mode)
     ("\\.mi2$" . snmpv2-mode)
-    ("\\.sm2$" . snmpv2-mode))
+    ("\\.sm2$" . snmpv2-mode)
+    ("\\.\\(diffs?\\|patch\\|rej\\)\\'" . diff-mode)
+    ("\\.[eE]?[pP][sS]$" . ps-mode))
   "\
 Alist of filename patterns vs corresponding major mode functions.
 Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL).
@@ -2009,14 +2035,19 @@ no longer accessible under its old name."
                  ;; Actually write the back up file.
                  (condition-case ()
                      (if (or file-precious-flag
-    ;                    (file-symlink-p buffer-file-name)
+    ;                        (file-symlink-p buffer-file-name)
                              backup-by-copying
                              (and backup-by-copying-when-linked
                                   (> (file-nlinks real-file-name) 1))
-                             (and backup-by-copying-when-mismatch
+                             (and (or backup-by-copying-when-mismatch 
+                                      (integerp backup-by-copying-when-privileged-mismatch))
                                   (let ((attr (file-attributes real-file-name)))
-                                    (or (nth 9 attr)
-                                        (not (file-ownership-preserved-p real-file-name))))))
+                                    (and (or backup-by-copying-when-mismatch 
+                                             (and (integerp (nth 2 attr))
+                                                  (integerp backup-by-copying-when-privileged-mismatch)
+                                                  (<= (nth 2 attr) backup-by-copying-when-privileged-mismatch)))
+                                         (or (nth 9 attr)
+                                             (not (file-ownership-preserved-p real-file-name)))))))
                          (condition-case ()
                              (copy-file real-file-name backupname t t)
                            (file-error