changeset 108251:275d802c8570

Extract common suffix for * in partial-completion. * minibuffer.el (completion--sreverse, completion--common-suffix): New functions. (completion-pcm--merge-completions): Extract common suffix when safe.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 05 May 2010 22:59:07 -0400
parents 2fb37c89f2f7
children 623b349bb7c2 7d3e117cb7a7
files lisp/ChangeLog lisp/minibuffer.el
diffstat 2 files changed, 26 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Wed May 05 22:53:56 2010 -0400
+++ b/lisp/ChangeLog	Wed May 05 22:59:07 2010 -0400
@@ -1,5 +1,9 @@
 2010-05-06  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+	* minibuffer.el (completion--sreverse, completion--common-suffix):
+	New functions.
+	(completion-pcm--merge-completions): Extract common suffix when safe.
+
 	* emacs-lisp/easy-mmode.el (define-minor-mode):
 	Make :variable more flexible.
 	* files.el (auto-save-mode): Use it to define using define-minor-mode.
--- a/lisp/minibuffer.el	Wed May 05 22:53:56 2010 -0400
+++ b/lisp/minibuffer.el	Wed May 05 22:59:07 2010 -0400
@@ -1983,6 +1983,17 @@
       (nconc (completion-pcm--hilit-commonality pattern all)
              (length prefix)))))
 
+(defun completion--sreverse (str)
+  "Like `reverse' but for a string STR rather than a list."
+  (apply 'string (nreverse (mapcar 'identity str))))
+
+(defun completion--common-suffix (strs)
+  "Return the common suffix of the strings STRS."
+  (completion--sreverse
+   (try-completion
+    ""
+    (mapcar 'completion--sreverse comps))))
+
 (defun completion-pcm--merge-completions (strs pattern)
   "Extract the commonality in STRS, with the help of PATTERN."
   ;; When completing while ignoring case, we want to try and avoid
@@ -2044,7 +2055,17 @@
                 ;; `any' into a `star' because the surrounding context has
                 ;; changed such that string->pattern wouldn't add an `any'
                 ;; here any more.
-                (unless unique (push elem res))
+                (unless unique
+                  (push elem res)
+                  (when (memq elem '(star point))
+                    ;; Extract common suffix additionally to common prefix.
+                    ;; Only do it for `point' and `star' since for
+                    ;; `any' it could lead to a merged completion that
+                    ;; doesn't itself match the candidates.
+                    (let ((suffix (completion--common-suffix comps)))
+                      (assert (stringp suffix))
+                      (unless (equal suffix "")
+                        (push suffix res)))))
                 (setq fixed "")))))
         ;; We return it in reverse order.
         res)))))