Fix Bug#6019, Bug#9315.
[bpt/emacs.git] / lisp / files.el
index 0b253fc..6321cff 100644 (file)
@@ -151,6 +151,7 @@ Automatically local in all buffers."
   :type 'boolean
   :group 'backup)
 (make-variable-buffer-local 'buffer-offer-save)
+(put 'buffer-offer-save 'permanent-local t)
 
 (defcustom find-file-existing-other-name t
   "Non-nil means find a file under alternative names, in existing buffers.
@@ -1341,8 +1342,8 @@ automatically choosing a major mode, use \\[find-file-literally]."
                         (confirm-nonexistent-file-or-buffer)))
   (let ((value (find-file-noselect filename nil nil wildcards)))
     (if (listp value)
-       (mapcar #'pop-to-buffer-same-window (nreverse value))
-      (pop-to-buffer-same-window value))))
+       (mapcar 'switch-to-buffer (nreverse value))
+      (switch-to-buffer value))))
 
 (defun find-file-other-window (filename &optional wildcards)
   "Edit file FILENAME, in another window.
@@ -1638,11 +1639,6 @@ home directory is a root directory) and removes automounter prefixes
                        (substring filename (match-end 0)))))
       filename)))
 
-(defcustom find-file-not-true-dirname-list nil
-  "List of logical names for which visiting shouldn't save the true dirname."
-  :type '(repeat (string :tag "Name"))
-  :group 'find-file)
-
 (defun find-buffer-visiting (filename &optional predicate)
   "Return the buffer visiting file FILENAME (a string).
 This is like `get-file-buffer', except that it checks for any buffer
@@ -2465,7 +2461,9 @@ of a script, mode MODE is enabled.
 
 See also `auto-mode-alist'.")
 
-(defvar inhibit-first-line-modes-regexps (mapcar 'purecopy '("\\.tar\\'" "\\.tgz\\'"))
+(defvar inhibit-first-line-modes-regexps
+  (mapcar 'purecopy '("\\.tar\\'" "\\.tgz\\'" "\\.tiff?\\'"
+                     "\\.gif\\'" "\\.png\\'" "\\.jpe?g\\'"))
   "List of regexps; if one matches a file name, don't look for `-*-'.")
 
 (defvar inhibit-first-line-modes-suffixes nil
@@ -2631,12 +2629,12 @@ we don't actually set it to the same mode the buffer already has."
       (if buffer-file-name
          (let ((name buffer-file-name)
                (remote-id (file-remote-p buffer-file-name)))
+           ;; Remove backup-suffixes from file name.
+           (setq name (file-name-sans-versions name))
            ;; Remove remote file name identification.
            (when (and (stringp remote-id)
                       (string-match (regexp-quote remote-id) name))
              (setq name (substring name (match-end 0))))
-           ;; Remove backup-suffixes from file name.
-           (setq name (file-name-sans-versions name))
            (while name
              ;; Find first matching alist entry.
              (setq mode
@@ -2956,59 +2954,62 @@ Returns an alist of elements (VAR . VAL), where VAR is a variable
 and VAL is the specified value.  Ignores any specification for
 `mode:' and `coding:' (which should have already been handled
 by `set-auto-mode' and `set-auto-coding', respectively).
-Throws an error if the -*- line is malformed.
+Return nil if the -*- line is malformed.
 
 If MODE-ONLY is non-nil, just returns the symbol specifying the
 mode, if there is one, otherwise nil."
-  (save-excursion
-    (goto-char (point-min))
-    (let ((end (set-auto-mode-1))
-         result)
-      (cond ((not end)
-            nil)
-           ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)")
-            ;; Simple form: "-*- MODENAME -*-".
-            (if mode-only
-                (intern (concat (match-string 1) "-mode"))))
-           (t
-            ;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-'
-            ;; (last ";" is optional).
-            ;; If MODE-ONLY, just check for `mode'.
-            ;; Otherwise, parse the -*- line into the RESULT alist.
-            (while (and (or (not mode-only)
-                            (not result))
-                        (< (point) end))
-              (or (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*")
-                  (error "Malformed -*- line"))
-              (goto-char (match-end 0))
-              ;; There used to be a downcase here,
-              ;; but the manual didn't say so,
-              ;; and people want to set var names that aren't all lc.
-              (let* ((key (intern (match-string 1)))
-                     (val (save-restriction
-                            (narrow-to-region (point) end)
-                            (let ((read-circle nil))
-                              (read (current-buffer)))))
-                     ;; It is traditional to ignore
-                     ;; case when checking for `mode' in set-auto-mode,
-                     ;; so we must do that here as well.
-                     ;; That is inconsistent, but we're stuck with it.
-                     ;; The same can be said for `coding' in set-auto-coding.
-                     (keyname (downcase (symbol-name key))))
-                (if mode-only
-                    (and (equal keyname "mode")
-                         (setq result
-                               (intern (concat (downcase (symbol-name val))
-                                               "-mode"))))
-                  (or (equal keyname "coding")
-                      (condition-case nil
-                          (push (cons (if (eq key 'eval)
-                                          'eval
-                                        (indirect-variable key))
-                                      val) result)
-                        (error nil))))
-                (skip-chars-forward " \t;")))
-            result)))))
+  (catch 'malformed-line
+    (save-excursion
+      (goto-char (point-min))
+      (let ((end (set-auto-mode-1))
+           result)
+       (cond ((not end)
+              nil)
+             ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)")
+              ;; Simple form: "-*- MODENAME -*-".
+              (if mode-only
+                  (intern (concat (match-string 1) "-mode"))))
+             (t
+              ;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-'
+              ;; (last ";" is optional).
+              ;; If MODE-ONLY, just check for `mode'.
+              ;; Otherwise, parse the -*- line into the RESULT alist.
+              (while (and (or (not mode-only)
+                              (not result))
+                          (< (point) end))
+                (unless (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*")
+                  (message "Malformed mode-line")
+                  (throw 'malformed-line nil))
+                (goto-char (match-end 0))
+                ;; There used to be a downcase here,
+                ;; but the manual didn't say so,
+                ;; and people want to set var names that aren't all lc.
+                (let* ((key (intern (match-string 1)))
+                       (val (save-restriction
+                              (narrow-to-region (point) end)
+                              (let ((read-circle nil))
+                                (read (current-buffer)))))
+                       ;; It is traditional to ignore
+                       ;; case when checking for `mode' in set-auto-mode,
+                       ;; so we must do that here as well.
+                       ;; That is inconsistent, but we're stuck with it.
+                       ;; The same can be said for `coding' in set-auto-coding.
+                       (keyname (downcase (symbol-name key))))
+                  (if mode-only
+                      (and (equal keyname "mode")
+                           (setq result
+                                 (intern (concat (downcase (symbol-name val))
+                                                 "-mode"))))
+                    (or (equal keyname "coding")
+                        (condition-case nil
+                            (push (cons (cond ((eq key 'eval) 'eval)
+                                              ;; Downcase "Mode:".
+                                              ((equal keyname "mode") 'mode)
+                                              (t (indirect-variable key)))
+                                        val) result)
+                          (error nil))))
+                  (skip-chars-forward " \t;")))
+              result))))))
 
 (defun hack-local-variables-filter (variables dir-name)
   "Filter local variable settings, querying the user if necessary.
@@ -3152,6 +3153,8 @@ major-mode."
                           (var (let ((read-circle nil))
                                  (read str)))
                           val val2)
+                     (and (equal (downcase (symbol-name var)) "mode")
+                          (setq var 'mode))
                      ;; Read the variable value.
                      (skip-chars-forward "^:")
                      (forward-char 1)
@@ -4938,9 +4941,10 @@ directly into NEWNAME instead."
              (copy-file file target t keep-time)))))
 
       ;; Set directory attributes.
-      (set-file-modes newname (file-modes directory))
-      (if keep-time
-         (set-file-times newname (nth 5 (file-attributes directory)))))))
+      (let ((modes (file-modes directory))
+           (times (and keep-time (nth 5 (file-attributes directory)))))
+       (if modes (set-file-modes newname modes))
+       (if times (set-file-times newname times))))))
 \f
 (put 'revert-buffer-function 'permanent-local t)
 (defvar revert-buffer-function nil
@@ -6302,7 +6306,7 @@ as in \"og+rX-w\"."
   "Convert symbolic file modes to numeric file modes.
 MODES is the string to convert, it should match
 \"[ugoa]*([+-=][rwxXstugo]*)+,...\".
-See (info \"(coreutils)File permissions\") for more information on this
+See Info node `(coreutils)File permissions' for more information on this
 notation.
 FROM (or 0 if nil) gives the mode bits on which to base permissions if
 MODES request to add, remove, or set permissions based on existing ones,