From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.devel Subject: Re: new-flex-completion-style Date: Mon, 18 Feb 2019 20:46:19 +0000 Message-ID: <87wolwvn8k.fsf@gmail.com> References: <20190202232827.27331.87300@vcs0.savannah.gnu.org> <20190202232828.4AE452159A@vcs0.savannah.gnu.org> <87lg2mynrg.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="222459"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Feb 18 21:46:43 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 1gvpoH-000vmO-Ba for ged-emacs-devel@m.gmane.org; Mon, 18 Feb 2019 21:46:41 +0100 Original-Received: from localhost ([127.0.0.1]:36445 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvpoG-00015A-9G for ged-emacs-devel@m.gmane.org; Mon, 18 Feb 2019 15:46:40 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:43609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvpoA-00014u-0B for emacs-devel@gnu.org; Mon, 18 Feb 2019 15:46:35 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gvpo8-0007Av-WC for emacs-devel@gnu.org; Mon, 18 Feb 2019 15:46:33 -0500 Original-Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:33931) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gvpo8-00079z-M7 for emacs-devel@gnu.org; Mon, 18 Feb 2019 15:46:32 -0500 Original-Received: by mail-wr1-x42e.google.com with SMTP id f14so19907845wrg.1 for ; Mon, 18 Feb 2019 12:46:32 -0800 (PST) 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=3ujf/ZnQXKl/haLMfpW9qGKKXKDmzLnhbgONIoBxHys=; b=UEiH+zjydhdNF400OwCz/em98d7gtXdycLX0nZ03hslTCZdIx/FRN1Aluh0nrmaqAv itaoiG3dYUvcaUphIrYrM7JI/jy6RoS+r5WrCguSBCoQ/R75pgrjRr1pBPWSafhj/RaL SQ1uf1hiroMlGRBFScO9AMgb/N2EF970o6KjtPERKikY5M5zlrA+VMygEdeX4+6XRWdI i9dvKZSjByr+Iy11OP+mxj0xapVZqT9BofzB5mUYJyC+cq5sb5fnCzDpstjsEPyLAlWT rVWmrm5cMafWtEVDh40EAvN0ss4sEzloiRMsKuIgG979ZdjG8fv8Av5tVD1QnvRUqESy h8CA== 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=3ujf/ZnQXKl/haLMfpW9qGKKXKDmzLnhbgONIoBxHys=; b=Zc9Qs6cDmbsMsWQFqpHM2kjmfCfv1CIXXYJQ8jQqONMePSjhf7f2ZxT9zsRenVERoI dyJ19N5mI7PStxDCnMmPi7g9MiwfyZ48+k8EKPS541tqR4XWnEKCXEPt3/giFcRY9H+9 oU82ImZwa47UN7hlsXJEENHwDbLbEZWd+h1aTu17wNgVVXOssx9NFeCpouUyO3TQBLSw CvOkdPFPasLM4bFloNQu7Hd7IFj3nPXGomCqWN6SF1nJiB2VrFgAm1MV8LljKrRda7jW NcLZkxjwLlV+3bz4vk/JQSDgMXc5I5c42ixhhErcf20adGwDevS/pS047fGA+Wiu7VWH H0iw== X-Gm-Message-State: AHQUAuYvlEVmtWrSQ0oPFMew7Qbv1g3xlred0zHzvvkdPxq0tcmC5CEO iFytpwiDhAFv899T58F/qNULrDn6 X-Google-Smtp-Source: AHgI3IabV0DZp6vt8gzT6+RtI/EyIbjFUWdjOI4BxEbC6ha7Ix37xb62wxLRirauOk9YXHSLKpZGag== X-Received: by 2002:a5d:4a8a:: with SMTP id o10mr18112712wrq.189.1550522790634; Mon, 18 Feb 2019 12:46:30 -0800 (PST) Original-Received: from lolita.yourcompany.com (188.139.62.94.rev.vodafone.pt. [94.62.139.188]) by smtp.gmail.com with ESMTPSA id y185sm561439wmg.34.2019.02.18.12.46.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Feb 2019 12:46:29 -0800 (PST) In-Reply-To: (Stefan Monnier's message of "Tue, 12 Feb 2019 09:08:03 -0500") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42e 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:233445 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Stefan Monnier writes: > How 'bout we change the buffer name completion table so it specifies its > own cycle-sort-function which uses buffer-list, then. It seems like it > would be a clear win (the buffer-list order is a much better heuristic > than the length). Hi again, Here are two patches: the first does exactly what you propose above, the second goes a little bit further, but I still think it's the right thing... Lightly tested stuff... Jo=C3=A3o --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-switch-to-buffer-s-completion-table-uses-its-own-sor.patch >From f170e728c1c1ac426bb73c63cc54ba2ae30afd1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Mon, 18 Feb 2019 20:32:38 +0000 Subject: [PATCH 1/2] switch-to-buffer's completion table uses its own sorting * src/minibuf.c (Finternal_complete_buffer): Add Qcycle_sort_function to completion table's metadata. (syms_of_minibuf): New symbol Qcycle_sort_function. --- src/minibuf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/minibuf.c b/src/minibuf.c index 321fda1ba8..b23e24c4bd 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -1801,7 +1801,9 @@ If FLAG is nil, invoke `try-completion'; if it is t, invoke else if (EQ (flag, Qlambda)) return Ftest_completion (string, Vbuffer_alist, predicate); else if (EQ (flag, Qmetadata)) - return list2 (Qmetadata, Fcons (Qcategory, Qbuffer)); + return list3 (Qmetadata, + Fcons (Qcategory, Qbuffer), + Fcons (Qcycle_sort_function, Qidentity)); else return Qnil; } @@ -1922,6 +1924,8 @@ syms_of_minibuf (void) DEFSYM (Qactivate_input_method, "activate-input-method"); DEFSYM (Qcase_fold_search, "case-fold-search"); DEFSYM (Qmetadata, "metadata"); + DEFSYM (Qcycle_sort_function, "cycle-sort-function"); + /* A frame parameter. */ DEFSYM (Qminibuffer_exit, "minibuffer-exit"); -- 2.20.0 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-cycle-sort-function-prevails-in-completion-all-sorte.patch >From f8ce65482d86a136f1320dac89e71662256c2168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Mon, 18 Feb 2019 20:41:09 +0000 Subject: [PATCH 2/2] cycle-sort-function prevails in completion-all-sorted-completions * lisp/minibuffer.el (completion-all-sorted-completions): Don't re-sort if completion table has cycle-sort-function. --- lisp/minibuffer.el | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 7413be42eb..cc87ffaced 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1246,20 +1246,23 @@ completion-all-sorted-completions (setq all (delete-dups all)) (setq last (last all)) - (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 and put the default, if - ;; it exists, on top. - (when (minibufferp) - (let ((hist (symbol-value minibuffer-history-variable))) - (setq all (sort all + (cond + (sort-fun + (setq all (funcall sort-fun all))) + (t + ;; Prefer shorter completions, by default. + (setq all (sort all (lambda (c1 c2) (< (length c1) (length c2))))) + (when (minibufferp) + ;; Prefer recently used completions and put the default, if + ;; it exists, on top. + (let ((hist (symbol-value minibuffer-history-variable))) + (setq all + (sort all (lambda (c1 c2) (cond ((equal c1 minibuffer-default) t) ((equal c2 minibuffer-default) nil) (t (> (length (member c1 hist)) - (length (member c2 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. -- 2.20.0 --=-=-=--