From a333e4d29764e8f086a9fdeeb17c060a5d06d6dc Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Thu, 6 Feb 2014 03:22:38 +0200 Subject: [PATCH] Define and use `completion-table-merge' * 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 | 8 +++++--- etc/NEWS | 6 ++++++ lisp/ChangeLog | 8 ++++++++ lisp/emacs-lisp/lisp.el | 2 +- lisp/minibuffer.el | 26 ++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index e32922eef6..df51086246 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi @@ -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 diff --git a/etc/NEWS b/etc/NEWS index 08b07aa86e..bcbab2edf0 100644 --- 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'. diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5ce9ab4913..571f954727 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2014-02-06 Dmitry Gutov + + * 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 * net/tramp-sh.el (tramp-end-of-heredoc): New defconst. diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index 3ff4f64d24..716df8a4cc 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -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 diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index c87fcc1c3e..105075524b 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -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 -- 2.20.1