Mercurial > emacs
comparison lisp/minibuffer.el @ 108500:9f927f4deab4
Allow the default completion to cycle.
* minibuffer.el (completion-cycle-threshold): New custom var.
(completion--do-completion): Use it.
(minibuffer-complete): Use cycling if appropriate.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 11 May 2010 20:39:46 -0400 |
parents | 7b8ec1ad0223 |
children | c8b4b7099b45 |
comparison
equal
deleted
inserted
replaced
108499:ffe7f17f895f | 108500:9f927f4deab4 |
---|---|
74 ;; - indicate that `all-completions' doesn't do prefix-completion | 74 ;; - indicate that `all-completions' doesn't do prefix-completion |
75 ;; but just returns some list that relates in some other way to | 75 ;; but just returns some list that relates in some other way to |
76 ;; the provided string (as is the case in filecache.el), in which | 76 ;; the provided string (as is the case in filecache.el), in which |
77 ;; case partial-completion (for example) doesn't make any sense | 77 ;; case partial-completion (for example) doesn't make any sense |
78 ;; and neither does the completions-first-difference highlight. | 78 ;; and neither does the completions-first-difference highlight. |
79 ;; - indicate how to display the completions in *Completions* (turn | |
80 ;; \n into something else, add special boundaries between | |
81 ;; completions). E.g. when completing from the kill-ring. | |
79 | 82 |
80 ;; - make partial-completion-mode obsolete: | 83 ;; - make partial-completion-mode obsolete: |
81 ;; - (?) <foo.h> style completion for file names. | 84 ;; - (?) <foo.h> style completion for file names. |
82 ;; This can't be done identically just by tweaking completion, | 85 ;; This can't be done identically just by tweaking completion, |
83 ;; because partial-completion-mode's behavior is to expand <string.h> | 86 ;; because partial-completion-mode's behavior is to expand <string.h> |
487 ;; after-change-functions that may themselves modify the buffer. | 490 ;; after-change-functions that may themselves modify the buffer. |
488 (goto-char beg) | 491 (goto-char beg) |
489 (insert newtext) | 492 (insert newtext) |
490 (delete-region (point) (+ (point) (- end beg)))) | 493 (delete-region (point) (+ (point) (- end beg)))) |
491 | 494 |
495 (defcustom completion-cycle-threshold nil | |
496 "Number of completion candidates below which cycling is used. | |
497 Depending on this setting `minibuffer-complete' may use cycling, | |
498 like `minibuffer-force-complete'. | |
499 If nil, cycling is never used. | |
500 If t, cycling is always used. | |
501 If an integer, cycling is used as soon as there are fewer completion | |
502 candidates than this number." | |
503 :type '(choice (const :tag "No cycling" nil) | |
504 (const :tag "Always cycle" t) | |
505 (integer :tag "Threshold"))) | |
506 | |
492 (defun completion--do-completion (&optional try-completion-function) | 507 (defun completion--do-completion (&optional try-completion-function) |
493 "Do the completion and return a summary of what happened. | 508 "Do the completion and return a summary of what happened. |
494 M = completion was performed, the text was Modified. | 509 M = completion was performed, the text was Modified. |
495 C = there were available Completions. | 510 C = there were available Completions. |
496 E = after completion we now have an Exact match. | 511 E = after completion we now have an Exact match. |
546 (completion--do-completion try-completion-function) | 561 (completion--do-completion try-completion-function) |
547 | 562 |
548 ;; It did find a match. Do we match some possibility exactly now? | 563 ;; It did find a match. Do we match some possibility exactly now? |
549 (let ((exact (test-completion completion | 564 (let ((exact (test-completion completion |
550 minibuffer-completion-table | 565 minibuffer-completion-table |
551 minibuffer-completion-predicate))) | 566 minibuffer-completion-predicate)) |
552 (if completed | 567 (comps |
568 ;; Check to see if we want to do cycling. We do it | |
569 ;; here, after having performed the normal completion, | |
570 ;; so as to take advantage of the difference between | |
571 ;; try-completion and all-completions, for things | |
572 ;; like completion-ignored-extensions. | |
573 (when (and completion-cycle-threshold | |
574 ;; Check that the completion didn't make | |
575 ;; us jump to a different boundary. | |
576 (or (not completed) | |
577 (< (car (completion-boundaries | |
578 (substring completion 0 comp-pos) | |
579 minibuffer-completion-table | |
580 minibuffer-completion-predicate | |
581 "")) | |
582 comp-pos))) | |
583 (completion-all-sorted-completions)))) | |
584 (setq completion-all-sorted-completions nil) | |
585 (cond | |
586 ((and (not (ignore-errors | |
587 ;; This signal an (intended) error if comps is too | |
588 ;; short or if completion-cycle-threshold is t. | |
589 (consp (nthcdr completion-cycle-threshold comps)))) | |
590 ;; More than 1, so there's something to cycle. | |
591 (consp (cdr comps))) | |
592 ;; Fewer than completion-cycle-threshold remaining | |
593 ;; completions: let's cycle. | |
594 (setq completed t exact t) | |
595 (setq completion-all-sorted-completions comps) | |
596 (minibuffer-force-complete)) | |
597 (completed | |
553 ;; We could also decide to refresh the completions, | 598 ;; We could also decide to refresh the completions, |
554 ;; if they're displayed (and assuming there are | 599 ;; if they're displayed (and assuming there are |
555 ;; completions left). | 600 ;; completions left). |
556 (minibuffer-hide-completions) | 601 (minibuffer-hide-completions)) |
557 ;; Show the completion table, if requested. | 602 ;; Show the completion table, if requested. |
558 (cond | |
559 ((not exact) | 603 ((not exact) |
560 (if (case completion-auto-help | 604 (if (case completion-auto-help |
561 (lazy (eq this-command last-command)) | 605 (lazy (eq this-command last-command)) |
562 (t completion-auto-help)) | 606 (t completion-auto-help)) |
563 (minibuffer-completion-help) | 607 (minibuffer-completion-help) |
564 (minibuffer-message "Next char not unique"))) | 608 (minibuffer-message "Next char not unique"))) |
565 ;; If the last exact completion and this one were the same, it | 609 ;; If the last exact completion and this one were the same, it |
566 ;; means we've already given a "Next char not unique" message | 610 ;; means we've already given a "Next char not unique" message |
567 ;; and the user's hit TAB again, so now we give him help. | 611 ;; and the user's hit TAB again, so now we give him help. |
568 ((eq this-command last-command) | 612 ((eq this-command last-command) |
569 (if completion-auto-help (minibuffer-completion-help))))) | 613 (if completion-auto-help (minibuffer-completion-help)))) |
570 | 614 |
571 (minibuffer--bitset completed t exact)))))))) | 615 (minibuffer--bitset completed t exact)))))))) |
572 | 616 |
573 (defun minibuffer-complete () | 617 (defun minibuffer-complete () |
574 "Complete the minibuffer contents as far as possible. | 618 "Complete the minibuffer contents as far as possible. |
578 scroll the window of possible completions." | 622 scroll the window of possible completions." |
579 (interactive) | 623 (interactive) |
580 ;; If the previous command was not this, | 624 ;; If the previous command was not this, |
581 ;; mark the completion buffer obsolete. | 625 ;; mark the completion buffer obsolete. |
582 (unless (eq this-command last-command) | 626 (unless (eq this-command last-command) |
627 (setq completion-all-sorted-completions nil) | |
583 (setq minibuffer-scroll-window nil)) | 628 (setq minibuffer-scroll-window nil)) |
584 | 629 |
585 (let ((window minibuffer-scroll-window)) | 630 (cond |
586 ;; If there's a fresh completion window with a live buffer, | 631 ;; If there's a fresh completion window with a live buffer, |
587 ;; and this command is repeated, scroll that window. | 632 ;; and this command is repeated, scroll that window. |
588 (if (window-live-p window) | 633 ((window-live-p minibuffer-scroll-window) |
634 (let ((window minibuffer-scroll-window)) | |
589 (with-current-buffer (window-buffer window) | 635 (with-current-buffer (window-buffer window) |
590 (if (pos-visible-in-window-p (point-max) window) | 636 (if (pos-visible-in-window-p (point-max) window) |
591 ;; If end is in view, scroll up to the beginning. | 637 ;; If end is in view, scroll up to the beginning. |
592 (set-window-start window (point-min) nil) | 638 (set-window-start window (point-min) nil) |
593 ;; Else scroll down one screen. | 639 ;; Else scroll down one screen. |
594 (scroll-other-window)) | 640 (scroll-other-window)) |
595 nil) | 641 nil))) |
596 | 642 ;; If we're cycling, keep on cycling. |
597 (case (completion--do-completion) | 643 (completion-all-sorted-completions |
644 (minibuffer-force-complete) | |
645 t) | |
646 (t (case (completion--do-completion) | |
598 (#b000 nil) | 647 (#b000 nil) |
599 (#b001 (minibuffer-message "Sole completion") | 648 (#b001 (minibuffer-message "Sole completion") |
600 t) | 649 t) |
601 (#b011 (minibuffer-message "Complete, but not unique") | 650 (#b011 (minibuffer-message "Complete, but not unique") |
602 t) | 651 t) |