From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: [pcomplete.el (pcomplete-completions-at-point)] Why max?
Date: Tue, 19 Mar 2019 22:09:21 -0400 [thread overview]
Message-ID: <jwvh8bys4nz.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: CAN-HRFYUgcpWMiB1NR-CBBhVS9F5+OOh_qdRnmjP9E5VFLFudA@mail.gmail.com
> M-x shell
> cd /tmp
> mkdir AAAA\ BB\ CCCC
> cd AAAA\ BB<tab>
When I try this (with Emacs `master` but AFAIK this hasn't changed for
quite a while), I get the expected completion to
cd AAAA\ BB\ CCCC
what do you get instead?
> Autocomplete fails because (pcomplete-begin) returns the position of
> the first letter A but (length pcomplete-stub) is the length of "AAAA
> BB", which gives the position of the second letter A. The function
> `max', therefore, sets `beg' to the start of the second letter A.
> Consequently, file-name-completion will be asked to complete "AAA BB"
> instead of the correct one "AAAA BB".
The `completion-table-subvert` and `completion-table-with-quoting`
layers of the completion table are supposed to convert the "AAA\ BB" to
"AAAA BB" and back, so that file-name-completion should see neither
"AAAA\ BB" nor "AAA BB" but "AAAA BB" (which is indeed the string it
needs to do its job correctly).
> What do you think will break if `min' is used instead of `max' to
> repair the following problem seen using `emacs -Q' at the said commit?
To some extent the value of `beg` is not tremendously important because
of the `completion-table-subvert` layer, but there are cases where it
does make a difference. I can't offhand remember enough to tell you
which are those cases (IIRC it has to do with cases where completion
wants to change text *before* point, e.g. completing `em-li` to
`emacs-lisp` or /u/s/d to /usr/share/doc) so I can't quite remember when
`min` would be worse than `max` here, but IIRC `beg` is used as a kind
of "modification boundary" (the completion operation cannot modify any
part of the text before `beg`) so I use `max` to minimize the damage in
case the replacement breaks the assumptions made by
`completion-table-subvert`.
[ As alluded to in the comment just before the code you cite, there's
a fundamental discrepancy between the information that pcomplete
collects and the information that completion-at-point-function needs,
so we do our best to workaround and confine the cases where the
discrepancy bites us. ]
Stefan
next prev parent reply other threads:[~2019-03-20 2:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-16 22:29 [pcomplete.el (pcomplete-completions-at-point)] Why max? Tadeus Prastowo
2019-03-19 9:55 ` Tadeus Prastowo
2019-03-19 16:37 ` Stefan Monnier
2019-03-19 16:40 ` Tadeus Prastowo
2019-03-20 2:09 ` Stefan Monnier [this message]
2019-03-20 11:00 ` Tadeus Prastowo
2019-03-20 14:00 ` Stefan Monnier
2019-03-20 16:14 ` Tadeus Prastowo
2019-03-20 17:11 ` Stefan Monnier
2019-03-20 17:17 ` Tadeus Prastowo
2019-03-20 23:38 ` John Wiegley
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvh8bys4nz.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@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 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.