From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Andy Schwartzmeyer Newsgroups: gmane.emacs.bugs Subject: bug#42101: Date: Sat, 27 Jun 2020 23:36:53 -0700 Message-ID: <67E6FFAA-233E-4A72-A947-93E358B91D4E@posteo.net> References: <427CB228-0C09-44A0-A684-0A7C2C294487@schwartzmeyer.com> Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_63D8D700-A63D-436B-BB74-D88066811735" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="16262"; mail-complaints-to="usenet@ciao.gmane.io" To: 42101@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 28 17:51:00 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jpZa8-00047e-BT for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 28 Jun 2020 17:51:00 +0200 Original-Received: from localhost ([::1]:51090 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpZa7-00014N-Cw for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 28 Jun 2020 11:50:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpZZD-0000Vp-Kk for bug-gnu-emacs@gnu.org; Sun, 28 Jun 2020 11:50:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35260) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jpZZD-00011J-BA for bug-gnu-emacs@gnu.org; Sun, 28 Jun 2020 11:50:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jpZZD-0004NG-9e for bug-gnu-emacs@gnu.org; Sun, 28 Jun 2020 11:50:03 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <427CB228-0C09-44A0-A684-0A7C2C294487@schwartzmeyer.com> Resent-From: Andy Schwartzmeyer Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 28 Jun 2020 15:50:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42101 X-GNU-PR-Package: emacs Original-Received: via spool by 42101-submit@debbugs.gnu.org id=B42101.159335939316765 (code B ref 42101); Sun, 28 Jun 2020 15:50:03 +0000 Original-Received: (at 42101) by debbugs.gnu.org; 28 Jun 2020 15:49:53 +0000 Original-Received: from localhost ([127.0.0.1]:46801 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jpZZ1-0004MI-GM for submit@debbugs.gnu.org; Sun, 28 Jun 2020 11:49:53 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:45170) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jpQw4-0005Fn-Qj for 42101@debbugs.gnu.org; Sun, 28 Jun 2020 02:37:06 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 3A355160060 for <42101@debbugs.gnu.org>; Sun, 28 Jun 2020 08:36:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1593326219; bh=Cc+tTLQyUSuohqJAZu6rGdnU3YWRZfEyHFHPcCYmATA=; h=From:Subject:Date:To:From; b=GuuoTiswspEQFrHRHN3oZ+VtcHRrcciJQJaicPGBv5RgeyEH0iAAfQNLNNrZIm1UI 81ROZTg4l7NwdqW7XOVT9ZhqjXvt5jk7ETJFWOgKMrlgfu0mYYJpTOJ3bEwxZRmrm5 o2cY2cAAY2VK4OTbzhWdP0Dq/vsR5JYXtaM5VnIYYxO1OMIHshdHQGX4rIVQTEvDOM 0v8QYRDcRQYEZoJpp4fYkPIWOGayD4K6WLVAxMAI/IgGltEcRDhzYoDi/Nt33yLHaQ 44/ttWsUgK8KVyTzamEklBOU6Rwn26IUw8JVN0rALc3lJJmbITuSSmLFa0C6YzPY/7 iQymuG/fYjKdg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 49vgrn3cnYz6tmJ for <42101@debbugs.gnu.org>; Sun, 28 Jun 2020 08:36:57 +0200 (CEST) X-Mailer: Apple Mail (2.3608.80.23.2.2) X-Mailman-Approved-At: Sun, 28 Jun 2020 11:49:50 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:182464 Archived-At: --Apple-Mail=_63D8D700-A63D-436B-BB74-D88066811735 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Okay, with some message style debugging I think I narrowed it down: (defun icomplete-force-complete-and-exit () "Complete the minibuffer with the longest possible match and exit. Use the first of the matches if there are any displayed, and use the default otherwise." (interactive) ;; This function is tricky. The mandate is to "force", meaning we ;; should take the first possible valid completion for the input. ;; However, if there is no input and we can prove that that ;; coincides with the default, it is much faster to just call ;; `minibuffer-complete-and-exit'. Otherwise, we have to call ;; `minibuffer-force-complete-and-exit', which needs the full ;; completion set and is potentially slow and blocking. Do the ;; latter if: (if (or ;; there's some input, meaning the default in off the table by ;; definition; OR (> (icomplete--field-end) (icomplete--field-beg)) ;; there's no input, but there's also no minibuffer default ;; (and the user really wants to see completions on no input, ;; meaning he expects a "force" to be at least attempted); OR (and (not minibuffer-default) icomplete-show-matches-on-no-input) ;; there's no input but the full completion set has been ;; calculated, This causes the first cached completion to ;; be taken (i.e. the one that the user sees highlighted) completion-all-sorted-completions) (progn (message (if completion-all-sorted-completions (message = "completions t") (message "completions nil"))) (message (if minibuffer-default "default t" "default nil")) (message "FORCING") (minibuffer-force-complete-and-exit)) ;; Otherwise take the faster route... (minibuffer-complete-and-exit))) With fido-mode, the final test in the or clause, namely = 'completion-all-sorted-completions=E2=80=99, is t, whereas in = icomplete-mode it is nil. This is causing the first cached completion to = be taken (i.e. the =E2=80=98completion-styles-alist=E2=80=99 which = probably shouldn=E2=80=99t be the first completion anyway). Moreover, it = means that this function=E2=80=99s existence is being overriden: it=E2=80=99= s never shortcutting to 'minibuffer-complete-and-exit=E2=80=99 for = fido-mode users. Now to find out two more things: 1. Why is the completion list not bubbling minibuffer-default to the = top? (I=E2=80=99m using helpful-variable, but this also happens with = describe-variable, and I=E2=80=99ve noticed it with other functions that = will use a default from point.) 2. Why is 'completion-all-sorted-completions=E2=80=99 always t when = using fido-mode? At least for #1: In this bit of code the minibuffer-default is compared with equal and = with string-prefix-p: (defun icomplete--sorted-completions () (or completion-all-sorted-completions (cl-loop with beg =3D (icomplete--field-beg) with end =3D (icomplete--field-end) with all =3D (completion-all-sorted-completions beg end) for fn in (cond ((and minibuffer-default (stringp minibuffer-default) ; bug#38992 (=3D (icomplete--field-end) = (icomplete--field-beg))) ;; When we have a non-nil string default and ;; no input whatsoever: we want to make sure ;; that default is bubbled to the top so that ;; `icomplete-force-complete-and-exit' will ;; select it (do that even if the match ;; doesn't match the completion perfectly. `(,(lambda (comp) (equal minibuffer-default comp)) ,(lambda (comp) (string-prefix-p minibuffer-default comp)))) ((and fido-mode (not minibuffer-default) (eq (icomplete--category) 'file)) ;; `fido-mode' has some extra file-sorting ;; semantics even if there isn't a default, ;; which is to bubble "./" to the top if it ;; exists. This makes M-x dired RET RET go to ;; the directory of current file, which is ;; what vanilla Emacs and `ido-mode' both do. `(,(lambda (comp) (string=3D "./" comp))))) thereis (cl-loop for l on all while (consp (cdr l)) for comp =3D (cadr l) when (funcall fn comp) do (setf (cdr l) (cddr l)) and return (completion--cache-all-sorted-completions beg end (cons = comp all))) finally return all))) I=E2=80=99m not sure how to get it to do so, but when there are = candidates satisfying both =E2=80=98equals=E2=80=99 and = =E2=80=98string-prefix-p=E2=80=99, we need to get this to prefer the = former over the latter. Cheers, Andy= --Apple-Mail=_63D8D700-A63D-436B-BB74-D88066811735 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Okay, with some message style debugging I think I narrowed it = down:

(defun = icomplete-force-complete-and-exit ()
  = "Complete the minibuffer with the longest possible match and = exit.
Use the first of the matches if there are any = displayed, and use
the default = otherwise."
  (interactive)
  ;; This function is tricky.  The mandate is to = "force", meaning we
  ;; should take the first = possible valid completion for the input.
  ;; = However, if there is no input and we can prove that that
  ;; coincides with the default, it is much faster to = just call
  ;; `minibuffer-complete-and-exit'. =  Otherwise, we have to call
  ;; = `minibuffer-force-complete-and-exit', which needs the full
  ;; completion set and is potentially slow and = blocking.  Do the
  ;; latter = if:
  (if (or
  =      ;; there's some input, meaning the default in off = the table by
       ;; = definition; OR
       (> = (icomplete--field-end) (icomplete--field-beg))
 =      ;; there's no input, but there's also no minibuffer = default
       ;; (and the user = really wants to see completions on no input,
  =      ;; meaning he expects a "force" to be at least = attempted); OR
       (and (not = minibuffer-default)
        =     icomplete-show-matches-on-no-input)
       ;; there's no input but the full = completion set has been
      =  ;; calculated, This causes the first cached completion = to
       ;; be taken (i.e. the = one that the user sees highlighted)
    =    completion-all-sorted-completions)
      (progn
  =       (message (if completion-all-sorted-completions = (message "completions t") (message "completions nil")))
        (message (if minibuffer-default = "default t" "default nil"))
      =   (message "FORCING")
      =   (minibuffer-force-complete-and-exit))
  =   ;; Otherwise take the faster route...
  =   (minibuffer-complete-and-exit)))

With fido-mode, the final test in the or clause, = namely 'completion-all-sorted-completions=E2=80=99, is t, whereas in = icomplete-mode it is nil. This is causing the first cached completion to = be taken (i.e. the =E2=80=98completion-styles-alist=E2=80=99 which = probably shouldn=E2=80=99t be the first completion anyway). Moreover, it = means that this function=E2=80=99s existence is being overriden: it=E2=80=99= s never shortcutting to 'minibuffer-complete-and-exit=E2=80= =99 for fido-mode users.

Now to find out two more = things:

1. Why is = the completion list not bubbling minibuffer-default to the top? (I=E2=80=99= m using helpful-variable, but this also happens with describe-variable, = and I=E2=80=99ve noticed it with other functions that will use a default = from point.)
2. Why is = 'completion-all-sorted-completions=E2=80=99 always t when using = fido-mode?

At least = for #1:

In this bit = of code the minibuffer-default is compared with equal and with = string-prefix-p:

(defun = icomplete--sorted-completions ()
 (or = completion-all-sorted-completions
     (cl-loop
      with beg =3D = (icomplete--field-beg)
      with end =3D = (icomplete--field-end)
      with all =3D = (completion-all-sorted-completions beg end)
      for fn in (cond ((and = minibuffer-default
          &nb= sp;            = ;     (stringp minibuffer-default) ; = bug#38992
          &nb= sp;            = ;     (=3D (icomplete--field-end) = (icomplete--field-beg)))
          &nb= sp;            = ;;; When we have a non-nil string default and
          &nb= sp;            = ;;; no input whatsoever: we want to make sure
          &nb= sp;            = ;;; that default is bubbled to the top so that
          &nb= sp;            = ;;; `icomplete-force-complete-and-exit' will
          &nb= sp;            = ;;; select it (do that even if the match
          &nb= sp;            = ;;; doesn't match the completion perfectly.
          &nb= sp;            = ;`(,(lambda (comp)
          &nb= sp;            = ;     (equal minibuffer-default comp))
          &nb= sp;            = ;  ,(lambda (comp)
          &nb= sp;            = ;     (string-prefix-p minibuffer-default = comp))))
          &nb= sp;           ((and= fido-mode
          &nb= sp;            = ;     (not minibuffer-default)
          &nb= sp;            = ;     (eq (icomplete--category) 'file))
          &nb= sp;            = ;;; `fido-mode' has some extra file-sorting
          &nb= sp;            = ;;; semantics even if there isn't a default,
          &nb= sp;            = ;;; which is to bubble "./" to the top if it
          &nb= sp;            = ;;; exists.  This makes M-x dired RET RET go to
          &nb= sp;            = ;;; the directory of current file, which is
          &nb= sp;            = ;;; what vanilla Emacs and `ido-mode' both do.
          &nb= sp;            = ;`(,(lambda (comp)
          &nb= sp;            = ;     (string=3D "./" comp)))))
      thereis (cl-loop
          &nb= sp;    for l on all
          &nb= sp;    while (consp (cdr l))
          &nb= sp;    for comp =3D (cadr l)
          &nb= sp;    when (funcall fn comp)
          &nb= sp;    do (setf (cdr l) (cddr l))
          &nb= sp;    and return
          &nb= sp;    (completion--cache-all-sorted-completions beg = end (cons comp all)))
      finally return all)))

I=E2=80=99m not sure how to get it to do so, = but when there are candidates satisfying both =E2=80=98equals=E2=80=99 = and =E2=80=98string-prefix-p=E2=80=99, we need to get this to prefer the = former over the latter.
Cheers,
Andy
= --Apple-Mail=_63D8D700-A63D-436B-BB74-D88066811735--