]> code.delx.au - gnu-emacs/blobdiff - lisp/files.el
* lisp/info-look.el (info-lookup-select-mode): If major-mode has no
[gnu-emacs] / lisp / files.el
index 9fca70d36f72d787791560eb0390d5508c331598..f9ed65b8ac0659f29d450419db65d2053903683a 100644 (file)
@@ -507,6 +507,11 @@ and ignores this variable."
                 (other :tag "Query" other))
   :group 'find-file)
 
+(defvar enable-dir-local-variables t
+  "Non-nil means enable use of directory-local variables.
+Some modes may wish to set this to nil to prevent directory-local
+settings being applied, but still respect file-local ones.")
+
 ;; This is an odd variable IMO.
 ;; You might wonder why it is needed, when we could just do:
 ;; (set (make-local-variable 'enable-local-variables) nil)
@@ -3659,8 +3664,12 @@ is found.  Returns the new class name."
 (defun hack-dir-local-variables ()
   "Read per-directory local variables for the current buffer.
 Store the directory-local variables in `dir-local-variables-alist'
-and `file-local-variables-alist', without applying them."
+and `file-local-variables-alist', without applying them.
+
+This does nothing if either `enable-local-variables' or
+`enable-dir-local-variables' are nil."
   (when (and enable-local-variables
+            enable-dir-local-variables
             (or enable-remote-dir-locals
                 (not (file-remote-p (or (buffer-file-name)
                                         default-directory)))))
@@ -4554,28 +4563,39 @@ Before and after saving the buffer, this function runs
                 (not (file-exists-p buffer-file-name))))
        (let ((recent-save (recent-auto-save-p))
              setmodes)
-         ;; If buffer has no file name, ask user for one.
-         (or buffer-file-name
-             (let ((filename
-                    (expand-file-name
-                     (read-file-name "File to save in: "
-                                     nil (expand-file-name (buffer-name))))))
-               (if (file-exists-p filename)
-                   (if (file-directory-p filename)
-                       ;; Signal an error if the user specified the name of an
-                       ;; existing directory.
-                       (error "%s is a directory" filename)
-                     (unless (y-or-n-p (format "File `%s' exists; overwrite? "
-                                               filename))
-                       (error "Canceled")))
-                 ;; Signal an error if the specified name refers to a
-                 ;; non-existing directory.
-                 (let ((dir (file-name-directory filename)))
-                   (unless (file-directory-p dir)
-                     (if (file-exists-p dir)
-                         (error "%s is not a directory" dir)
-                       (error "%s: no such directory" dir)))))
-               (set-visited-file-name filename)))
+         (if buffer-file-name
+             (let ((dir (file-name-directory
+                         (expand-file-name buffer-file-name))))
+               (unless (file-exists-p dir)
+                 (if (y-or-n-p
+                      (format "Directory `%s' does not exist; create? " dir))
+                     (make-directory dir t)
+                   (error "Canceled"))))
+           ;; If buffer has no file name, ask user for one.
+           (let ((filename
+                  (expand-file-name
+                   (read-file-name "File to save in: "
+                                   nil (expand-file-name (buffer-name))))))
+             (if (file-exists-p filename)
+                 (if (file-directory-p filename)
+                     ;; Signal an error if the user specified the name of an
+                     ;; existing directory.
+                     (error "%s is a directory" filename)
+                   (unless (y-or-n-p (format "File `%s' exists; overwrite? "
+                                             filename))
+                     (error "Canceled")))
+               ;; Signal an error if the specified name refers to a
+               ;; non-existing directory.
+               (let ((dir (file-name-directory filename)))
+                 (unless (file-directory-p dir)
+                   (if (file-exists-p dir)
+                       (error "%s is not a directory" dir)
+                     (if (y-or-n-p
+                          (format "Directory `%s' does not exist; create? "
+                                  dir))
+                         (make-directory dir t)
+                       (error "Canceled"))))))
+             (set-visited-file-name filename)))
          (or (verify-visited-file-modtime (current-buffer))
              (not (file-exists-p buffer-file-name))
              (yes-or-no-p
@@ -4646,9 +4666,7 @@ Before and after saving the buffer, this function runs
            (basic-save-buffer-2))
        (basic-save-buffer-2))
     (if buffer-file-coding-system-explicit
-       (setcar buffer-file-coding-system-explicit last-coding-system-used)
-      (setq buffer-file-coding-system-explicit
-           (cons last-coding-system-used nil)))))
+       (setcar buffer-file-coding-system-explicit last-coding-system-used))))
 
 ;; This returns a value (MODES EXTENDED-ATTRIBUTES BACKUPNAME), like
 ;; backup-buffer.