]> code.delx.au - gnu-emacs/commitdiff
Extract common suffix for * in partial-completion.
authorStefan Monnier <monnier@iro.umontreal.ca>
Thu, 6 May 2010 02:59:07 +0000 (22:59 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Thu, 6 May 2010 02:59:07 +0000 (22:59 -0400)
* minibuffer.el (completion--sreverse, completion--common-suffix):
New functions.
(completion-pcm--merge-completions): Extract common suffix when safe.

lisp/ChangeLog
lisp/minibuffer.el

index 88c41ea84c270a40fda76c65a0e7a98dad9b7c00..97a0f8c5b41db4fca33712543101ac76ad536e06 100644 (file)
@@ -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.
index d8f1f0a8e9d63b32d0d2bca1f6ee13acdd0117b2..31bdb6993fa6d37d57e3e45721d73a31799f5c29 100644 (file)
@@ -1983,6 +1983,17 @@ filter out additional entries (because TABLE migth not obey PRED)."
       (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 @@ filter out additional entries (because TABLE migth not obey PRED)."
                 ;; `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)))))