changeset 99882:ccbff16a0960

(confirm-nonexistent-file-or-buffer): Allow `after-completion' value to request confirm only after TAB. (confirm-nonexistent-file-or-buffer): New function. (read-buffer-to-switch, find-file, find-file-other-window) (find-file-other-frame, find-file-read-only) (find-file-read-only-other-window) (find-file-read-only-other-frame): Use it. (switch-to-buffer-other-window, switch-to-buffer-other-frame): Doc fix.
author Chong Yidong <cyd@stupidchicken.com>
date Mon, 24 Nov 2008 19:13:58 +0000
parents 2842e1343bee
children 494c4c7bcf01
files lisp/files.el
diffstat 1 files changed, 43 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/files.el	Mon Nov 24 19:13:45 2008 +0000
+++ b/lisp/files.el	Mon Nov 24 19:13:58 2008 +0000
@@ -1102,12 +1102,31 @@
     (rename-file encoded new-encoded ok-if-already-exists)
     newname))
 
-(defcustom confirm-nonexistent-file-or-buffer nil
-  "If non-nil, confirmation is requested before visiting a new file or buffer.
+(defcustom confirm-nonexistent-file-or-buffer 'after-completion
+  "Whether confirmation is requested before visiting a new file or buffer.
+If nil, confirmation is not requested.
+If the value is `after-completion', confirmation is only
+ requested if the user called `minibuffer-complete' right before
+ `minibuffer-complete-and-exit'.
+Any other non-nil value means to request confirmation.
+
 This affects commands like `switch-to-buffer' and `find-file'."
   :group 'find-file
   :version "23.1"
-  :type 'boolean)
+  :type '(choice (other :tag "Always" t)
+		 (const :tag "After completion" after-completion)
+		 (const :tag "Never" nil)))
+
+(defun confirm-nonexistent-file-or-buffer ()
+  "Whether to request confirmation before visiting a new file or buffer.
+The variable `confirm-nonexistent-file-or-buffer' determines the
+return value, which may be passed as the REQUIRE-MATCH arg to
+`read-buffer' or `find-file-read-args'."
+  (cond ((eq confirm-nonexistent-file-or-buffer 'after-completion)
+	 'confirm-after-completion)
+	(confirm-nonexistent-file-or-buffer
+	 'confirm)
+	(t nil)))
 
 (defun read-buffer-to-switch (prompt)
   "Read the name of a buffer to switch to and return as a string.
@@ -1118,18 +1137,21 @@
     (minibuffer-with-setup-hook
         (lambda () (setq minibuffer-completion-table rbts-completion-table))
       (read-buffer prompt (other-buffer (current-buffer))
-                   (if confirm-nonexistent-file-or-buffer 'confirm-only)))))
+                   (confirm-nonexistent-file-or-buffer)))))
 
 (defun switch-to-buffer-other-window (buffer-or-name &optional norecord)
   "Select the buffer specified by BUFFER-OR-NAME in another window.
 BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or
 nil.  Return the buffer switched to.
 
+If called interactively, prompt for the buffer name using the
+minibuffer.  The variable `confirm-nonexistent-file-or-buffer'
+determines whether to request confirmation before creating a new
+buffer.
+
 If BUFFER-OR-NAME is a string and does not identify an existing
-buffer, create a new buffer with that name.  Interactively, if
-`confirm-nonexistent-file-or-buffer' is non-nil, request
-confirmation before creating a new buffer.  If BUFFER-OR-NAME is
-nil, switch to buffer returned by `other-buffer'.
+buffer, create a new buffer with that name.  If BUFFER-OR-NAME is
+nil, switch to the buffer returned by `other-buffer'.
 
 Optional second argument NORECORD non-nil means do not put this
 buffer at the front of the list of recently selected ones.
@@ -1147,11 +1169,14 @@
 BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or
 nil.  Return the buffer switched to.
 
+If called interactively, prompt for the buffer name using the
+minibuffer.  The variable `confirm-nonexistent-file-or-buffer'
+determines whether to request confirmation before creating a new
+buffer.
+
 If BUFFER-OR-NAME is a string and does not identify an existing
-buffer, create a new buffer with that name.  Interactively, if
-`confirm-nonexistent-file-or-buffer' is non-nil, request
-confirmation before creating a new buffer.  If BUFFER-OR-NAME is
-nil, switch to buffer returned by `other-buffer'.
+buffer, create a new buffer with that name.  If BUFFER-OR-NAME is
+nil, switch to the buffer returned by `other-buffer'.
 
 Optional second arg NORECORD non-nil means do not put this
 buffer at the front of the list of recently selected ones.
@@ -1241,7 +1266,7 @@
 automatically choosing a major mode, use \\[find-file-literally]."
   (interactive
    (find-file-read-args "Find file: "
-                        (if confirm-nonexistent-file-or-buffer 'confirm-only)))
+                        (confirm-nonexistent-file-or-buffer)))
   (let ((value (find-file-noselect filename nil nil wildcards)))
     (if (listp value)
 	(mapcar 'switch-to-buffer (nreverse value))
@@ -1261,7 +1286,7 @@
 expand wildcards (if any) and visit multiple files."
   (interactive
    (find-file-read-args "Find file in other window: "
-                        (if confirm-nonexistent-file-or-buffer 'confirm-only)))
+                        (confirm-nonexistent-file-or-buffer)))
   (let ((value (find-file-noselect filename nil nil wildcards)))
     (if (listp value)
 	(progn
@@ -1284,7 +1309,7 @@
 expand wildcards (if any) and visit multiple files."
   (interactive
    (find-file-read-args "Find file in other frame: "
-                        (if confirm-nonexistent-file-or-buffer 'confirm-only)))
+                        (confirm-nonexistent-file-or-buffer)))
   (let ((value (find-file-noselect filename nil nil wildcards)))
     (if (listp value)
 	(progn
@@ -1309,7 +1334,7 @@
 Use \\[toggle-read-only] to permit editing."
   (interactive
    (find-file-read-args "Find file read-only: "
-                        (if confirm-nonexistent-file-or-buffer 'confirm-only)))
+                        (confirm-nonexistent-file-or-buffer)))
   (unless (or (and wildcards find-file-wildcards
 		   (not (string-match "\\`/:" filename))
 		   (string-match "[[*?]" filename))
@@ -1326,7 +1351,7 @@
 Use \\[toggle-read-only] to permit editing."
   (interactive
    (find-file-read-args "Find file read-only other window: "
-                        (if confirm-nonexistent-file-or-buffer 'confirm-only)))
+                        (confirm-nonexistent-file-or-buffer)))
   (unless (or (and wildcards find-file-wildcards
 		   (not (string-match "\\`/:" filename))
 		   (string-match "[[*?]" filename))
@@ -1343,7 +1368,7 @@
 Use \\[toggle-read-only] to permit editing."
   (interactive
    (find-file-read-args "Find file read-only other frame: "
-                        (if confirm-nonexistent-file-or-buffer 'confirm-only)))
+                        (confirm-nonexistent-file-or-buffer)))
   (unless (or (and wildcards find-file-wildcards
 		   (not (string-match "\\`/:" filename))
 		   (string-match "[[*?]" filename))