Mercurial > emacs
comparison lisp/ido.el @ 103191:1ea11abb22f8
Add proper support for confirm-nonexistent-file-or-buffer
values `confirm' and `confirm-after-completion'.
(ido-read-internal, ido-buffer-internal, ido-file-internal):
Setup and handle require-match arg according to c-n-f-o-b.
(ido-show-confirm-message): New dynamic variable.
(ido-exit-minibuffer): Request confirmation for non-existing file
or buffer according to confirm-nonexistent-file-or-buffer.
(ido-decorations): Add 11th element for "confirm" message.
(ido-completions): Show confirmation message when requested.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Sun, 10 May 2009 21:21:33 +0000 |
parents | a9dc0e7c3f2b |
children | 5e04d99c2e49 |
comparison
equal
deleted
inserted
replaced
103190:21a9a415c6d0 | 103191:1ea11abb22f8 |
---|---|
766 "String used by ido to separate the alternatives in the minibuffer. | 766 "String used by ido to separate the alternatives in the minibuffer. |
767 Obsolete. Set 3rd element of `ido-decorations' instead." | 767 Obsolete. Set 3rd element of `ido-decorations' instead." |
768 :type '(choice string (const nil)) | 768 :type '(choice string (const nil)) |
769 :group 'ido) | 769 :group 'ido) |
770 | 770 |
771 (defcustom ido-decorations '( "{" "}" " | " " | ..." "[" "]" " [No match]" " [Matched]" " [Not readable]" " [Too big]") | 771 (defcustom ido-decorations '( "{" "}" " | " " | ..." "[" "]" " [No match]" " [Matched]" " [Not readable]" " [Too big]" " [Confirm]") |
772 "List of strings used by ido to display the alternatives in the minibuffer. | 772 "List of strings used by ido to display the alternatives in the minibuffer. |
773 There are 10 elements in this list: | 773 There are 10 elements in this list: |
774 1st and 2nd elements are used as brackets around the prospect list, | 774 1st and 2nd elements are used as brackets around the prospect list, |
775 3rd element is the separator between prospects (ignored if `ido-separator' is set), | 775 3rd element is the separator between prospects (ignored if `ido-separator' is set), |
776 4th element is the string inserted at the end of a truncated list of prospects, | 776 4th element is the string inserted at the end of a truncated list of prospects, |
777 5th and 6th elements are used as brackets around the common match string which | 777 5th and 6th elements are used as brackets around the common match string which |
778 can be completed using TAB, | 778 can be completed using TAB, |
779 7th element is the string displayed when there are no matches, and | 779 7th element is the string displayed when there are no matches, and |
780 8th element is displayed if there is a single match (and faces are not used), | 780 8th element is displayed if there is a single match (and faces are not used), |
781 9th element is displayed when the current directory is non-readable, | 781 9th element is displayed when the current directory is non-readable, |
782 10th element is displayed when directory exceeds `ido-max-directory-size'." | 782 10th element is displayed when directory exceeds `ido-max-directory-size', |
783 11th element is displayed to confirm creating new file or buffer." | |
783 :type '(repeat string) | 784 :type '(repeat string) |
784 :group 'ido) | 785 :group 'ido) |
785 | 786 |
786 (defcustom ido-use-faces t | 787 (defcustom ido-use-faces t |
787 "Non-nil means use ido faces to highlighting first match, only match and | 788 "Non-nil means use ido faces to highlighting first match, only match and |
1079 ;; Buffer from which ido was entered. | 1080 ;; Buffer from which ido was entered. |
1080 (defvar ido-entry-buffer) | 1081 (defvar ido-entry-buffer) |
1081 | 1082 |
1082 ;; Non-nil if matching file must be selected. | 1083 ;; Non-nil if matching file must be selected. |
1083 (defvar ido-require-match) | 1084 (defvar ido-require-match) |
1085 | |
1086 ;; Non-nil if we should add [confirm] to prompt | |
1087 (defvar ido-show-confirm-message) | |
1084 | 1088 |
1085 ;; Stores a temporary version of the file list being created. | 1089 ;; Stores a temporary version of the file list being created. |
1086 (defvar ido-temp-list) | 1090 (defvar ido-temp-list) |
1087 | 1091 |
1088 ;; Non-nil if default list element should be rotated into place. | 1092 ;; Non-nil if default list element should be rotated into place. |
1801 Return the name of a buffer or file selected. | 1805 Return the name of a buffer or file selected. |
1802 PROMPT is the prompt to give to the user. | 1806 PROMPT is the prompt to give to the user. |
1803 DEFAULT if given is the default item to start with. | 1807 DEFAULT if given is the default item to start with. |
1804 If REQUIRE-MATCH is non-nil, an existing file must be selected. | 1808 If REQUIRE-MATCH is non-nil, an existing file must be selected. |
1805 If INITIAL is non-nil, it specifies the initial input string." | 1809 If INITIAL is non-nil, it specifies the initial input string." |
1806 ;; Ido does not implement the `confirm' and | |
1807 ;; `confirm-after-completion' values of REQUIRE-MATCH. | |
1808 (if (memq require-match '(confirm confirm-after-completion)) | |
1809 (setq require-match nil)) | |
1810 (let | 1810 (let |
1811 ((ido-cur-item item) | 1811 ((ido-cur-item item) |
1812 (ido-entry-buffer (current-buffer)) | 1812 (ido-entry-buffer (current-buffer)) |
1813 (ido-process-ignore-lists t) | 1813 (ido-process-ignore-lists t) |
1814 (ido-process-ignore-lists-inhibit nil) | 1814 (ido-process-ignore-lists-inhibit nil) |
1827 (ido-try-merged-list t) | 1827 (ido-try-merged-list t) |
1828 (ido-pre-merge-state nil) | 1828 (ido-pre-merge-state nil) |
1829 (ido-case-fold ido-case-fold) | 1829 (ido-case-fold ido-case-fold) |
1830 (ido-enable-prefix ido-enable-prefix) | 1830 (ido-enable-prefix ido-enable-prefix) |
1831 (ido-enable-regexp ido-enable-regexp) | 1831 (ido-enable-regexp ido-enable-regexp) |
1832 (ido-show-confirm-message nil) | |
1832 ) | 1833 ) |
1833 | 1834 |
1834 (ido-setup-completion-map) | 1835 (ido-setup-completion-map) |
1835 (setq ido-text-init initial) | 1836 (setq ido-text-init initial) |
1836 (setq ido-input-stack nil) | 1837 (setq ido-input-stack nil) |
2065 (setq ido-cur-item (car elt)) | 2066 (setq ido-cur-item (car elt)) |
2066 (setq ido-text-init (cdr elt))))) | 2067 (setq ido-text-init (cdr elt))))) |
2067 | 2068 |
2068 ;; Handling the require-match must be done in a better way. | 2069 ;; Handling the require-match must be done in a better way. |
2069 ((and require-match | 2070 ((and require-match |
2071 (not (memq require-match '(confirm confirm-after-completion))) | |
2070 (not (if ido-directory-too-big | 2072 (not (if ido-directory-too-big |
2071 (file-exists-p (concat ido-current-directory ido-final-text)) | 2073 (file-exists-p (concat ido-current-directory ido-final-text)) |
2072 (ido-existing-item-p)))) | 2074 (ido-existing-item-p)))) |
2073 (error "Must specify valid item")) | 2075 (error "Must specify valid item")) |
2074 | 2076 |
2156 (call-interactively (or fallback 'switch-to-buffer))) | 2158 (call-interactively (or fallback 'switch-to-buffer))) |
2157 (let* ((ido-context-switch-command switch-cmd) | 2159 (let* ((ido-context-switch-command switch-cmd) |
2158 (ido-current-directory nil) | 2160 (ido-current-directory nil) |
2159 (ido-directory-nonreadable nil) | 2161 (ido-directory-nonreadable nil) |
2160 (ido-directory-too-big nil) | 2162 (ido-directory-too-big nil) |
2161 (buf (ido-read-internal 'buffer (or prompt "Buffer: ") 'ido-buffer-history default nil initial))) | 2163 (require-match (confirm-nonexistent-file-or-buffer)) |
2164 (buf (ido-read-internal 'buffer (or prompt "Buffer: ") 'ido-buffer-history default | |
2165 require-match initial))) | |
2162 | 2166 |
2163 ;; Choose the buffer name: either the text typed in, or the head | 2167 ;; Choose the buffer name: either the text typed in, or the head |
2164 ;; of the list of matches | 2168 ;; of the list of matches |
2165 | 2169 |
2166 (cond | 2170 (cond |
2193 (insert-buffer-substring (get-buffer buf)) | 2197 (insert-buffer-substring (get-buffer buf)) |
2194 (point)))) | 2198 (point)))) |
2195 (ido-visit-buffer buf method t))) | 2199 (ido-visit-buffer buf method t))) |
2196 | 2200 |
2197 ;; buffer doesn't exist | 2201 ;; buffer doesn't exist |
2198 ((eq ido-create-new-buffer 'never) | 2202 ((and (eq ido-create-new-buffer 'never) |
2203 (null require-match)) | |
2199 (message "No buffer matching `%s'" buf)) | 2204 (message "No buffer matching `%s'" buf)) |
2200 | 2205 |
2201 ((and (eq ido-create-new-buffer 'prompt) | 2206 ((and (eq ido-create-new-buffer 'prompt) |
2207 (null require-match) | |
2202 (not (y-or-n-p (format "No buffer matching `%s', create one? " buf)))) | 2208 (not (y-or-n-p (format "No buffer matching `%s', create one? " buf)))) |
2203 nil) | 2209 nil) |
2204 | 2210 |
2205 ;; create a new buffer | 2211 ;; create a new buffer |
2206 (t | 2212 (t |
2305 (let ((minibuffer-completing-file-name t)) | 2311 (let ((minibuffer-completing-file-name t)) |
2306 (setq filename (ido-read-internal item | 2312 (setq filename (ido-read-internal item |
2307 (or prompt "Find file: ") | 2313 (or prompt "Find file: ") |
2308 'ido-file-history | 2314 'ido-file-history |
2309 (and (eq method 'alt-file) buffer-file-name) | 2315 (and (eq method 'alt-file) buffer-file-name) |
2310 nil initial)))) | 2316 (confirm-nonexistent-file-or-buffer) initial)))) |
2311 | 2317 |
2312 ;; Choose the file name: either the text typed in, or the head | 2318 ;; Choose the file name: either the text typed in, or the head |
2313 ;; of the list of matches | 2319 ;; of the list of matches |
2314 | 2320 |
2315 (cond | 2321 (cond |
2679 | 2685 |
2680 (defun ido-exit-minibuffer () | 2686 (defun ido-exit-minibuffer () |
2681 "Exit minibuffer, but make sure we have a match if one is needed." | 2687 "Exit minibuffer, but make sure we have a match if one is needed." |
2682 (interactive) | 2688 (interactive) |
2683 (if (and (or (not ido-require-match) | 2689 (if (and (or (not ido-require-match) |
2690 (if (memq ido-require-match '(confirm confirm-after-completion)) | |
2691 (if (or (eq ido-cur-item 'dir) | |
2692 (eq last-command this-command)) | |
2693 t | |
2694 (setq ido-show-confirm-message t) | |
2695 nil)) | |
2684 (ido-existing-item-p)) | 2696 (ido-existing-item-p)) |
2685 (not ido-incomplete-regexp)) | 2697 (not ido-incomplete-regexp)) |
2686 (exit-minibuffer))) | 2698 (exit-minibuffer))) |
2687 | 2699 |
2688 (defun ido-select-text () | 2700 (defun ido-select-text () |
4396 (let ((inf (ido-completions | 4408 (let ((inf (ido-completions |
4397 contents | 4409 contents |
4398 minibuffer-completion-table | 4410 minibuffer-completion-table |
4399 minibuffer-completion-predicate | 4411 minibuffer-completion-predicate |
4400 (not minibuffer-completion-confirm)))) | 4412 (not minibuffer-completion-confirm)))) |
4413 (setq ido-show-confirm-message nil) | |
4401 (ido-trace "inf" inf) | 4414 (ido-trace "inf" inf) |
4402 (insert inf)) | 4415 (insert inf)) |
4403 )))) | 4416 )))) |
4404 | 4417 |
4405 (defun ido-completions (name candidates predicate require-match) | 4418 (defun ido-completions (name candidates predicate require-match) |
4428 (if ind (setq first (concat first ind))) | 4441 (if ind (setq first (concat first ind))) |
4429 (setq comps (cons first (cdr comps))))) | 4442 (setq comps (cons first (cdr comps))))) |
4430 | 4443 |
4431 (cond ((null comps) | 4444 (cond ((null comps) |
4432 (cond | 4445 (cond |
4446 (ido-show-confirm-message | |
4447 (or (nth 11 ido-decorations) " [Confirm]")) | |
4433 (ido-directory-nonreadable | 4448 (ido-directory-nonreadable |
4434 (or (nth 8 ido-decorations) " [Not readable]")) | 4449 (or (nth 8 ido-decorations) " [Not readable]")) |
4435 (ido-directory-too-big | 4450 (ido-directory-too-big |
4436 (or (nth 9 ido-decorations) " [Too big]")) | 4451 (or (nth 9 ido-decorations) " [Too big]")) |
4437 (ido-report-no-match | 4452 (ido-report-no-match |