From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs Subject: bug#34083: 27.0.50; Default completion, if it exists, should always sort to top Date: Tue, 15 Jan 2019 13:39:10 +0000 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1547559486 25886 195.159.176.226 (15 Jan 2019 13:38:06 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 15 Jan 2019 13:38:06 +0000 (UTC) Cc: monnier@iro.umontreal.ca To: 34083@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jan 15 14:38:02 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gjOun-0006cQ-0B for geb-bug-gnu-emacs@m.gmane.org; Tue, 15 Jan 2019 14:38:01 +0100 Original-Received: from localhost ([127.0.0.1]:50892 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjOwt-0006Py-UO for geb-bug-gnu-emacs@m.gmane.org; Tue, 15 Jan 2019 08:40:11 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:58881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjOwm-0006P0-IS for bug-gnu-emacs@gnu.org; Tue, 15 Jan 2019 08:40:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjOwl-00013w-Hm for bug-gnu-emacs@gnu.org; Tue, 15 Jan 2019 08:40:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60343) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gjOwl-00013c-EA for bug-gnu-emacs@gnu.org; Tue, 15 Jan 2019 08:40:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gjOwk-00033m-U5 for bug-gnu-emacs@gnu.org; Tue, 15 Jan 2019 08:40:03 -0500 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: Tue, 15 Jan 2019 13:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 34083 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.154755958811728 (code B ref -1); Tue, 15 Jan 2019 13:40:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 Jan 2019 13:39:48 +0000 Original-Received: from localhost ([127.0.0.1]:59624 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gjOwW-000336-6z for submit@debbugs.gnu.org; Tue, 15 Jan 2019 08:39:48 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:48536) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gjOwU-00032r-AS for submit@debbugs.gnu.org; Tue, 15 Jan 2019 08:39:46 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:57929) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjOwM-0000HS-6N for submit@debbugs.gnu.org; Tue, 15 Jan 2019 08:39:39 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:58721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjOwL-00069k-1p for bug-gnu-emacs@gnu.org; Tue, 15 Jan 2019 08:39:38 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjOwE-0000Ap-4i for bug-gnu-emacs@gnu.org; Tue, 15 Jan 2019 08:39:34 -0500 Original-Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:32973) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gjOw8-00005m-Q2 for bug-gnu-emacs@gnu.org; Tue, 15 Jan 2019 08:39:25 -0500 Original-Received: by mail-wm1-x32d.google.com with SMTP id r24so1070576wmh.0 for ; Tue, 15 Jan 2019 05:39:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version; bh=AgO08BxTP2OwetQNdNlKxX4qeWCU6FW7N3zRq1Mk5Ts=; b=lLbY3zk1R7L5xtIb3KC339hseEtxSiGEiUC0o7lVqZEy8wwkppXbbcvw7sCrK4kOxW Wl46R+frkgmvIsQ5/YhDQvqC52wm1by9meEjWXpadIR7EZhby59B3KA6hKAxAi3Riv0x XE/DDmkstZ43vOmcooVT2QklV0f3T72OA0Pf8Ucdt0CpeVlLKqI2VqN96vDRas8KdVQ/ +gdtLgtGqoyK/WSjRCzvZqQPFeTwFng27ORPbtiNlpzvWGVdusJIrFJtFiQlxiVN5vfQ xO2bvbqVam0FUHM2NRaBGValld+voBYspesqpbmxUPU2QpwzaGmjbAjuDXrJOLu5OqyK qDcA== 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:date:message-id:mime-version; bh=AgO08BxTP2OwetQNdNlKxX4qeWCU6FW7N3zRq1Mk5Ts=; b=QfEUCoRaH7jzizkGrQfjAE+If/R0AjdWITnROGxZYE9RikWjyIqIL8iZf3fRW93XGu cl5nY5+wk4ke7YTg+9SK3/YcBaoamzUG7UD+U7htc8g9f3Dx1BdE64Mzv2/Ifm5DD+Tk F+0ppYLndvrGYbQeNAsXiJlUiET0aBbxmAojivKoz3wHdaoElW16dgZ1IdRuA9ZNi8MT IyOqZKa2DN5/niSwQKcJX2mTp04hHelM4Mq+8jaCE5Z+fILLjl00TWRD8yDBXFSjgq0I 2akMzT7zxpOTDVfSBRVpQuBULkAxGwZoYE+3GAztzUkvla8lDDvlg2sc2oNTiIXSBS3a Wwlg== X-Gm-Message-State: AJcUukfuUa/HcDPYBoj15M+KSUHQcqG4u+HFRa/aG0yrM24VM/ciU2Dh ZKOwvDdLumj2svnA7vh/T38= X-Google-Smtp-Source: ALg8bN4bxYR9s+mpD/Xg5LznG6D65MmPPrhoel6HjQOB1k7SqFaUlVDS0Er5ofRoAQ/+4+RjT6vxeA== X-Received: by 2002:a1c:180a:: with SMTP id 10mr3440963wmy.92.1547559562303; Tue, 15 Jan 2019 05:39:22 -0800 (PST) Original-Received: from GONDOMAR.yourcompany.com (mail1.siscog.pt. [89.115.233.242]) by smtp.gmail.com with ESMTPSA id p139sm61992426wmd.31.2019.01.15.05.39.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 Jan 2019 05:39:21 -0800 (PST) X-Antivirus: AVG (VPS 190115-0, 15-01-2019), Outbound message X-Antivirus-Status: Clean X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:154449 Archived-At: --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hi maintainers, In completion-all-sorted-completions, completions are sorted according to recency of usage, which is a good idea. However, for calls to completing-read that are given a DEFAULT (actually DEF) argument, the sort order isn't very useful. It means that, when using icomplete for i.e. M-x describe-symbol on top of the symbol sort Describe symbol (default sort): { some-other-symbol | yet-another | sort= } ^^^^^^^^^^^^^^^^^ boldface =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20 This is very confusing in icomplete as "some-other-symbol" in the previous example is boldface and gives the idea of a default. It is the thing that minibuffer-force-complete-and-exit, bound to C-j, will complete to immediately. But since no text has been entered, C-m will make completion consider "sort" instead. Here's a recipe: Emacs -Q M-x icomplete-mode M-: (setq icomplete-show-matches-on-no-input t) RET type "sort" C-h o Verify that "sort" is the default but it doesn't visually in the "propects list". Instead "%" is made boldface and C-j and C-M-i will immediately complete to it. This inconsistency is easy to fix in minibuffer.el, as attached in a patch. After the patch, "sort" is sorted to the top. I couldn't figure exactly if there is an impact on non-icomplete.el usage of completion-all-sorted-completions, because I'm not familiar with that code. But since it was already using minibuffer-history-variable, I don't think this disturbs it much more than that. Naturally, this could be coded to work in icomplete-mode only, but doing that patch cleanly is much harder. Jo=E3o --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Consider-default-completion-in-completion-all-sorted.patch >From 26acc0bf504a5c3c29abcbdec7af0544cf2aec02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Tue, 15 Jan 2019 13:27:01 +0000 Subject: [PATCH] Consider default completion in completion-all-sorted-completions * lisp/minibuffer.el (minibuffer-completion-default): New variable. (completion-all-sorted-completions): Sort with the default on top. (completing-read-default): Set minibuffer-completion-default --- lisp/minibuffer.el | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 5760a2e49d..578fd9ab63 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1210,6 +1210,9 @@ completion--metadata (if (eq (car bounds) base) md-at-point (completion-metadata (substring string 0 base) table pred)))) +(defvar minibuffer-completion-default nil + "Within call to `completing-read', this holds the DEF argument.") + (defun completion-all-sorted-completions (&optional start end) (or completion-all-sorted-completions (let* ((start (or start (minibuffer-prompt-end))) @@ -1242,12 +1245,17 @@ completion-all-sorted-completions (setq all (if sort-fun (funcall sort-fun all) ;; Prefer shorter completions, by default. (sort all (lambda (c1 c2) (< (length c1) (length c2)))))) - ;; Prefer recently used completions. + ;; Prefer recently used completions and put the default, if + ;; it exists, on top. (when (minibufferp) - (let ((hist (symbol-value minibuffer-history-variable))) - (setq all (sort all (lambda (c1 c2) - (> (length (member c1 hist)) - (length (member c2 hist)))))))) + (let ((hist (symbol-value minibuffer-history-variable)) + (def minibuffer-completion-default)) + (setq all (sort all + (lambda (c1 c2) + (cond ((equal c1 def) t) + ((equal c2 def) nil) + (t (> (length (member c1 hist)) + (length (member c2 hist)))))))))) ;; Cache the result. This is not just for speed, but also so that ;; repeated calls to minibuffer-force-complete can cycle through ;; all possibilities. @@ -3422,6 +3430,7 @@ completing-read-default (let* ((minibuffer-completion-table collection) (minibuffer-completion-predicate predicate) + (minibuffer-completion-default def) (minibuffer-completion-confirm (unless (eq require-match t) require-match)) (base-keymap (if require-match -- 2.19.2 --=-=-=--