From: Amai Kinono <amaikinono@gmail.com>
To: 39600@debbugs.gnu.org
Subject: bug#39600: [PATCH] Fix handling of non-exclusive non-prefix completion functions
Date: Fri, 14 Feb 2020 15:34:19 +0800 [thread overview]
Message-ID: <CAPu3fz2upooTeN7XmQt7q=W1FGxyk1pzaVqg+TQkEz7OnEYeaA@mail.gmail.com> (raw)
[-- 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
next reply other threads:[~2020-02-14 7:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-14 7:34 Amai Kinono [this message]
2020-08-08 14:04 ` bug#39600: [PATCH] Fix handling of non-exclusive non-prefix completion functions Lars Ingebrigtsen
2020-08-08 21:58 ` Stefan Monnier
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='CAPu3fz2upooTeN7XmQt7q=W1FGxyk1pzaVqg+TQkEz7OnEYeaA@mail.gmail.com' \
--to=amaikinono@gmail.com \
--cc=39600@debbugs.gnu.org \
/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).