From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [pcomplete.el (pcomplete-completions-at-point)] Why max? Date: Tue, 19 Mar 2019 22:09:21 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="213766"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Mar 20 03:13:22 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h6QjK-000tTj-0A for ged-emacs-devel@m.gmane.org; Wed, 20 Mar 2019 03:13:22 +0100 Original-Received: from localhost ([127.0.0.1]:41447 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6QjI-0006Iq-VR for ged-emacs-devel@m.gmane.org; Tue, 19 Mar 2019 22:13:21 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:56059) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6Qj7-0006CB-SW for emacs-devel@gnu.org; Tue, 19 Mar 2019 22:13:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h6Qfb-0004u4-Sa for emacs-devel@gnu.org; Tue, 19 Mar 2019 22:09:32 -0400 Original-Received: from [195.159.176.226] (port=50378 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h6Qfa-0004or-OT for emacs-devel@gnu.org; Tue, 19 Mar 2019 22:09:31 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1h6QfY-000pe9-Fy for emacs-devel@gnu.org; Wed, 20 Mar 2019 03:09:28 +0100 X-Injected-Via-Gmane: http://gmane.org/ Cancel-Lock: sha1:32D6u84RxWrlxaO+RM9FwIdMpSc= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:234387 Archived-At: > M-x shell > cd /tmp > mkdir AAAA\ BB\ CCCC > cd AAAA\ BB 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