aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2010-05-11 20:39:46 -0400
committerStefan Monnier2010-05-11 20:39:46 -0400
commit902a6d8d73e416ca25e2d9382479e6a78c3a8a44 (patch)
tree837eed1b6d968daf9da79a9260611b4361621dbb
parent9ee120ba0118e977e5b7fa78123af6c765002b99 (diff)
downloademacs-902a6d8d73e416ca25e2d9382479e6a78c3a8a44.tar.gz
emacs-902a6d8d73e416ca25e2d9382479e6a78c3a8a44.zip
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.
-rw-r--r--etc/NEWS2
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/minibuffer.el69
3 files changed, 67 insertions, 10 deletions
diff --git a/etc/NEWS b/etc/NEWS
index d20a87e76e9..c4393a53efe 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -43,6 +43,8 @@ You can disable this by using --without-selinux.
43 43
44* Changes in Emacs 24.1 44* Changes in Emacs 24.1
45 45
46** Completion can cycle, depending on completion-cycle-threshold.
47
46** auto-mode-case-fold is now enabled by default. 48** auto-mode-case-fold is now enabled by default.
47 49
48+++ 50+++
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e7d4150450b..e0cbf007771 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12010-05-12 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * minibuffer.el (completion-cycle-threshold): New custom var.
4 (completion--do-completion): Use it.
5 (minibuffer-complete): Use cycling if appropriate.
6
12010-05-11 Juanma Barranquero <lekktu@gmail.com> 72010-05-11 Juanma Barranquero <lekktu@gmail.com>
2 8
3 * dirtrack.el (dirtrackp): Remove defcustom; don't make automatically 9 * dirtrack.el (dirtrackp): Remove defcustom; don't make automatically
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 2f27cd0d40e..b1ecae3801d 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -76,6 +76,9 @@
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.
@@ -489,6 +492,18 @@ Moves point to the end of the new text."
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.
497Depending on this setting `minibuffer-complete' may use cycling,
498like `minibuffer-force-complete'.
499If nil, cycling is never used.
500If t, cycling is always used.
501If an integer, cycling is used as soon as there are fewer completion
502candidates 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.
494M = completion was performed, the text was Modified. 509M = completion was performed, the text was Modified.
@@ -548,14 +563,43 @@ E = after completion we now have an Exact match.
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))
@@ -566,7 +610,7 @@ E = after completion we now have an Exact match.
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
@@ -580,21 +624,26 @@ scroll the window of possible completions."
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)