From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] `completing-read` - allow history=t, sorting improvements Date: Mon, 19 Apr 2021 18:55:08 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6180"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Daniel Mendler Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Apr 20 00:56:34 2021 Return-path: Envelope-to: ged-emacs-devel@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 1lYcoj-0001OB-8U for ged-emacs-devel@m.gmane-mx.org; Tue, 20 Apr 2021 00:56:33 +0200 Original-Received: from localhost ([::1]:38710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYcoh-0005am-BX for ged-emacs-devel@m.gmane-mx.org; Mon, 19 Apr 2021 18:56:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37326) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYcnT-0004vW-GG for emacs-devel@gnu.org; Mon, 19 Apr 2021 18:55:15 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:18966) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYcnQ-0003EG-IM for emacs-devel@gnu.org; Mon, 19 Apr 2021 18:55:14 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 390F8100222; Mon, 19 Apr 2021 18:55:11 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id B8A3A1000C4; Mon, 19 Apr 2021 18:55:09 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1618872909; bh=MmGp4H6NL5XFIw0zEdegrclurrPYqvndKbw5fcmkIV4=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=GBCXYItPo666TtWoqwsZnf+OlgDm9yCDckE5jYwqrLOA3lTK0mx5IDCo95xPtYEg1 EJkR8ZCJF02xdtuqMwF8vrpjG0dgAidHyvtFG5DuZFbZO9F547fKlJbatpZtJuuEiq zLkibeycBGmiBg4kUO8JdyXqTR4n4ZoxfoMviB67yTjF7PgZY4NLzeH6nBuHxtXR2A DNHmWR/jGN76djHEucdc7T/tAPOYWH6vm+id225L2GkNQvccpN7fqN+Aey57AMBudR VKySsjB9/DT+4ld3WfYd2VcfMlp+5kRv5dFRnpaYreSXliIHhiEdQUh73hdKWL7BfQ xJAC1IVcFunrQ== Original-Received: from alfajor (104-222-126-84.cpe.teksavvy.com [104.222.126.84]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 8C446120210; Mon, 19 Apr 2021 18:55:09 -0400 (EDT) In-Reply-To: (Daniel Mendler's message of "Tue, 20 Apr 2021 00:29:24 +0200") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:268196 Archived-At: > Btw, I attached the updated patch for the boundaries. I am not sure if the > approach I took there is a good one, this works only in restricted set of > scenarios (not with partial-completion/initials unfortunately). So this > should be discussed. See my comment below. > Then you mentioned test cases - to clarify, do you want to see some kind of > integration test where a mockup minibuffer-completion-table is set-up and > the results of `completion-all-sorted-completions` are checked, I think that's what we'd want, yes. > I looked briefly into > test/lisp/minibuffer.el - the test should probably go there? ^^^ -tests Yes, indeed. > +(defun minibuffer--sort-preprocess-history (start string) > + "Preprocess history, remove completion prefixes. > +STRING is the minibuffer content. > +START is the start position of the completion." > + (let* ((def (car-safe minibuffer-default)) > + (hist (symbol-value minibuffer-history-variable)) > + (hist (if def (cons def hist) hist)) > + (bounds (completion-boundaries > + (substring string 0 (- (point) start)) > + minibuffer-completion-table > + minibuffer-completion-predicate > + "")) Actually, the caller has the info we need already in the (cdr last), which it throws away in: (when last (setcdr last nil) This info also has the advantage of working with partial-completion because it comes from the completion-style output rather than from the completion-table. [ If (cdr last) is nil it's equivalent to 0. ] > + (pre (substring string 0 (car bounds))) > + (pre-len (length pre))) > + ;; Preprocess history if completion boundaries are used > + (cond > + ;; Special handling of file name candidates. > + ;; Drop prefix and everything after the first "/". > + (minibuffer-completing-file-name I hope that using (cdr last) will make it unnecessary to use such a hack. If not, then please try and use the `category` from `md` rather than `minibuffer-completing-file-name` which I consider as obsolete (tho it's not marked as such yet). Stefan