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] `completion-all-sorted-completions`: Add support for completion boundaries Date: Sat, 24 Apr 2021 18:19:48 -0400 Message-ID: References: <9beb1aa3-d934-c3ae-7c26-26256e34ae43@daniel-mendler.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32626"; 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 Sun Apr 25 00:20:48 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 1laQdr-0008OQ-Ip for ged-emacs-devel@m.gmane-mx.org; Sun, 25 Apr 2021 00:20:47 +0200 Original-Received: from localhost ([::1]:41026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1laQdq-0000fG-M7 for ged-emacs-devel@m.gmane-mx.org; Sat, 24 Apr 2021 18:20:46 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1laQcz-0000Da-RA for emacs-devel@gnu.org; Sat, 24 Apr 2021 18:19:53 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:17211) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1laQcx-0004jB-Dx for emacs-devel@gnu.org; Sat, 24 Apr 2021 18:19:53 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 7FDED100311; Sat, 24 Apr 2021 18:19:50 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 0A455100216; Sat, 24 Apr 2021 18:19:49 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1619302789; bh=gh4wSvl/BD9zQBug+GgTspdVUxykKmulLhHzQ72xL5c=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=kzUXsUAb4QOaudZKlUz5FPP3Dtf+vJszCIdVRAb1e8UwfXqzZxWNaQVKcs5D2+fvB wbhIWvIqcsN03kl9hXDcJS7gyM5TrWyurnQ92GXRMcWWN/f7ru14d0AQEBPjn2D/of mBM3/k9F8bXIQbkQmtTeqSYiuWH0EmRj80ofn7Iqznw4NMsiCDWfq1WCto/qW/4/73 mzKorg57KPMENWSr4Ex+cPW//bpznZ5X++Fpod4q5+g4603xqh2KN4kV43JMqEQqE5 S70an/mtSCw+kXkTUkZh0XEXuVatH5mY0Z0gxlDPFq/5gid9yAatNRhtIIgKqKNRVL tjC9hgHt5QC/Q== Original-Received: from alfajor (104-222-126-84.cpe.teksavvy.com [104.222.126.84]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id D0AE712017E; Sat, 24 Apr 2021 18:19:48 -0400 (EDT) In-Reply-To: <9beb1aa3-d934-c3ae-7c26-26256e34ae43@daniel-mendler.de> (Daniel Mendler's message of "Sat, 24 Apr 2021 22:14:27 +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:268350 Archived-At: > I attached a patch which adds support for completion boundaries to the > sorting by history position. Tests are included. Thanks, pushed. > lisp/minibuffer.el (completion-all-sorted-completions): The history is > preprocessed by the function `minibuffer--sort-preprocess-history`. > The default value is prepended to the history. The completion base > prefix string is removed from the history elements. This allows > sorting by history position for completion tables which use completion > boundaries, in particular the file completion table. > test/lisp/minibuffer-tests.el (completion-all-sorted-completions): Add > tests for various combinations of with/without history/base/default. I massaged this to use the active voice and stick a bit closer to our conventions. > +(defun minibuffer--sort-preprocess-history (base) > + "Preprocess history. > +Remove completion BASE prefix string from history elements." > + (let* ((def (if (stringp minibuffer-default) > + minibuffer-default > + (car-safe minibuffer-default))) > + (hist (and (not (eq minibuffer-history-variable t)) > + (symbol-value minibuffer-history-variable))) > + (base-size (length base))) > + ;; Drop base string from the history elements > + (when (/= base-size 0) > + (setq hist (delq nil (mapcar > + (lambda (c) > + (when (string-prefix-p base c) > + (substring c base-size))) > + hist)))) > + ;; Default comes first > + (setq hist (if def (cons def hist) hist)) > + hist)) I massaged this so that `def` is also filtered through `base` (and also so that comments are properly punctuated). > + (`(boundaries . ,_) `(boundaries ,(length base) . 0)) > + (_ (complete-with-action action > + '(epsilon alpha gamma beta delta) And I changed this completion table to a list of strings, since lists of symbols happen to work most of the time but aren't officially supported (we support alists whose keys are symbols, OTOH). Stefan