* 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
@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
@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
*** 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'.
+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.
;; 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
"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