Subject: Re: bug#16604: 24.3.50; False negatives in lisp-completion-at-point

From: Dmitry Gutov <[email-masked]>
Date: Sun, 02 Feb 2014 03:52:30 +0200

Is it okay to install the following patch?

On a related note, company-capf returns nil to `duplicates', but with 
the patch below, for example, I do receive duplicates from it. And with 
another, functional completion table I wrote in a third-party package. 
Should I change `duplicates' to t?

=== modified file 'lisp/emacs-lisp/lisp.el'
--- lisp/emacs-lisp/lisp.el	2014-01-01 07:43:34 +0000
+++ lisp/emacs-lisp/lisp.el	2014-02-02 01:42:32 +0000
@@ -830,7 +830,7 @@
                  ;; 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

=== modified file 'lisp/minibuffer.el'
--- lisp/minibuffer.el	2014-01-07 23:36:29 +0000
+++ lisp/minibuffer.el	2014-02-02 01:46:41 +0000
@@ -393,6 +393,27 @@
                          (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 caveat as in `completion-table-in-turn', only harder
+  ;; to fix.
+  (lambda (string pred action)
+    (cond
+     ((null action)
+      (try-completion string
+                      (mapcar (lambda (table)
+                                (try-completion string table pred))
+                              tables)
+                      pred))
+     ((eq action t)
+      (apply #'append (mapcar (lambda (table)
+                                (all-completions string table pred))
+                              tables)))
+     ((not (or (eq (car-safe action) 'boundaries)
+               (eq action 'metadata)))
+      (completion--some (lambda (table) (test-completion string table 
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