From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: Canonical way to add a pre-filter to completing-read Date: Thu, 10 May 2018 18:05:17 -0400 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1525989823 32628 195.159.176.226 (10 May 2018 22:03:43 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 10 May 2018 22:03:43 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: help-gnu-emacs@gnu.org To: Kaushal Modi Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri May 11 00:03:39 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fGtf0-0008Mj-Tm for geh-help-gnu-emacs@m.gmane.org; Fri, 11 May 2018 00:03:39 +0200 Original-Received: from localhost ([::1]:35779 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGth6-0003U9-KV for geh-help-gnu-emacs@m.gmane.org; Thu, 10 May 2018 18:05:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41669) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGtgi-0003S5-Qx for help-gnu-emacs@gnu.org; Thu, 10 May 2018 18:05:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGtgf-0007A7-M8 for help-gnu-emacs@gnu.org; Thu, 10 May 2018 18:05:24 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:44399) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGtgf-00079a-Dz for help-gnu-emacs@gnu.org; Thu, 10 May 2018 18:05:21 -0400 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id w4AM5WxI019175; Thu, 10 May 2018 18:05:33 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 01FCF67F7C; Thu, 10 May 2018 18:05:17 -0400 (EDT) In-Reply-To: (Kaushal Modi's message of "Thu, 10 May 2018 17:19:52 +0000") X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 2 Rules triggered EDT_SA_DN_PASS=0, RV6283=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6283> : inlines <6627> : streams <1786518> : uri <2639994> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.20 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:116707 Archived-At: >> M-: (km-completion "Entry: " '("abc" "bcd" "cde") "bc") RET >> and then types `a` (and then hits `?` to see the list of remaining >> completions, or maybe he uses icomplete-mode to always see the list of >> remaining candidates). What do you want the list of completions to be >> at that point? > If I type `a` there, the entry would become "bca", Is "bca" really what you think would be ideal here (where the user never typed "bc")? That seems to imply the user would have to use something like C-a C-k in order to type something completely different from "bc". Most UIs seem to find such behavior undesirable, AFAIK (in the default Emacs UI we shun initial inputs altogether, requiring the user to hit M-n if he wants to edit the default; and in more "mainstream" UIs I know, the initial input is highlighted/selected at first, and hitting "a" would first delete it (you'd need to use a cursor key first in order to de-select the text before hitting "a" in order to keep the "bc")). >> Some things you can do with the standard completion-UI: >> - setup your completion table such that it uses `substring` completion >> by default. > That sounds like that would work.. can you please point to an example? You want to setup your completion table so it returns a `metadata` which includes a `category` of your choice, and then you want to add an entry for that category to completion-category-defaults. This is done for example for read-char-by-name. >> - use `completion-table-in-turn` with the first table being a sub-table >> which only includes the entries that match "bc". > I did not understand this suggestion. You could setup your completion table such that the UI would behave as follows: - Imagine your list of completion candidates is abc, bcd, acd, cde. - And you want to start by filtering for "bc". - At first the minibuffer says "Entry: " - At this point the available completions would be "abc" and "bcd". - Then the user hits "a". - The minibuffer becomes "Entry: a" - The available completions become just "abc" and nothing else. - Then the user hits "ac". - The minibuffer becomes "Entry: ac" - The available completions become just "acd" and nothing else. You'd do this by combining (with the mentioned function) two completion tables: one containing only the entries that match "bc" and the other containing all the entries, so when the input matches in the first table, we stay in the first stable, but if it doesn't, then we search in the second table. Stefan