From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs Subject: bug#49888: 28.0.50; fido-mode not sorting by recency Date: Sun, 15 Aug 2021 13:11:27 +0100 Message-ID: <87k0kmx5zk.fsf@gmail.com> References: <1dec2c8a-fc9e-a70c-f236-9b1887ca384f@inventati.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7373"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 49888@debbugs.gnu.org To: Manuel Uberti Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Aug 15 14:12:15 2021 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 1mFEzv-0001bG-AM for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 15 Aug 2021 14:12:15 +0200 Original-Received: from localhost ([::1]:46440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mFEzp-0000SY-0Q for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 15 Aug 2021 08:12:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mFEzi-0000Ro-EZ for bug-gnu-emacs@gnu.org; Sun, 15 Aug 2021 08:12:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34420) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mFEzi-0003mo-03 for bug-gnu-emacs@gnu.org; Sun, 15 Aug 2021 08:12:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mFEzh-0000Vz-Re for bug-gnu-emacs@gnu.org; Sun, 15 Aug 2021 08:12:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 15 Aug 2021 12:12:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49888 X-GNU-PR-Package: emacs Original-Received: via spool by 49888-submit@debbugs.gnu.org id=B49888.16290295051955 (code B ref 49888); Sun, 15 Aug 2021 12:12:01 +0000 Original-Received: (at 49888) by debbugs.gnu.org; 15 Aug 2021 12:11:45 +0000 Original-Received: from localhost ([127.0.0.1]:45966 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mFEzN-0000VN-Sc for submit@debbugs.gnu.org; Sun, 15 Aug 2021 08:11:45 -0400 Original-Received: from mail-wr1-f41.google.com ([209.85.221.41]:34345) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mFEzI-0000V6-S5 for 49888@debbugs.gnu.org; Sun, 15 Aug 2021 08:11:40 -0400 Original-Received: by mail-wr1-f41.google.com with SMTP id h13so19739363wrp.1 for <49888@debbugs.gnu.org>; Sun, 15 Aug 2021 05:11:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=EJ20ztefS1G1li/OySc/lN2GEECAspmKWEKEmNg4XRY=; b=EBgBTwMum+9fjrdQbhpAaq5sTQJbUxevp/Rf1kz4aGwih7vPxYJ5tTsuAgpD/6ZV00 HYSTWmA4GoJ96OnEs+mz7cb/P29dFLK3xXjL0R1+YT1k9silMoGsrbgOix02KK9wvGBw 5TlgtRpzCSRinw17ucId7r49sq5U8l2aTxvJ92SZa3YkXE8k5gK6PmstBHKnqVlplYyk xwFUlA31hRCcjDn0ZI6ZHII6UXNxRfAFRXhD6gIZ1QK81mL43NkN8LXToofLCBBh/xff anXTe0uY4Gh3mNQGXfd+Qg28n3/mul605bO85ud5lwfA6KzyhCLvfC/Xb6rgv7rkbSE2 z1zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=EJ20ztefS1G1li/OySc/lN2GEECAspmKWEKEmNg4XRY=; b=CFt0UxzaACon9egZ7AjQg8Vi6/qNTl3iX48ejNKdF2CtvhkO3FeS5Q5hFvr16R5UGQ AfGmzlwPvZAiOdIbq1PUaV3M+uRri3pj0OzwN4xH0KwhKXT8cXKQOqS5FZFjyNxLs4JY VobIgGzf0d5UtgtbCDxHeu6Y6dChSG2IBNTrHRYkIdeCwSjiM8mfTpsPYvYh7csNS9Cz yd1QIm41YJlSUTFtMI32y1XB6/rifOiMjwmFJd0A8jyNkMT8LyzY1E5Dunx6w0A5D1uE mRVTNKY4DrqQvIIwISYaIiJirJMQQBCGAXxGlzKiVPWxEZLvGiKbTvtRDqkSviGmIDuO FlqA== X-Gm-Message-State: AOAM533dyImHtrSWHQJWK2UJ+LYoP2SHbWkc6LXYmrvTQPJhuvIdJcZQ 0D67LenTgjRGtmgAB5XS33g3eN3dcpU= X-Google-Smtp-Source: ABdhPJyCHd1fwm4Qkkw42hR80yWC0GyFU1xkV8hh3N5VAxvn8uqmuvFwAB86zrsDe8fDpAVagqBSnQ== X-Received: by 2002:adf:80e8:: with SMTP id 95mr13092144wrl.388.1629029490630; Sun, 15 Aug 2021 05:11:30 -0700 (PDT) Original-Received: from krug (a94-133-27-132.cpe.netcabo.pt. [94.133.27.132]) by smtp.gmail.com with ESMTPSA id o6sm8165243wru.92.2021.08.15.05.11.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Aug 2021 05:11:30 -0700 (PDT) In-Reply-To: <1dec2c8a-fc9e-a70c-f236-9b1887ca384f@inventati.org> (Manuel Uberti's message of "Thu, 5 Aug 2021 15:04:40 +0200") 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:211891 Archived-At: Manuel Uberti writes: > In 'emacs -Q', this is what I did: > > - M-x savehist-mode RET > - M-x fido-mode RET > - M-x icomplete-vertical-mode RET > - M-x emacs-init-time > - C-x p p, pick a Git-versioned directory RET > - f, pick the fourth candidate, C-x k RET > - M-x now shows pr-ps-file-preview on top > - C-x p p, pick the only available project > - C-x p f does not offer the previously selected candidate > > Is it possible to make fido-mode sort the candidates by recency? I've now taken a look at this. Yes, it is certainly possible and desirable _if_ there aren't any other overriding criteria. This has to do with the 'flex' completion style. In that style, if anything has been input that leads to "flexy" filtering, the default and correct behaviour is to sort by completion score. But if nothing has been input and there are basically no scores, it makes sense to fall back to a sensible strategy like the one you suggest. Try this patch. It will fix the M-x case, bugt not the C-x p f or C-x f cases unfortunately. Those will be harder to fix. diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 1e8e9fc624..36d95ad5f5 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -3947,27 +3947,36 @@ completion--flex-adjust-metadata ((compose-flex-sort-fn (existing-sort-fn) ; wish `cl-flet' had proper indentation... (lambda (completions) - (let ((pre-sorted - (if existing-sort-fn - (funcall existing-sort-fn completions) - completions))) - (cond - ((or (not (window-minibuffer-p)) - ;; JT@2019-12-23: FIXME: this is still wrong. What - ;; we need to test here is "some input that actually - ;; leads to flex filtering", not "something after - ;; the minibuffer prompt". Among other - ;; inconsistencies, the latter is always true for - ;; file searches, meaning the next clauses will be - ;; ignored. - (> (point-max) (minibuffer-prompt-end))) - (sort - pre-sorted - (lambda (c1 c2) - (let ((s1 (get-text-property 0 'completion-score c1)) - (s2 (get-text-property 0 'completion-score c2))) - (> (or s1 0) (or s2 0)))))) - (t pre-sorted)))))) + (cond + (;; Sort by flex score whenever outside the minibuffer or + ;; in the minibuffer with some input. JT@2019-12-23: + ;; FIXME: this is still wrong. What we need to test here + ;; is "some input that actually leads to flex filtering", + ;; not "something after the minibuffer prompt". Among + ;; other inconsistencies, the latter is always true for + ;; file searches, meaning the next clauses in this cond + ;; will be ignored. + (or (not (window-minibuffer-p)) + (> (point-max) (minibuffer-prompt-end))) + (sort + (if existing-sort-fn + (funcall existing-sort-fn completions) + completions) + (lambda (c1 c2) + (let ((s1 (get-text-property 0 'completion-score c1)) + (s2 (get-text-property 0 'completion-score c2))) + (> (or s1 0) (or s2 0)))))) + (;; If no existing sort fn and nothing flexy happening, use + ;; the default sort. + (not existing-sort-fn) + (let ((la (minibuffer--sort-by-length-alpha completions)) + (hist (and (minibufferp) + (and (not (eq minibuffer-history-variable t)) + (symbol-value minibuffer-history-variable))))) + ;; Sort by history position, put the default, if it + ;; exists, on top. + (if hist (minibuffer--sort-by-position hist la) la))) + (t completions))))) `(metadata (display-sort-function . ,(compose-flex-sort-fn