emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r111031: * lisp/icomplete.el: Change


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111031: * lisp/icomplete.el: Change separator; add ido-style commands.
Date: Thu, 29 Nov 2012 16:32:24 -0500
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111031
author: Jambunathan K <address@hidden>
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Thu 2012-11-29 16:32:24 -0500
message:
  * lisp/icomplete.el: Change separator; add ido-style commands.
  (icomplete-show-key-bindings): Remove custom var.
  (icomplete-get-keys): Remove function.
  (icomplete-forward-completions, icomplete-backward-completions):
  New commands.
  (icomplete-minibuffer-map): New var.
  (icomplete-minibuffer-setup): Use it.
  (icomplete-exhibit): Don't delay if the list of completions is known.
  (icomplete-separator): New custom.
  (icomplete-completions): Use it.
  * lisp/minibuffer.el (completion-all-sorted-completions): Delete duplicates.
  (minibuffer-force-complete-and-exit): New command.
  (minibuffer--complete-and-exit): New function extracted from
  minibuffer-complete-and-exit.
  (minibuffer-complete-and-exit): Use it.
modified:
  etc/NEWS
  lisp/ChangeLog
  lisp/icomplete.el
  lisp/minibuffer.el
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2012-11-25 18:33:16 +0000
+++ b/etc/NEWS  2012-11-29 21:32:24 +0000
@@ -29,6 +29,10 @@
 
 * Changes in Specialized Modes and Packages in Emacs 24.4
 
+** Icomplete is a bit more like IDO.
+*** key bindings to navigate through and select the completions.
+*** The icomplete-separator is customizable, and its default has changed.
+*** Removed icomplete-show-key-bindings.
 ** Calc
 
 *** Calc by default now uses the Gregorian calendar for all dates, and

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-11-29 20:19:11 +0000
+++ b/lisp/ChangeLog    2012-11-29 21:32:24 +0000
@@ -1,4 +1,21 @@
-2012-11-29  Stefan Monnier  <address@hidden>
+2012-11-29  Jambunathan K  <address@hidden>
+            Stefan Monnier  <address@hidden>
+
+       * icomplete.el: Change separator; add ido-style commands.
+       (icomplete-show-key-bindings): Remove custom var.
+       (icomplete-get-keys): Remove function.
+       (icomplete-forward-completions, icomplete-backward-completions):
+       New commands.
+       (icomplete-minibuffer-map): New var.
+       (icomplete-minibuffer-setup): Use it.
+       (icomplete-exhibit): Don't delay if the list of completions is known.
+       (icomplete-separator): New custom.
+       (icomplete-completions): Use it.
+       * minibuffer.el (completion-all-sorted-completions): Delete duplicates.
+       (minibuffer-force-complete-and-exit): New command.
+       (minibuffer--complete-and-exit): New function extracted from
+       minibuffer-complete-and-exit.
+       (minibuffer-complete-and-exit): Use it.
 
        * progmodes/etags.el (visit-tags-table-buffer): Give a more precise
        error message when the file doesn't exist (bug#12974).

=== modified file 'lisp/icomplete.el'
--- a/lisp/icomplete.el 2012-06-22 17:37:28 +0000
+++ b/lisp/icomplete.el 2012-11-29 21:32:24 +0000
@@ -71,6 +71,11 @@
 (make-obsolete-variable
  'icomplete-prospects-length 'icomplete-prospects-height "23.1")
 
+(defcustom icomplete-separator " | "
+  "String used by icomplete to separate alternatives in the minibuffer."
+  :type 'string
+  :version "24.3")
+
 ;;;_* User Customization variables
 (defcustom icomplete-prospects-height
   ;; 20 is an estimated common size for the prompt + minibuffer content, to
@@ -97,11 +102,6 @@
   :type 'integer
   :group 'icomplete)
 
-(defcustom icomplete-show-key-bindings t
-  "If non-nil, show key bindings as well as completion for sole matches."
-  :type 'boolean
-  :group 'icomplete)
-
 (defcustom icomplete-minibuffer-setup-hook nil
   "Icomplete-specific customization of minibuffer setup.
 
@@ -145,23 +145,6 @@
 minibuffer completion.")
 (add-hook 'icomplete-post-command-hook 'icomplete-exhibit)
 
-(defun icomplete-get-keys (func-name)
-  "Return strings naming keys bound to FUNC-NAME, or nil if none.
-Examines the prior, not current, buffer, presuming that current buffer
-is minibuffer."
-  (when (commandp func-name)
-    (save-excursion
-      (let* ((sym (intern func-name))
-            (buf (other-buffer nil t))
-            (keys (with-current-buffer buf (where-is-internal sym))))
-       (when keys
-         (concat "<"
-                 (mapconcat 'key-description
-                            (sort keys
-                                  #'(lambda (x y)
-                                      (< (length x) (length y))))
-                            ", ")
-                 ">"))))))
 ;;;_  = icomplete-with-completion-tables
 (defvar icomplete-with-completion-tables '(internal-complete-buffer)
   "Specialized completion tables with which icomplete should operate.
@@ -169,6 +152,37 @@
 Icomplete does not operate with any specialized completion tables
 except those on this list.")
 
+(defvar icomplete-minibuffer-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map [?\M-\t] 'minibuffer-force-complete)
+    (define-key map [?\C-j]  'minibuffer-force-complete-and-exit)
+    (define-key map [?\C-s]  'icomplete-forward-completions)
+    (define-key map [?\C-r]  'icomplete-backward-completions)
+    map))
+
+(defun icomplete-forward-completions ()
+  "Step forward completions by one entry.
+Second entry becomes the first and can be selected with
+`minibuffer-force-complete-and-exit'."
+  (interactive)
+  (let* ((comps (completion-all-sorted-completions))
+        (last (last comps)))
+    (setcdr last (cons (car comps) (cdr last)))
+    (completion--cache-all-sorted-completions (cdr comps))))
+
+(defun icomplete-backward-completions ()
+  "Step backward completions by one entry.
+Last entry becomes the first and can be selected with
+`minibuffer-force-complete-and-exit'."
+  (interactive)
+  (let* ((comps (completion-all-sorted-completions))
+        (last-but-one (last comps 2))
+        (last (cdr last-but-one)))
+    (when last
+      (setcdr last-but-one (cdr last))
+      (push (car last) comps)
+      (completion--cache-all-sorted-completions comps))))
+
 ;;;_ > icomplete-mode (&optional prefix)
 ;;;###autoload
 (define-minor-mode icomplete-mode
@@ -208,6 +222,8 @@
 Usually run by inclusion in `minibuffer-setup-hook'."
   (when (and icomplete-mode (icomplete-simple-completing-p))
     (set (make-local-variable 'completion-show-inline-help) nil)
+    (use-local-map (make-composed-keymap icomplete-minibuffer-map
+                                        (current-local-map)))
     (add-hook 'pre-command-hook
              (lambda () (let ((non-essential t))
                       (run-hooks 'icomplete-pre-command-hook)))
@@ -239,27 +255,29 @@
       (goto-char (point-max))
                                         ; Insert the match-status information:
       (if (and (> (point-max) (minibuffer-prompt-end))
-              buffer-undo-list         ; Wait for some user input.
-              (or
-               ;; Don't bother with delay after certain number of chars:
-               (> (- (point) (field-beginning)) icomplete-max-delay-chars)
-               ;; Don't delay if alternatives number is small enough:
-               (and (sequencep minibuffer-completion-table)
-                    (< (length minibuffer-completion-table)
-                       icomplete-delay-completions-threshold))
-               ;; Delay - give some grace time for next keystroke, before
+               buffer-undo-list         ; Wait for some user input.
+               (or
+                ;; Don't bother with delay after certain number of chars:
+                (> (- (point) (field-beginning)) icomplete-max-delay-chars)
+                ;; Don't delay if the completions are known.
+                completion-all-sorted-completions
+                ;; Don't delay if alternatives number is small enough:
+                (and (sequencep minibuffer-completion-table)
+                     (< (length minibuffer-completion-table)
+                        icomplete-delay-completions-threshold))
+                ;; Delay - give some grace time for next keystroke, before
                ;; embarking on computing completions:
                (sit-for icomplete-compute-delay)))
          (let ((text (while-no-input
-                        (icomplete-completions
-                         (field-string)
-                         minibuffer-completion-table
-                         minibuffer-completion-predicate
+                        (icomplete-completions
+                         (field-string)
+                         minibuffer-completion-table
+                         minibuffer-completion-predicate
                          (not minibuffer-completion-confirm))))
                (buffer-undo-list t)
                deactivate-mark)
            ;; Do nothing if while-no-input was aborted.
-           (when (stringp text)
+            (when (stringp text)
               (move-overlay icomplete-overlay (point) (point) (current-buffer))
               ;; The current C cursor code doesn't know to use the overlay's
               ;; marker's stickiness to figure out whether to place the cursor
@@ -365,17 +383,14 @@
        (if prospects
            (concat determ
                    "{"
-                   (and most-is-exact ",")
-                   (mapconcat 'identity (nreverse prospects) ",")
-                   (and limit ",...")
+                   (and most-is-exact
+                         (substring icomplete-separator
+                                    (string-match "[^ ]" icomplete-separator)))
+                   (mapconcat 'identity (nreverse prospects)
+                               icomplete-separator)
+                   (and limit (concat icomplete-separator "…"))
                    "}")
-         (concat determ
-                 " [Matched"
-                 (let ((keys (and icomplete-show-key-bindings
-                                  (commandp (intern-soft most))
-                                  (icomplete-get-keys most))))
-                   (if keys (concat "; " keys) ""))
-                 "]"))))))
+         (concat determ " [Matched]"))))))
 
 ;;_* Local emacs vars.
 ;;Local variables:

=== modified file 'lisp/minibuffer.el'
--- a/lisp/minibuffer.el        2012-11-08 15:10:08 +0000
+++ b/lisp/minibuffer.el        2012-11-29 21:32:24 +0000
@@ -1106,6 +1106,13 @@
              (sort-fun (completion-metadata-get all-md 'cycle-sort-function)))
         (when last
           (setcdr last nil)
+
+          ;; Delete duplicates: do it after setting last's cdr to nil (so
+          ;; it's a proper list), and be careful to reset `last' since it
+          ;; may be a different cons-cell.
+          (setq all (delete-dups all))
+          (setq last (last all))
+
           (setq all (if sort-fun (funcall sort-fun all)
                       ;; Prefer shorter completions, by default.
                       (sort all (lambda (c1 c2) (< (length c1) (length c2))))))
@@ -1120,6 +1127,15 @@
           ;; all possibilities.
           (completion--cache-all-sorted-completions (nconc all base-size))))))
 
+(defun minibuffer-force-complete-and-exit ()
+  "Complete the minibuffer with first of the matches and exit."
+  (interactive)
+  (minibuffer-force-complete)
+  (minibuffer--complete-and-exit
+   ;; If the previous completion completed to an element which fails
+   ;; test-completion, then we shouldn't exit, but that should be rare.
+   (lambda () (minibuffer-message "Incomplete"))))
+
 (defun minibuffer-force-complete ()
   "Complete the minibuffer to an exact match.
 Repeated uses step through the possible completions."
@@ -1192,6 +1208,22 @@
  `minibuffer-confirm-exit-commands', and accept the input
  otherwise."
   (interactive)
+  (minibuffer--complete-and-exit
+   (lambda ()
+     (pcase (condition-case nil
+                (completion--do-completion nil 'expect-exact)
+              (error 1))
+       ((or #b001 #b011) (exit-minibuffer))
+       (#b111 (if (not minibuffer-completion-confirm)
+                  (exit-minibuffer)
+                (minibuffer-message "Confirm")
+                nil))
+       (_ nil)))))
+
+(defun minibuffer--complete-and-exit (completion-function)
+  "Exit from `require-match' minibuffer.
+COMPLETION-FUNCTION is called if the current buffer's content does not
+appear to be a match."
   (let ((beg (field-beginning))
         (end (field-end)))
     (cond
@@ -1239,15 +1271,7 @@
 
      (t
       ;; Call do-completion, but ignore errors.
-      (pcase (condition-case nil
-                (completion--do-completion nil 'expect-exact)
-              (error 1))
-        ((or #b001 #b011) (exit-minibuffer))
-        (#b111 (if (not minibuffer-completion-confirm)
-                   (exit-minibuffer)
-                 (minibuffer-message "Confirm")
-                 nil))
-        (_ nil))))))
+      (funcall completion-function)))))
 
 (defun completion--try-word-completion (string table predicate point md)
   (let ((comp (completion-try-completion string table predicate point md)))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]