diff options
| author | Chong Yidong | 2008-11-24 19:13:58 +0000 |
|---|---|---|
| committer | Chong Yidong | 2008-11-24 19:13:58 +0000 |
| commit | 4a977e2030bfd7061ff69ea6ec402525f37a62f2 (patch) | |
| tree | 1f02304d2aad67356926f7972b0e9900a9644a12 | |
| parent | 14ac7ce7ae45e495f78618930fc7004e0e947c88 (diff) | |
| download | emacs-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.el | 61 |
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. |
| 1107 | If nil, confirmation is not requested. | ||
| 1108 | If the value is `after-completion', confirmation is only | ||
| 1109 | requested if the user called `minibuffer-complete' right before | ||
| 1110 | `minibuffer-complete-and-exit'. | ||
| 1111 | Any other non-nil value means to request confirmation. | ||
| 1112 | |||
| 1107 | This affects commands like `switch-to-buffer' and `find-file'." | 1113 | This 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. | ||
| 1122 | The variable `confirm-nonexistent-file-or-buffer' determines the | ||
| 1123 | return 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. |
| 1125 | BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or | 1144 | BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or |
| 1126 | nil. Return the buffer switched to. | 1145 | nil. Return the buffer switched to. |
| 1127 | 1146 | ||
| 1147 | If called interactively, prompt for the buffer name using the | ||
| 1148 | minibuffer. The variable `confirm-nonexistent-file-or-buffer' | ||
| 1149 | determines whether to request confirmation before creating a new | ||
| 1150 | buffer. | ||
| 1151 | |||
| 1128 | If BUFFER-OR-NAME is a string and does not identify an existing | 1152 | If BUFFER-OR-NAME is a string and does not identify an existing |
| 1129 | buffer, create a new buffer with that name. Interactively, if | 1153 | buffer, create a new buffer with that name. If BUFFER-OR-NAME is |
| 1130 | `confirm-nonexistent-file-or-buffer' is non-nil, request | 1154 | nil, switch to the buffer returned by `other-buffer'. |
| 1131 | confirmation before creating a new buffer. If BUFFER-OR-NAME is | ||
| 1132 | nil, switch to buffer returned by `other-buffer'. | ||
| 1133 | 1155 | ||
| 1134 | Optional second argument NORECORD non-nil means do not put this | 1156 | Optional second argument NORECORD non-nil means do not put this |
| 1135 | buffer at the front of the list of recently selected ones. | 1157 | buffer at the front of the list of recently selected ones. |
| @@ -1147,11 +1169,14 @@ documentation for additional customization information." | |||
| 1147 | BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or | 1169 | BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or |
| 1148 | nil. Return the buffer switched to. | 1170 | nil. Return the buffer switched to. |
| 1149 | 1171 | ||
| 1172 | If called interactively, prompt for the buffer name using the | ||
| 1173 | minibuffer. The variable `confirm-nonexistent-file-or-buffer' | ||
| 1174 | determines whether to request confirmation before creating a new | ||
| 1175 | buffer. | ||
| 1176 | |||
| 1150 | If BUFFER-OR-NAME is a string and does not identify an existing | 1177 | If BUFFER-OR-NAME is a string and does not identify an existing |
| 1151 | buffer, create a new buffer with that name. Interactively, if | 1178 | buffer, create a new buffer with that name. If BUFFER-OR-NAME is |
| 1152 | `confirm-nonexistent-file-or-buffer' is non-nil, request | 1179 | nil, switch to the buffer returned by `other-buffer'. |
| 1153 | confirmation before creating a new buffer. If BUFFER-OR-NAME is | ||
| 1154 | nil, switch to buffer returned by `other-buffer'. | ||
| 1155 | 1180 | ||
| 1156 | Optional second arg NORECORD non-nil means do not put this | 1181 | Optional second arg NORECORD non-nil means do not put this |
| 1157 | buffer at the front of the list of recently selected ones. | 1182 | buffer 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 | |||
| 1241 | automatically choosing a major mode, use \\[find-file-literally]." | 1266 | automatically 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, | |||
| 1261 | expand wildcards (if any) and visit multiple files." | 1286 | expand 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, | |||
| 1284 | expand wildcards (if any) and visit multiple files." | 1309 | expand 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. | |||
| 1309 | Use \\[toggle-read-only] to permit editing." | 1334 | Use \\[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. | |||
| 1326 | Use \\[toggle-read-only] to permit editing." | 1351 | Use \\[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. | |||
| 1343 | Use \\[toggle-read-only] to permit editing." | 1368 | Use \\[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)) |