aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2008-11-24 19:13:58 +0000
committerChong Yidong2008-11-24 19:13:58 +0000
commit4a977e2030bfd7061ff69ea6ec402525f37a62f2 (patch)
tree1f02304d2aad67356926f7972b0e9900a9644a12
parent14ac7ce7ae45e495f78618930fc7004e0e947c88 (diff)
downloademacs-4a977e2030bfd7061ff69ea6ec402525f37a62f2.tar.gz
emacs-4a977e2030bfd7061ff69ea6ec402525f37a62f2.zip
(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.
-rw-r--r--lisp/files.el61
1 files changed, 43 insertions, 18 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 9b317252c36..a071e2bb435 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1102,12 +1102,31 @@ use with M-x."
1102 (rename-file encoded new-encoded ok-if-already-exists) 1102 (rename-file encoded new-encoded ok-if-already-exists)
1103 newname)) 1103 newname))
1104 1104
1105(defcustom confirm-nonexistent-file-or-buffer nil 1105(defcustom confirm-nonexistent-file-or-buffer 'after-completion
1106 "If non-nil, confirmation is requested before visiting a new file or buffer. 1106 "Whether confirmation is requested before visiting a new file or buffer.
1107If nil, confirmation is not requested.
1108If the value is `after-completion', confirmation is only
1109 requested if the user called `minibuffer-complete' right before
1110 `minibuffer-complete-and-exit'.
1111Any other non-nil value means to request confirmation.
1112
1107This affects commands like `switch-to-buffer' and `find-file'." 1113This affects commands like `switch-to-buffer' and `find-file'."
1108 :group 'find-file 1114 :group 'find-file
1109 :version "23.1" 1115 :version "23.1"
1110 :type 'boolean) 1116 :type '(choice (other :tag "Always" t)
1117 (const :tag "After completion" after-completion)
1118 (const :tag "Never" nil)))
1119
1120(defun confirm-nonexistent-file-or-buffer ()
1121 "Whether to request confirmation before visiting a new file or buffer.
1122The variable `confirm-nonexistent-file-or-buffer' determines the
1123return value, which may be passed as the REQUIRE-MATCH arg to
1124`read-buffer' or `find-file-read-args'."
1125 (cond ((eq confirm-nonexistent-file-or-buffer 'after-completion)
1126 'confirm-after-completion)
1127 (confirm-nonexistent-file-or-buffer
1128 'confirm)
1129 (t nil)))
1111 1130
1112(defun read-buffer-to-switch (prompt) 1131(defun read-buffer-to-switch (prompt)
1113 "Read the name of a buffer to switch to and return as a string. 1132 "Read the name of a buffer to switch to and return as a string.
@@ -1118,18 +1137,21 @@ and default values."
1118 (minibuffer-with-setup-hook 1137 (minibuffer-with-setup-hook
1119 (lambda () (setq minibuffer-completion-table rbts-completion-table)) 1138 (lambda () (setq minibuffer-completion-table rbts-completion-table))
1120 (read-buffer prompt (other-buffer (current-buffer)) 1139 (read-buffer prompt (other-buffer (current-buffer))
1121 (if confirm-nonexistent-file-or-buffer 'confirm-only))))) 1140 (confirm-nonexistent-file-or-buffer)))))
1122 1141
1123(defun switch-to-buffer-other-window (buffer-or-name &optional norecord) 1142(defun switch-to-buffer-other-window (buffer-or-name &optional norecord)
1124 "Select the buffer specified by BUFFER-OR-NAME in another window. 1143 "Select the buffer specified by BUFFER-OR-NAME in another window.
1125BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or 1144BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or
1126nil. Return the buffer switched to. 1145nil. Return the buffer switched to.
1127 1146
1147If called interactively, prompt for the buffer name using the
1148minibuffer. The variable `confirm-nonexistent-file-or-buffer'
1149determines whether to request confirmation before creating a new
1150buffer.
1151
1128If BUFFER-OR-NAME is a string and does not identify an existing 1152If BUFFER-OR-NAME is a string and does not identify an existing
1129buffer, create a new buffer with that name. Interactively, if 1153buffer, create a new buffer with that name. If BUFFER-OR-NAME is
1130`confirm-nonexistent-file-or-buffer' is non-nil, request 1154nil, switch to the buffer returned by `other-buffer'.
1131confirmation before creating a new buffer. If BUFFER-OR-NAME is
1132nil, switch to buffer returned by `other-buffer'.
1133 1155
1134Optional second argument NORECORD non-nil means do not put this 1156Optional second argument NORECORD non-nil means do not put this
1135buffer at the front of the list of recently selected ones. 1157buffer at the front of the list of recently selected ones.
@@ -1147,11 +1169,14 @@ documentation for additional customization information."
1147BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or 1169BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or
1148nil. Return the buffer switched to. 1170nil. Return the buffer switched to.
1149 1171
1172If called interactively, prompt for the buffer name using the
1173minibuffer. The variable `confirm-nonexistent-file-or-buffer'
1174determines whether to request confirmation before creating a new
1175buffer.
1176
1150If BUFFER-OR-NAME is a string and does not identify an existing 1177If BUFFER-OR-NAME is a string and does not identify an existing
1151buffer, create a new buffer with that name. Interactively, if 1178buffer, create a new buffer with that name. If BUFFER-OR-NAME is
1152`confirm-nonexistent-file-or-buffer' is non-nil, request 1179nil, switch to the buffer returned by `other-buffer'.
1153confirmation before creating a new buffer. If BUFFER-OR-NAME is
1154nil, switch to buffer returned by `other-buffer'.
1155 1180
1156Optional second arg NORECORD non-nil means do not put this 1181Optional second arg NORECORD non-nil means do not put this
1157buffer at the front of the list of recently selected ones. 1182buffer at the front of the list of recently selected ones.
@@ -1241,7 +1266,7 @@ To visit a file without any kind of conversion and without
1241automatically choosing a major mode, use \\[find-file-literally]." 1266automatically choosing a major mode, use \\[find-file-literally]."
1242 (interactive 1267 (interactive
1243 (find-file-read-args "Find file: " 1268 (find-file-read-args "Find file: "
1244 (if confirm-nonexistent-file-or-buffer 'confirm-only))) 1269 (confirm-nonexistent-file-or-buffer)))
1245 (let ((value (find-file-noselect filename nil nil wildcards))) 1270 (let ((value (find-file-noselect filename nil nil wildcards)))
1246 (if (listp value) 1271 (if (listp value)
1247 (mapcar 'switch-to-buffer (nreverse value)) 1272 (mapcar 'switch-to-buffer (nreverse value))
@@ -1261,7 +1286,7 @@ Interactively, or if WILDCARDS is non-nil in a call from Lisp,
1261expand wildcards (if any) and visit multiple files." 1286expand wildcards (if any) and visit multiple files."
1262 (interactive 1287 (interactive
1263 (find-file-read-args "Find file in other window: " 1288 (find-file-read-args "Find file in other window: "
1264 (if confirm-nonexistent-file-or-buffer 'confirm-only))) 1289 (confirm-nonexistent-file-or-buffer)))
1265 (let ((value (find-file-noselect filename nil nil wildcards))) 1290 (let ((value (find-file-noselect filename nil nil wildcards)))
1266 (if (listp value) 1291 (if (listp value)
1267 (progn 1292 (progn
@@ -1284,7 +1309,7 @@ Interactively, or if WILDCARDS is non-nil in a call from Lisp,
1284expand wildcards (if any) and visit multiple files." 1309expand wildcards (if any) and visit multiple files."
1285 (interactive 1310 (interactive
1286 (find-file-read-args "Find file in other frame: " 1311 (find-file-read-args "Find file in other frame: "
1287 (if confirm-nonexistent-file-or-buffer 'confirm-only))) 1312 (confirm-nonexistent-file-or-buffer)))
1288 (let ((value (find-file-noselect filename nil nil wildcards))) 1313 (let ((value (find-file-noselect filename nil nil wildcards)))
1289 (if (listp value) 1314 (if (listp value)
1290 (progn 1315 (progn
@@ -1309,7 +1334,7 @@ Like \\[find-file], but marks buffer as read-only.
1309Use \\[toggle-read-only] to permit editing." 1334Use \\[toggle-read-only] to permit editing."
1310 (interactive 1335 (interactive
1311 (find-file-read-args "Find file read-only: " 1336 (find-file-read-args "Find file read-only: "
1312 (if confirm-nonexistent-file-or-buffer 'confirm-only))) 1337 (confirm-nonexistent-file-or-buffer)))
1313 (unless (or (and wildcards find-file-wildcards 1338 (unless (or (and wildcards find-file-wildcards
1314 (not (string-match "\\`/:" filename)) 1339 (not (string-match "\\`/:" filename))
1315 (string-match "[[*?]" filename)) 1340 (string-match "[[*?]" filename))
@@ -1326,7 +1351,7 @@ Like \\[find-file-other-window], but marks buffer as read-only.
1326Use \\[toggle-read-only] to permit editing." 1351Use \\[toggle-read-only] to permit editing."
1327 (interactive 1352 (interactive
1328 (find-file-read-args "Find file read-only other window: " 1353 (find-file-read-args "Find file read-only other window: "
1329 (if confirm-nonexistent-file-or-buffer 'confirm-only))) 1354 (confirm-nonexistent-file-or-buffer)))
1330 (unless (or (and wildcards find-file-wildcards 1355 (unless (or (and wildcards find-file-wildcards
1331 (not (string-match "\\`/:" filename)) 1356 (not (string-match "\\`/:" filename))
1332 (string-match "[[*?]" filename)) 1357 (string-match "[[*?]" filename))
@@ -1343,7 +1368,7 @@ Like \\[find-file-other-frame], but marks buffer as read-only.
1343Use \\[toggle-read-only] to permit editing." 1368Use \\[toggle-read-only] to permit editing."
1344 (interactive 1369 (interactive
1345 (find-file-read-args "Find file read-only other frame: " 1370 (find-file-read-args "Find file read-only other frame: "
1346 (if confirm-nonexistent-file-or-buffer 'confirm-only))) 1371 (confirm-nonexistent-file-or-buffer)))
1347 (unless (or (and wildcards find-file-wildcards 1372 (unless (or (and wildcards find-file-wildcards
1348 (not (string-match "\\`/:" filename)) 1373 (not (string-match "\\`/:" filename))
1349 (string-match "[[*?]" filename)) 1374 (string-match "[[*?]" filename))