Mercurial > emacs
comparison lisp/minibuffer.el @ 106453:eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
minibuffer's content with itself.
Fold the confirm-after-completion case into the `confirm' case.
(completion-pcm-word-delimiters): Add : and / to the delimiters.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sun, 06 Dec 2009 01:25:41 +0000 |
parents | 4543cbad36da |
children | 806e9f7990d8 |
comparison
equal
deleted
inserted
replaced
106452:4543cbad36da | 106453:eaa5eba6d613 |
---|---|
55 ;; - minibuffer-force-complete completes ~/src/emacs/t<!>/lisp/minibuffer.el | 55 ;; - minibuffer-force-complete completes ~/src/emacs/t<!>/lisp/minibuffer.el |
56 ;; to ~/src/emacs/trunk/ and throws away lisp/minibuffer.el. | 56 ;; to ~/src/emacs/trunk/ and throws away lisp/minibuffer.el. |
57 | 57 |
58 ;;; Todo: | 58 ;;; Todo: |
59 | 59 |
60 ;; - make partial-complete-mode obsolete: | 60 ;; - extend `boundaries' to provide various other meta-data about the |
61 ;; output of `all-completions': | |
62 ;; - quoting/unquoting (so we can complete files names with envvars | |
63 ;; and backslashes, and all-completion can list names without | |
64 ;; quoting backslashes and dollars). | |
65 ;; - indicate how to turn all-completion's output into | |
66 ;; try-completion's output: e.g. completion-ignored-extensions. | |
67 ;; maybe that could be merged with the "quote" operation above. | |
68 ;; - completion hook to run when the completion is | |
69 ;; selected/inserted (maybe this should be provided some other | |
70 ;; way, e.g. as text-property, so `try-completion can also return it?) | |
71 ;; both for when it's inserted via TAB or via choose-completion. | |
72 ;; - indicate that `all-completions' doesn't do prefix-completion | |
73 ;; but just returns some list that relates in some other way to | |
74 ;; the provided string (as is the case in filecache.el), in which | |
75 ;; case partial-completion (for example) doesn't make any sense | |
76 ;; and neither does the completions-first-difference highlight. | |
77 | |
78 ;; - make partial-completion-mode obsolete: | |
61 ;; - (?) <foo.h> style completion for file names. | 79 ;; - (?) <foo.h> style completion for file names. |
62 ;; This can't be done identically just by tweaking completion, | 80 ;; This can't be done identically just by tweaking completion, |
63 ;; because partial-completion-mode's behavior is to expand <string.h> | 81 ;; because partial-completion-mode's behavior is to expand <string.h> |
64 ;; to /usr/include/string.h only when exiting the minibuffer, at which | 82 ;; to /usr/include/string.h only when exiting the minibuffer, at which |
65 ;; point the completion code is actually not involved normally. | 83 ;; point the completion code is actually not involved normally. |
412 "List the possible completions of STRING in completion table TABLE. | 430 "List the possible completions of STRING in completion table TABLE. |
413 Only the elements of table that satisfy predicate PRED are considered. | 431 Only the elements of table that satisfy predicate PRED are considered. |
414 POINT is the position of point within STRING. | 432 POINT is the position of point within STRING. |
415 The return value is a list of completions and may contain the base-size | 433 The return value is a list of completions and may contain the base-size |
416 in the last `cdr'." | 434 in the last `cdr'." |
417 ;; FIXME: We need to additionally return completion-extra-size (similar | 435 ;; FIXME: We need to additionally return the info needed for the |
418 ;; to completion-base-size but for the text after point). | 436 ;; second part of completion-base-position. |
419 (completion--some (lambda (style) | 437 (completion--some (lambda (style) |
420 (funcall (nth 2 (assq style completion-styles-alist)) | 438 (funcall (nth 2 (assq style completion-styles-alist)) |
421 string table pred point)) | 439 string table pred point)) |
422 completion-styles)) | 440 completion-styles)) |
423 | 441 |
624 ;; Allow user to specify null string | 642 ;; Allow user to specify null string |
625 ((= beg end) (exit-minibuffer)) | 643 ((= beg end) (exit-minibuffer)) |
626 ((test-completion (buffer-substring beg end) | 644 ((test-completion (buffer-substring beg end) |
627 minibuffer-completion-table | 645 minibuffer-completion-table |
628 minibuffer-completion-predicate) | 646 minibuffer-completion-predicate) |
647 ;; FIXME: completion-ignore-case has various slightly | |
648 ;; incompatible meanings. E.g. it can reflect whether the user | |
649 ;; wants completion to pay attention to case, or whether the | |
650 ;; string will be used in a context where case is significant. | |
651 ;; E.g. usually try-completion should obey the first, whereas | |
652 ;; test-completion should obey the second. | |
629 (when completion-ignore-case | 653 (when completion-ignore-case |
630 ;; Fixup case of the field, if necessary. | 654 ;; Fixup case of the field, if necessary. |
631 (let* ((string (buffer-substring beg end)) | 655 (let* ((string (buffer-substring beg end)) |
632 (compl (try-completion | 656 (compl (try-completion |
633 string | 657 string |
634 minibuffer-completion-table | 658 minibuffer-completion-table |
635 minibuffer-completion-predicate))) | 659 minibuffer-completion-predicate))) |
636 (when (and (stringp compl) | 660 (when (and (stringp compl) (not (equal string compl)) |
637 ;; If it weren't for this piece of paranoia, I'd replace | 661 ;; If it weren't for this piece of paranoia, I'd replace |
638 ;; the whole thing with a call to do-completion. | 662 ;; the whole thing with a call to do-completion. |
639 ;; This is important, e.g. when the current minibuffer's | 663 ;; This is important, e.g. when the current minibuffer's |
640 ;; content is a directory which only contains a single | 664 ;; content is a directory which only contains a single |
641 ;; file, so `try-completion' actually completes to | 665 ;; file, so `try-completion' actually completes to |
644 (goto-char end) | 668 (goto-char end) |
645 (insert compl) | 669 (insert compl) |
646 (delete-region beg end)))) | 670 (delete-region beg end)))) |
647 (exit-minibuffer)) | 671 (exit-minibuffer)) |
648 | 672 |
649 ((eq minibuffer-completion-confirm 'confirm) | 673 ((memq minibuffer-completion-confirm '(confirm confirm-after-completion)) |
650 ;; The user is permitted to exit with an input that's rejected | 674 ;; The user is permitted to exit with an input that's rejected |
651 ;; by test-completion, after confirming her choice. | 675 ;; by test-completion, after confirming her choice. |
652 (if (eq last-command this-command) | 676 (if (or (eq last-command this-command) |
677 ;; For `confirm-after-completion' we only ask for confirmation | |
678 ;; if trying to exit immediately after typing TAB (this | |
679 ;; catches most minibuffer typos). | |
680 (and (eq minibuffer-completion-confirm 'confirm-after-completion) | |
681 (not (memq last-command minibuffer-confirm-exit-commands)))) | |
653 (exit-minibuffer) | 682 (exit-minibuffer) |
654 (minibuffer-message "Confirm") | 683 (minibuffer-message "Confirm") |
655 nil)) | 684 nil)) |
656 | |
657 ((eq minibuffer-completion-confirm 'confirm-after-completion) | |
658 ;; Similar to the above, but only if trying to exit immediately | |
659 ;; after typing TAB (this catches most minibuffer typos). | |
660 (if (memq last-command minibuffer-confirm-exit-commands) | |
661 (progn (minibuffer-message "Confirm") | |
662 nil) | |
663 (exit-minibuffer))) | |
664 | 685 |
665 (t | 686 (t |
666 ;; Call do-completion, but ignore errors. | 687 ;; Call do-completion, but ignore errors. |
667 (case (condition-case nil | 688 (case (condition-case nil |
668 (completion--do-completion) | 689 (completion--do-completion) |
1078 | 1099 |
1079 (defun completion-in-region (start end collection &optional predicate) | 1100 (defun completion-in-region (start end collection &optional predicate) |
1080 "Complete the text between START and END using COLLECTION. | 1101 "Complete the text between START and END using COLLECTION. |
1081 Return nil if there is no valid completion, else t. | 1102 Return nil if there is no valid completion, else t. |
1082 Point needs to be somewhere between START and END." | 1103 Point needs to be somewhere between START and END." |
1083 ;; FIXME: some callers need to setup completion-ignore-case, | |
1084 ;; completion-ignored-extensions. The latter can be embedded in the | |
1085 ;; completion tables, but the first cannot (actually, maybe it should). | |
1086 (assert (<= start (point)) (<= (point) end)) | 1104 (assert (<= start (point)) (<= (point) end)) |
1087 ;; FIXME: undisplay the *Completions* buffer once the completion is done. | 1105 ;; FIXME: undisplay the *Completions* buffer once the completion is done. |
1088 (with-wrapper-hook | 1106 (with-wrapper-hook |
1089 completion-in-region-functions (start end collection predicate) | 1107 completion-in-region-functions (start end collection predicate) |
1090 (let ((minibuffer-completion-table collection) | 1108 (let ((minibuffer-completion-table collection) |
1245 ;; would require us to track the relationship between `str' and | 1263 ;; would require us to track the relationship between `str' and |
1246 ;; `string', which is difficult. And in any case, if | 1264 ;; `string', which is difficult. And in any case, if |
1247 ;; substitute-in-file-name turns "fo-$TO-ba" into "fo-o/b-ba", there's | 1265 ;; substitute-in-file-name turns "fo-$TO-ba" into "fo-o/b-ba", there's |
1248 ;; no way for us to return proper boundaries info, because the | 1266 ;; no way for us to return proper boundaries info, because the |
1249 ;; boundary is not (yet) in `string'. | 1267 ;; boundary is not (yet) in `string'. |
1268 ;; FIXME: Actually there is a way to return correct boundaries info, | |
1269 ;; at the condition of modifying the all-completions return accordingly. | |
1250 (let ((start (length (file-name-directory string))) | 1270 (let ((start (length (file-name-directory string))) |
1251 (end (string-match-p "/" (cdr action)))) | 1271 (end (string-match-p "/" (cdr action)))) |
1252 (list* 'boundaries start end))) | 1272 (list* 'boundaries start end))) |
1253 | 1273 |
1254 (t | 1274 (t |
1642 from lowercase to uppercase characters).") | 1662 from lowercase to uppercase characters).") |
1643 | 1663 |
1644 (defun completion-pcm--prepare-delim-re (delims) | 1664 (defun completion-pcm--prepare-delim-re (delims) |
1645 (setq completion-pcm--delim-wild-regex (concat "[" delims "*]"))) | 1665 (setq completion-pcm--delim-wild-regex (concat "[" delims "*]"))) |
1646 | 1666 |
1647 (defcustom completion-pcm-word-delimiters "-_. " | 1667 (defcustom completion-pcm-word-delimiters "-_./: " |
1648 "A string of characters treated as word delimiters for completion. | 1668 "A string of characters treated as word delimiters for completion. |
1649 Some arcane rules: | 1669 Some arcane rules: |
1650 If `]' is in this string, it must come first. | 1670 If `]' is in this string, it must come first. |
1651 If `^' is in this string, it must not come first. | 1671 If `^' is in this string, it must not come first. |
1652 If `-' is in this string, it must come first or right after `]'. | 1672 If `-' is in this string, it must come first or right after `]'. |