From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Mendler Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] `completing-read` - allow history=t, sorting improvements Date: Tue, 20 Apr 2021 01:47:34 +0200 Message-ID: <66a96995-10ec-f466-530c-87d173cdfaba@mendler.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11486"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Apr 20 03:13:28 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 1lYexC-0002tr-WA for ged-emacs-devel@m.gmane-mx.org; Tue, 20 Apr 2021 03:13:27 +0200 Original-Received: from localhost ([::1]:55290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYexC-0006Qs-2Q for ged-emacs-devel@m.gmane-mx.org; Mon, 19 Apr 2021 21:13:26 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYdcF-0006iH-1z for emacs-devel@gnu.org; Mon, 19 Apr 2021 19:47:43 -0400 Original-Received: from server.qxqx.de ([2a01:4f8:121:346::180]:60063 helo=mail.qxqx.de) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYdcC-00022o-Cs for emacs-devel@gnu.org; Mon, 19 Apr 2021 19:47:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de; s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=6jx8UVpKAMYGSi8xV45fYV+H/qVUghSgFH9Mem+4BXU=; b=bP4PT3Ef7w6xrB9qX5uAPIxzyT 77xsL9JIPusoTuMJmPxhOu5Z83YQ6QOniMer/EfooD1V+tRP36UOS1Mz5Cn7JCyHP12kj9ubw8rVo I+gy2u14ghshLHaAouC9LAq/nJOegnNjTGBfY6GUgOiBN3zxc7vW38o6oQB7XJ82jCeI=; In-Reply-To: Content-Language: en-US Received-SPF: pass client-ip=2a01:4f8:121:346::180; envelope-from=daniel@mendler.net; helo=mail.qxqx.de X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 19 Apr 2021 21:10:42 -0400 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:268198 Archived-At: On 4/20/21 12:55 AM, Stefan Monnier wrote: >> +(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. Yes, right. The base size, even better. I will use that instead! > [ If (cdr last) is nil it's equivalent to 0. ] I stumbled over this just today, when I had assumed that the cdr always has an integer. But the docs say it "may" have that. >> + (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). I will check. I still believe a tiny hack is needed because of the final slash. And the advantage of dropping everything behind the slash is that accesses to files influence the position of their parent directory (if one considers that an advantage). Thanks for letting me know about the `minibuffer-completing-file-name` variable. There is also `minibuffer-completing-symbol`. Shall we mark them as obsolete? I wondered why they exist but I took them thankfully as an easy way to access the category. I will revert this then in my packages. Daniel