]> code.delx.au - gnu-emacs/blobdiff - lisp/files.el
(byte-compile-dynamic)
[gnu-emacs] / lisp / files.el
index ab69c7958a9018722c746a3783b934c019f5d077..99972dc9709ba0d887ff4a49fef01e4f5410d4b9 100644 (file)
@@ -444,14 +444,21 @@ use `before-save-hook'.")
 
 (defcustom enable-local-variables t
   "*Control use of local variables in files you visit.
-The value can be t, nil or something else.
+The value can be t, nil, :safe, or something else.
 
 A value of t means file local variables specifications are obeyed
 if all the specified variable values are safe; if any values are
 not safe, Emacs queries you, once, whether to set them all.
+\(When you say yes to certain values, they are remembered as safe.)
+
+:safe means set the safe variables, and ignore the rest.
+:all means set all variables, whether safe or not.
+ (Don't set it permanently to :all.)
+nil means always ignore the file local variables.
 
-A value of nil means always ignore the file local variables.
 Any other value means always query you once whether to set them all.
+\(When you say yes to certain values, they are remembered as safe, but
+this has no effect when `enable-local-variables' is \"something else\".)
 
 This variable also controls use of major modes specified in
 a -*- line.
@@ -459,7 +466,9 @@ a -*- line.
 The command \\[normal-mode], when used interactively,
 always obeys file local variable specifications and the -*- line,
 and ignores this variable."
-  :type '(choice (const :tag "Obey" t)
+  :type '(choice (const :tag "Query Unsafe" t)
+                (const :tag "Safe Only" :safe)
+                (const :tag "Do all" :all)
                 (const :tag "Ignore" nil)
                 (other :tag "Query" other))
   :group 'find-file)
@@ -699,7 +708,7 @@ This is an interface to the function `load'."
   (interactive
    (list (completing-read "Load library: "
                          'locate-file-completion
-                         (cons load-path load-suffixes))))
+                         (cons load-path (get-load-suffixes)))))
   (load library))
 
 (defun file-remote-p (file)
@@ -990,6 +999,20 @@ documentation for additional customization information."
     (pop-to-buffer buffer t norecord)
     (raise-frame (window-frame (selected-window)))))
 
+(defun display-buffer-other-frame (buffer)
+  "Switch to buffer BUFFER in another frame.
+This uses the function `display-buffer' as a subroutine; see its
+documentation for additional customization information."
+  (interactive "BDisplay buffer in other frame: ")
+  (let ((pop-up-frames t)
+       same-window-buffer-names same-window-regexps
+        (old-window (selected-window))
+       new-window)
+    (setq new-window (display-buffer buffer t))
+    (lower-frame (window-frame new-window))
+    (make-frame-invisible (window-frame old-window))
+    (make-frame-visible (window-frame old-window))))
+
 (defvar find-file-default nil
   "Used within `find-file-read-args'.")
 
@@ -1765,8 +1788,7 @@ Uses the visited file name, the -*- line, and the local variables spec.
 
 This function is called automatically from `find-file'.  In that case,
 we may set up the file-specified mode and local variables,
-depending on the value of `enable-local-variables': if it is t, we do;
-if it is nil, we don't; otherwise, we query.
+depending on the value of `enable-local-variables'.
 In addition, if `local-enable-local-variables' is nil, we do
 not set local variables (though we do notice a mode specified with -*-.)
 
@@ -1872,7 +1894,7 @@ in that case, this function acts as if `enable-local-variables' were t."
      ;; `auto-coding-alist' with `no-conversion' coding system.
      ("\\.\\(arc\\|zip\\|lzh\\|zoo\\|[jew]ar\\|xpi\\)\\'" . archive-mode)
      ("\\.\\(ARC\\|ZIP\\|LZH\\|ZOO\\|[JEW]AR\\|XPI\\)\\'" . archive-mode)
-     ("\\.sx[dmicw]\\'" . archive-mode)        ; OpenOffice.org
+     ("\\.\\(sx[dmicw]\\|odt\\)\\'" . archive-mode)    ; OpenOffice.org
      ;; Mailer puts message to be edited in
      ;; /tmp/Re.... or Message
      ("\\`/tmp/Re" . text-mode)
@@ -1955,6 +1977,9 @@ REGEXP and search the list again for another match.
 If the file name matches `inhibit-first-line-modes-regexps',
 then `auto-mode-alist' is not processed.
 
+The extensions whose FUNCTION is `archive-mode' should also
+appear in `auto-coding-alist' with `no-conversion' coding system.
+
 See also `interpreter-mode-alist', which detects executable script modes
 based on the interpreters they specify to run,
 and `magic-mode-alist', which determines modes based on file contents.")
@@ -2261,6 +2286,7 @@ asking you for confirmation."
        default-text-properties
        display-time-string
        enable-local-eval
+       enable-local-variables
        eval
        exec-directory
        exec-path
@@ -2296,6 +2322,8 @@ asking you for confirmation."
        parse-time-rules
        process-environment
        rmail-output-file-alist
+       safe-local-variable-values
+       safe-local-eval-forms
        save-some-buffers-action-alist
        special-display-buffer-names
        standard-input
@@ -2305,41 +2333,47 @@ asking you for confirmation."
 
 ;; Safe local variables:
 ;;
-;; For variables defined by minor modes, put the safety declarations
-;; here, not in the file defining the minor mode (when Emacs visits a
-;; file specifying that local variable, the minor mode file may not be
-;; loaded yet).  For variables defined by major modes, the safety
-;; declarations can go into the major mode's file, since that will be
-;; loaded before file variables are processed.
+;; For variables defined by major modes, the safety declarations can go into
+;; the major mode's file, since that will be loaded before file variables are
+;; processed.
+;;
+;; For variables defined by minor modes, put the safety declarations in the
+;; file defining the minor mode after the defcustom/defvar using an autoload
+;; cookie, e.g.:
+;;
+;;   ;;;###autoload(put 'variable 'safe-local-variable 'stringp)
+;;
+;; Otherwise, when Emacs visits a file specifying that local variable, the
+;; minor mode file may not be loaded yet.
+;;
+;; For variables defined in the C source code the declaration should go here:
 
+;; FIXME: Some variables should be moved according to the rules above.
 (let ((string-or-null (lambda (a) (or (stringp a) (null a)))))
   (eval
    `(mapc (lambda (pair)
            (put (car pair) 'safe-local-variable (cdr pair)))
-         '((byte-compile-dynamic . t)
+         '((byte-compile-dynamic . booleanp)
+           (byte-compile-dynamic-docstrings . booleanp)
+           (byte-compile-warnings . booleanp)
            (c-basic-offset     .  integerp)
            (c-file-style       .  stringp)
            (c-indent-level     .  integerp)
            (comment-column     .  integerp)
-           (compile-command    . ,string-or-null)
+           (compile-command    .  string-or-null-p)
+           (find-file-visit-truename . booleanp)
            (fill-column        .  integerp)
-           (fill-prefix        . ,string-or-null)
-           (indent-tabs-mode   .  t)
-           (ispell-check-comments . (lambda (a)
-                                      (memq a '(nil t exclusive))))
-           (ispell-local-dictionary . ,string-or-null)
+           (fill-prefix        .  string-or-null-p)
+           (indent-tabs-mode   .  booleanp) ;; C source code
+           (kept-old-versions  .  integerp)
            (kept-new-versions  .  integerp)
-           (no-byte-compile    .  t)
-           (no-update-autoloads . t)
-           (outline-regexp     . ,string-or-null)
-           (page-delimiter     . ,string-or-null)
-           (paragraph-start    . ,string-or-null)
-           (paragraph-separate . ,string-or-null)
-           (sentence-end       . ,string-or-null)
-           (sentence-end-double-space . t)
-           (tab-width          .  integerp)
-           (truncate-lines     .  t)
-           (version-control    .  t)))))
+           (left-margin        .  integerp)
+           (no-byte-compile    .  booleanp)
+           (no-update-autoloads . booleanp)
+           (outline-regexp     .  string-or-null-p)
+           (tab-width          .  integerp) ;; C source code
+           (truncate-lines     .  booleanp) ;; C source code
+           (version-control    .  symbolp)))))
 
 (put 'c-set-style 'safe-local-eval-function t)
 
@@ -2349,6 +2383,7 @@ asking you for confirmation."
     (let ((name (if buffer-file-name
                    (file-name-nondirectory buffer-file-name)
                  (concat "buffer " (buffer-name))))
+         (offer-save (and (eq enable-local-variables t) unsafe-vars))
          prompt char)
       (save-window-excursion
        (let ((buf (get-buffer-create "*Local Variables*")))
@@ -2367,9 +2402,12 @@ asking you for confirmation."
              (insert "A local variables list is specified in " name ".")))
          (insert "\n\nDo you want to apply it?  You can type
 y  -- to apply the local variables list.
-n  -- to ignore the local variables list.
-!  -- to apply the local variables list, and mark these values (*) as
-      safe (in the future, they can be set automatically.)\n\n")
+n  -- to ignore the local variables list.")
+         (if offer-save
+             (insert "
+!  -- to apply the local variables list, and permanently mark these
+      values (*) as safe (in the future, they will be set automatically.)\n\n")
+           (insert "\n\n"))
          (dolist (elt vars)
            (cond ((member elt unsafe-vars)
                   (insert "  * "))
@@ -2381,12 +2419,16 @@ n  -- to ignore the local variables list.
            (insert " : ")
            (princ (cdr elt) buf)
            (insert "\n"))
-         (if (< (line-number-at-pos) (window-body-height))
-             (setq prompt "Please type y, n, or !: ")
-           (goto-char (point-min))
-           (setq prompt "Please type y, n, or !, or C-v to scroll: "))
-         (let ((inhibit-quit t)
-               (cursor-in-echo-area t)
+         (setq prompt
+               (format "Please type %s%s: "
+                       (if offer-save "y, n, or !" "y or n")
+                       (if (< (line-number-at-pos) (window-body-height))
+                           ""
+                         ", or C-v to scroll")))
+         (goto-char (point-min))
+         (let ((cursor-in-echo-area t)
+               (exit-chars
+                (if offer-save '(?! ?y ?n ?\s ?\C-g) '(?y ?n ?\s ?\C-g)))
                done)
            (while (not done)
              (message prompt)
@@ -2396,17 +2438,19 @@ n  -- to ignore the local variables list.
                      (condition-case nil
                          (scroll-up)
                        (error (goto-char (point-min))))
-                   (setq done (memq (downcase char)
-                                    '(?! ?y ?n ?\s ?\C-g))))))
-           (if (= char ?\C-g)
-               (setq quit-flag nil)))
+                   (setq done (memq (downcase char) exit-chars))))))
          (setq char (downcase char))
-         (when (and (= char ?!) unsafe-vars)
+         (when (and offer-save (= char ?!) unsafe-vars)
            (dolist (elt unsafe-vars)
              (add-to-list 'safe-local-variable-values elt))
-           (customize-save-variable
-            'safe-local-variable-values
-            safe-local-variable-values))
+           ;; When this is called from desktop-restore-file-buffer,
+           ;; coding-system-for-read may be non-nil.  Reset it before
+           ;; writing to .emacs.
+           (if (or custom-file user-init-file)
+               (let ((coding-system-for-read nil))
+                 (customize-save-variable
+                  'safe-local-variable-values
+                  safe-local-variable-values))))
          (kill-buffer buf)
          (or (= char ?!)
              (= char ?\s)
@@ -2582,13 +2626,23 @@ is specified, returning t if it is specified."
                    (and (risky-local-variable-p var val)
                         (push elt risky-vars))
                    (push elt unsafe-vars))))
-           (if (or (and (eq enable-local-variables t)
-                        (null unsafe-vars)
-                        (null risky-vars))
-                   (hack-local-variables-confirm
-                    result unsafe-vars risky-vars))
+           (if (eq enable-local-variables :safe)
+               ;; If caller wants only the safe variables,
+               ;; install only them.
                (dolist (elt result)
-                 (hack-one-local-variable (car elt) (cdr elt)))))
+                 (unless (or (memq (car elt) unsafe-vars)
+                             (memq (car elt) risky-vars))
+                   (hack-one-local-variable (car elt) (cdr elt))))
+             ;; Query, except in the case where all are known safe
+             ;; if the user wants no quuery in that case.
+             (if (or (and (eq enable-local-variables t)
+                          (null unsafe-vars)
+                          (null risky-vars))
+                     (eq enable-local-variables :all)
+                     (hack-local-variables-confirm
+                      result unsafe-vars risky-vars))
+                 (dolist (elt result)
+                   (hack-one-local-variable (car elt) (cdr elt))))))
          (run-hooks 'hack-local-variables-hook))))))
 
 (defun safe-local-variable-p (sym val)
@@ -2598,15 +2652,11 @@ It is safe if any of these conditions are met:
  * There is a matching entry (SYM . VAL) in the
    `safe-local-variable-values' user option.
 
- * The `safe-local-variable' property of SYM is t.
-
  * The `safe-local-variable' property of SYM is a function that
    evaluates to a non-nil value with VAL as an argument."
   (or (member (cons sym val) safe-local-variable-values)
       (let ((safep (get sym 'safe-local-variable)))
-       (or (eq safep t)
-           (and (functionp safep)
-                (funcall safep val))))))
+        (and (functionp safep) (funcall safep val)))))
 
 (defun risky-local-variable-p (sym &optional ignored)
   "Non-nil if SYM could be dangerous as a file-local variable.
@@ -2644,12 +2694,14 @@ It is dangerous if either of these conditions are met:
       (and (eq (car exp) 'put)
           (hack-one-local-variable-quotep (nth 1 exp))
           (hack-one-local-variable-quotep (nth 2 exp))
-          (memq (nth 1 (nth 2 exp))
-                '(lisp-indent-hook))
-          ;; Only allow safe values of lisp-indent-hook;
-          ;; not functions.
-          (or (numberp (nth 3 exp))
-              (equal (nth 3 exp) ''defun)))
+          (let ((prop (nth 1 (nth 2 exp))) (val (nth 3 exp)))
+            (cond ((eq prop 'lisp-indent-hook)
+                   ;; Only allow safe values of lisp-indent-hook;
+                   ;; not functions.
+                   (or (numberp val) (equal val ''defun)))
+                  ((eq prop 'edebug-form-spec)
+                   ;; Only allow indirect form specs.
+                   (edebug-basic-spec val)))))
       ;; Allow expressions that the user requested.
       (member exp safe-local-eval-forms)
       ;; Certain functions can be allowed with safe arguments
@@ -5121,6 +5173,7 @@ With prefix arg, silently save all file-visiting buffers, then kill."
 (define-key ctl-x-5-map "f" 'find-file-other-frame)
 (define-key ctl-x-5-map "\C-f" 'find-file-other-frame)
 (define-key ctl-x-5-map "r" 'find-file-read-only-other-frame)
+(define-key ctl-x-5-map "\C-o" 'display-buffer-other-frame)
 
 ;; arch-tag: bc68d3ea-19ca-468b-aac6-3a4a7766101f
 ;;; files.el ends here