* bug#39600: [PATCH] Fix handling of non-exclusive non-prefix completion functions
@ 2020-02-14 7:34 Amai Kinono
2020-08-08 14:04 ` Lars Ingebrigtsen
0 siblings, 1 reply; 3+ messages in thread
From: Amai Kinono @ 2020-02-14 7:34 UTC (permalink / raw)
To: 39600
[-- Attachment #1.1: Type: text/plain, Size: 3025 bytes --]
# What does this fix?
Currently, with non-exclusive completion functions, Emacs will do
`try-completion` on the current text, and decide whether to try next
completion function based on that. This makes completion functions that
can do non-prefix completions fails when the current text only occurs in
the middle of the candidates. This is a problem I found in a FIXME in
the code.
# How does this work?
I use `completion-all-completions` instead. As far as I know, this
respects the `completion-styles`.
Here's a simple test. Eval this:
```
(require 'thingatpt)
(defun my-completion-at-point ()
(let* ((symbol (thing-at-point 'symbol))
(bounds (bounds-of-thing-at-point 'symbol)))
(list (car bounds) (cdr bounds)
'("gnuemacs" "xemacs" "uemacs")
:exclusive 'no)))
(setq completion-at-point-functions
'(my-completion-at-point elisp-completion-at-point))
(setq completion-styles '(substring))
```
Now type "emacs" and press `C-M-i`, the candidates defined in
`my-completion-at-point` will show up correctly. Now change
`completion-styles` to `(basic)`, and complete "emacs" again, it
fallbacks to `elisp-completion-at-point`.
# The patch
See the attachment. Since I don't know much about email, I'm not sure if
gmail's attachment is permanent, so I'll also paste the diff and commit
log here:
## Diff
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2244,18 +2244,11 @@ completion--capf-wrapper
(unless (member fun completion--capf-safe-funs)
(push fun completion--capf-safe-funs))
(and (eq 'no (plist-get (nthcdr 3 res) :exclusive))
- ;; FIXME: Here we'd need to decide whether there are
- ;; valid completions against the current text. But this
depends
- ;; on the actual completion UI (e.g. with the default
completion
- ;; it depends on completion-style) ;-(
- ;; We approximate this result by checking whether prefix
- ;; completion might work, which means that non-prefix
completion
- ;; will not work (or not right) for completion functions
that
- ;; are non-exclusive.
- (null (try-completion (buffer-substring-no-properties
- (car res) (point))
- (nth 2 res)
- (plist-get (nthcdr 3 res)
:predicate)))
+ (null (completion-all-completions
+ (buffer-substring-no-properties (car res) (point))
+ (nth 2 res)
+ (plist-get (nthcdr 3 res) :predicate)
+ (- (point) (car res))))
(setq res nil)))
((not (or (listp res) (functionp res)))
(unless (member fun completion--capf-misbehave-funs)
## Commit Log
Fix handling for non-exclusive non-prefix completion functions
* lisp/minibuffer.el (completion--capf-wrapper):
use completion-all-completions to do the test.
[-- Attachment #1.2: Type: text/html, Size: 3604 bytes --]
[-- Attachment #2: 0001-Fix-handling-for-non-exclusive-non-prefix-completion.patch --]
[-- Type: text/x-patch, Size: 2019 bytes --]
From 4dd4d58d56c111eb1ba482119c07134b85591747 Mon Sep 17 00:00:00 2001
From: AmaiKinono <amaikinono@gmail.com>
Date: Fri, 14 Feb 2020 14:52:55 +0800
Subject: [PATCH] Fix handling for non-exclusive non-prefix completion
functions
* lisp/minibuffer.el (completion--capf-wrapper):
use completion-all-completions to do the test.
---
lisp/minibuffer.el | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 49daabc..f811a5f 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2244,18 +2244,11 @@ completion--capf-wrapper
(unless (member fun completion--capf-safe-funs)
(push fun completion--capf-safe-funs))
(and (eq 'no (plist-get (nthcdr 3 res) :exclusive))
- ;; FIXME: Here we'd need to decide whether there are
- ;; valid completions against the current text. But this depends
- ;; on the actual completion UI (e.g. with the default completion
- ;; it depends on completion-style) ;-(
- ;; We approximate this result by checking whether prefix
- ;; completion might work, which means that non-prefix completion
- ;; will not work (or not right) for completion functions that
- ;; are non-exclusive.
- (null (try-completion (buffer-substring-no-properties
- (car res) (point))
- (nth 2 res)
- (plist-get (nthcdr 3 res) :predicate)))
+ (null (completion-all-completions
+ (buffer-substring-no-properties (car res) (point))
+ (nth 2 res)
+ (plist-get (nthcdr 3 res) :predicate)
+ (- (point) (car res))))
(setq res nil)))
((not (or (listp res) (functionp res)))
(unless (member fun completion--capf-misbehave-funs)
--
2.25.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#39600: [PATCH] Fix handling of non-exclusive non-prefix completion functions
2020-02-14 7:34 bug#39600: [PATCH] Fix handling of non-exclusive non-prefix completion functions Amai Kinono
@ 2020-08-08 14:04 ` Lars Ingebrigtsen
2020-08-08 21:58 ` Stefan Monnier
0 siblings, 1 reply; 3+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-08 14:04 UTC (permalink / raw)
To: Amai Kinono; +Cc: 39600, Stefan Monnier
Amai Kinono <amaikinono@gmail.com> writes:
> Currently, with non-exclusive completion functions, Emacs will do
> `try-completion` on the current text, and decide whether to try next
> completion function based on that. This makes completion functions that
> can do non-prefix completions fails when the current text only occurs in
> the middle of the candidates. This is a problem I found in a FIXME in
> the code.
>
> # How does this work?
>
> I use `completion-all-completions` instead. As far as I know, this
> respects the `completion-styles`.
[...]
Stefan, how does this patch look to you?
> - ;; FIXME: Here we'd need to decide whether there are
> - ;; valid completions against the current text. But this depends
> - ;; on the actual completion UI (e.g. with the default completion
> - ;; it depends on completion-style) ;-(
> - ;; We approximate this result by checking whether prefix
> - ;; completion might work, which means that non-prefix completion
> - ;; will not work (or not right) for completion functions that
> - ;; are non-exclusive.
> - (null (try-completion (buffer-substring-no-properties
> - (car res) (point))
> - (nth 2 res)
> - (plist-get (nthcdr 3 res) :predicate)))
> + (null (completion-all-completions
> + (buffer-substring-no-properties (car res) (point))
> + (nth 2 res)
> + (plist-get (nthcdr 3 res) :predicate)
> + (- (point) (car res))))
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#39600: [PATCH] Fix handling of non-exclusive non-prefix completion functions
2020-08-08 14:04 ` Lars Ingebrigtsen
@ 2020-08-08 21:58 ` Stefan Monnier
0 siblings, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2020-08-08 21:58 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 39600, Amai Kinono
>> Currently, with non-exclusive completion functions, Emacs will do
>> `try-completion` on the current text, and decide whether to try next
>> completion function based on that. This makes completion functions that
>> can do non-prefix completions fails when the current text only occurs in
>> the middle of the candidates. This is a problem I found in a FIXME in
>> the code.
>>
>> # How does this work?
>>
>> I use `completion-all-completions` instead. As far as I know, this
>> respects the `completion-styles`.
> [...]
> Stefan, how does this patch look to you?
I think it replaces one set of problems with another.
Within the completion-at-point-function we shouldn't call anything like
`try-completion`: we should only decide which completion table to use
but we shouldn't look inside those completion tables.
So a better solution is to build a new completion table which combines
(e.g. with `completion-table-in-turn`) the current one with that of "the
rest". [ The tricky (but still doable) case being when when the current
completion table and that of the rest don't use the same BEG and END. ]
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-08-08 21:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-14 7:34 bug#39600: [PATCH] Fix handling of non-exclusive non-prefix completion functions Amai Kinono
2020-08-08 14:04 ` Lars Ingebrigtsen
2020-08-08 21:58 ` Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.