unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 16604@debbugs.gnu.org
Subject: bug#16604: 24.3.50; False negatives in lisp-completion-at-point
Date: Wed, 05 Feb 2014 06:41:14 +0200	[thread overview]
Message-ID: <52F1C0EA.9090406@yandex.ru> (raw)
In-Reply-To: <jwv38jyvksm.fsf-monnier+emacsbugs@gnu.org>

On 04.02.2014 19:54, Stefan Monnier wrote:
> I was thinking of a new property which would define a function which
> reduces the set of candidates considered for
> completion-try-completions.  File completion could use it to implement
> completion-ignored-extensions and we could use it here to prefer
> a local varname.

An approach that would work for completion-at-point, but wouldn't touch 
compan-capf? Sounds promising, though out of scope for this bug.

> We don't want to do those checks all the time, so it should probably be
> done only once when we combine the two tables (if possible)

`completion-metadata' requires both input string and a predicate (I 
guess, for maximum flexibility of functional completion tables). Pass it 
an empty string and a nil?

And completion boundaries requires suffix as an input. I guess we could 
see if the table supports boundaries at all by passing an empty string, 
and if so, raise an error (ignoring the possibility that the table 
supports only a certain set of suffixes). In that case, we'd be breaking 
support for merging tables that define boundaries, but are known by the 
caller to return identical ones. Which could be useful, I guess.

> or not at all.

Sounds good to me.

> Sounds like a bug in lisp-completion-at-point.

See http://debbugs.gnu.org/16646.

>> +      (let ((retvals (mapcar (lambda (table)
>> +                               (try-completion string table pred))
>> +                             tables))
>> +            (prelim (try-completion string retvals pred)))
>
> try-completion's behavior when passed a list mixing strings and symbols
> is not really defined.  So this second call to `try-completion' relies
> on largely undocumented behavior.  Two solutions: either you add
> a comment about what behavior you assume, or you change the code to
> avoid this problem.
>
> E.g. change retvals with (delq nil ...) and replace t with `string'.

Sure, thanks for catching this.


=== 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-05 04:38:11 +0000
@@ -388,11 +388,38 @@
    "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', only harder
+  ;; to fix.
+  (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







  reply	other threads:[~2014-02-05  4:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-31  4:46 bug#16604: 24.3.50; False negatives in lisp-completion-at-point Dmitry Gutov
2014-01-31 14:34 ` Stefan Monnier
2014-01-31 14:37   ` Dmitry Gutov
2014-01-31 15:05   ` Thierry Volpiatto
2014-02-02  1:52   ` Dmitry Gutov
2014-02-02  2:39     ` Stefan Monnier
2014-02-02  3:00       ` Dmitry Gutov
2014-02-02 14:12         ` Stefan Monnier
2014-02-02 18:24           ` Stefan Monnier
2014-02-03  2:03             ` Stefan Monnier
2014-02-03  3:48               ` Stefan Monnier
2014-02-04  5:37             ` Dmitry Gutov
2014-02-04 17:54               ` Stefan Monnier
2014-02-05  4:41                 ` Dmitry Gutov [this message]
2014-02-05 13:53                   ` Stefan Monnier
2014-02-06  1:38                     ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52F1C0EA.9090406@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=16604@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).