]> git.eshelyaron.com Git - emacs.git/commitdiff
Define and use `completion-table-merge'
authorDmitry Gutov <dgutov@yandex.ru>
Thu, 6 Feb 2014 01:22:38 +0000 (03:22 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Thu, 6 Feb 2014 01:22:38 +0000 (03:22 +0200)
* lisp/minibuffer.el (completion-table-merge): New function.

* lisp/emacs-lisp/lisp.el (lisp-completion-at-point): Use
`completion-table-merge' instead of `completion-table-in-turn'.

Fixes: debbugs:16604
doc/lispref/minibuf.texi
etc/NEWS
lisp/ChangeLog
lisp/emacs-lisp/lisp.el
lisp/minibuffer.el

index e32922eef689434b7137fbc3a6512ebed77aed94..df510862460c5a6559740b4d3b83a6510d0a67b9 100644 (file)
@@ -889,6 +889,7 @@ Here is an example:
 @c FIXME?  completion-table-with-context?
 @findex completion-table-case-fold
 @findex completion-table-in-turn
+@findex completion-table-merge
 @findex completion-table-subvert
 @findex completion-table-with-quoting
 @findex completion-table-with-predicate
@@ -897,9 +898,10 @@ Here is an example:
 @cindex completion tables, combining
 There are several functions that take an existing completion table and
 return a modified version.  @code{completion-table-case-fold} returns
-a case-insensitive table.  @code{completion-table-in-turn} combines
-multiple input tables.  @code{completion-table-subvert} alters a table
-to use a different initial prefix.  @code{completion-table-with-quoting}
+a case-insensitive table.  @code{completion-table-in-turn} and
+@code{completion-table-merge} combine multiple input tables in
+different ways.  @code{completion-table-subvert} alters a table to use
+a different initial prefix.  @code{completion-table-with-quoting}
 returns a table suitable for operating on quoted text.
 @code{completion-table-with-predicate} filters a table with a
 predicate function.  @code{completion-table-with-terminator} adds a
index 08b07aa86edce7f02661e84cdfa12d6b25c61986..bcbab2edf00cef497e933e7920731d9ccf24dabf 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2200,6 +2200,12 @@ in the presence of quoting, such as file completion in shell buffers.
 *** New function `completion-table-subvert' to use an existing completion
 table, but with a different prefix.
 
+*** New function `completion-table-with-cache' is a wrapper for
+`completion-table-dynamic' that caches the result of the last lookup.
+
+*** New function `completion-table-merge' to combine several
+completion tables by merging their completions.
+
 ** Debugger
 
 *** New error type and new function `user-error'.
index 5ce9ab4913c3edb11225e7e6f6f188208ed8d30c..571f9547279b9468a5072bc137a2e15d696c795d 100644 (file)
@@ -1,3 +1,11 @@
+2014-02-06  Dmitry Gutov  <dgutov@yandex.ru>
+
+       * emacs-lisp/lisp.el (lisp-completion-at-point): Use
+       `completion-table-merge' instead of `completion-table-in-turn'
+       (bug#16604).
+
+       * minibuffer.el (completion-table-merge): New function.
+
 2014-02-05  Michael Albinus  <michael.albinus@gmx.de>
 
        * net/tramp-sh.el (tramp-end-of-heredoc): New defconst.
index 3ff4f64d24cb33831e22c00d4db2d69767c0eb19..716df8a4cca527f00313572d82edde4e895cfae1 100644 (file)
@@ -830,7 +830,7 @@ considered."
                 ;; use it to provide a more specific completion table in some
                 ;; cases.  E.g. filter out keywords that are not understood by
                 ;; the macro/function being called.
-                (list nil (completion-table-in-turn
+                (list nil (completion-table-merge
                            lisp--local-variables-completion-table
                            obarray)       ;Could be anything.
                       :annotation-function
index c87fcc1c3ea4356a2fce80bc6e5bd90416b6bc4e..105075524bf7245002ed16e50cd44caafd478fc0 100644 (file)
@@ -388,11 +388,37 @@ Note: TABLE needs to be a proper completion table which obeys predicates."
   "Create a completion table that tries each table in TABLES in turn."
   ;; FIXME: the boundaries may come from TABLE1 even when the completion list
   ;; is returned by TABLE2 (because TABLE1 returned an empty list).
+  ;; Same potential problem if any of the tables use quoting.
   (lambda (string pred action)
     (completion--some (lambda (table)
                         (complete-with-action action table string pred))
                       tables)))
 
+(defun completion-table-merge (&rest tables)
+  "Create a completion table that collects completions from all TABLES."
+  ;; FIXME: same caveats as in `completion-table-in-turn'.
+  (lambda (string pred action)
+    (cond
+     ((null action)
+      (let ((retvals (mapcar (lambda (table)
+                               (try-completion string table pred))
+                             tables)))
+        (if (member string retvals)
+            string
+          (try-completion string
+                          (mapcar (lambda (value)
+                                    (if (eq value t) string value))
+                                  (delq nil retvals))
+                          pred))))
+     ((eq action t)
+      (apply #'append (mapcar (lambda (table)
+                                (all-completions string table pred))
+                              tables)))
+     (t
+      (completion--some (lambda (table)
+                          (complete-with-action action table string pred))
+                        tables)))))
+
 (defun completion-table-with-quoting (table unquote requote)
   ;; A difficult part of completion-with-quoting is to map positions in the
   ;; quoted string to equivalent positions in the unquoted string and