From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Kaushal Modi Newsgroups: gmane.emacs.help Subject: Re: Canonical way to add a pre-filter to completing-read Date: Thu, 10 May 2018 17:36:44 +0000 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1525973726 26542 195.159.176.226 (10 May 2018 17:35:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 10 May 2018 17:35:26 +0000 (UTC) Cc: Help Gnu Emacs mailing list To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu May 10 19:35:21 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 1fGpTN-0006ls-E7 for geh-help-gnu-emacs@m.gmane.org; Thu, 10 May 2018 19:35:21 +0200 Original-Received: from localhost ([::1]:34931 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGpVS-0007jn-FM for geh-help-gnu-emacs@m.gmane.org; Thu, 10 May 2018 13:37:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGpUw-0007jf-Nv for help-gnu-emacs@gnu.org; Thu, 10 May 2018 13:37:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGpUv-0005wn-Gl for help-gnu-emacs@gnu.org; Thu, 10 May 2018 13:36:58 -0400 Original-Received: from mail-lf0-x231.google.com ([2a00:1450:4010:c07::231]:38409) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGpUv-0005wT-3j for help-gnu-emacs@gnu.org; Thu, 10 May 2018 13:36:57 -0400 Original-Received: by mail-lf0-x231.google.com with SMTP id z142-v6so4119497lff.5 for ; Thu, 10 May 2018 10:36:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nLZXb/rSXXjOJLIsBSdRvsYGXSlH4VYDgTnbVk1ZA+w=; b=kqxCKwErfmGHRZkG7JsQKDHw9lrQEBV0S2dHLdzBBodeEILshhX1oSXcqFXNvMHzSb P1pJWLvmdS2Dbvg6J/plEWFRhDKSLbtwTULa8squXbPiE+uvPfT9A2cBS4zn4zO8C+fP nafSK52Yw+FFIlFkhPzgpPgM+boTZduDEZWCxiqqCdJ2ekSKN64IcSHbcouXABMHMwW2 OegAIAQ80rUWNt3+lW6G76fu9bxMjTtolfAgPnb+lu4Pnl5q9Ee+u0KK0Dem3TRa07dX /0IfPsdIWLOwKzEmTjxK+sW9LqWud22bBL59Ib/hsUueT0yKwVqEA842sE/qxHYuQv93 uDTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nLZXb/rSXXjOJLIsBSdRvsYGXSlH4VYDgTnbVk1ZA+w=; b=Y/pqjZzqq7aQpkvRiKf+LUiluyHNoBHgcLG2FCAkZ2uffTpolecE5z8KEBPAELnuGd /PDZ0RAXZCCPCUjfnZlR22pQIhXwkfKwj0S7OhilnHTgS/gR8Oq9jdKunD+BAbHJGrBj sXTfy60gf4xHsTleD9YAsbpwZ4DSHvIYBmz7hyLMXL6Z9ggDCcPfGjrlU2+fmRwL0s12 9htCDxhyQ+1qRJ6FtDjUuJXttBYnzkgng23dVE2B/qar1h1I9rFcEEhoJki9nzz7FhJQ cWDjVUw/5upH/bUmWKki3xLP9GYetaNAwOmtHPKVqaeuceJRlXGkrMox4ZDhst29XrqY fMvA== X-Gm-Message-State: ALKqPweidf/c9VUbhWY6OnyRtTH3w5dNmtc4HxX248qLaWysCR2ANzDQ C90vcCH0ijC0LZdXn3/ZYtHS/+izXlml+Uqyf6s= X-Google-Smtp-Source: AB8JxZoLMx4eEMdQL9VMk+wNoRh0GNoMqqS92XTVtJaoRva3wqunjLHQdXq5lbSkix4Pv3aVvxk2WZ0MDURiOr4mTl8= X-Received: by 2002:a2e:1614:: with SMTP id w20-v6mr1842861ljd.105.1525973815679; Thu, 10 May 2018 10:36:55 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::231 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 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:116706 Archived-At: Hi Drew, On Thu, May 10, 2018 at 10:10 AM Drew Adams wrote: > Possibilities: > > 1. Filter the list of completions before passing it. > IOW, pass '("abc" "bcd"), not '("abc" "bcd" "cde"). > (Or if COMPLETIONS is a function, have it also filter, > as and when needed.) > Pre-filtering would not work in my case, as I might even need to change the filter on the fly *after it got initially set using INITIAL-INPUT*. See how I use it in this GIF (the same that I linked in my earlier reply to Stefan): https://imgur.com/1Ki7uFX. 2. Provide a PREDICATE arg that filters as needed. E.g., > (lambda (xx) (string-match-p "bc" xx)). > That might.. work. I will have to try. With vanilla Emacs: > > If you use a non-function COMPLETIONS arg then you need > to establish that list of candidates before completing. > You have only PREDICATE to play with. The candidates > are determined independently of whatever input might be > in the minibuffer > > If you use a function COMPLETIONS arg then the function > can take into account the current minibuffer input. > The function can do anything you want, to come up with > > the (current, dynamically computed) set of candidates. Let me play with PREDICATE. At the moment, the COMPLETIONS is just a list. I will look into that if setting PREDICATE does not work. > > Below works exactly as I want.. but the docs and manual > > say that INITIAL-INPUT is deprecated. > > > > (completing-read "Entry: " '("abc" "bcd" "cde") nil > > :require-match "bc") > > > > So, what would be the right way, i.e. not using the > > deprecated INITIAL-INPUT? > > Ignore the docs. Emacs was wrong to proclaim INITIAL-INPUT > deprecated. It can be useful. It never hurt anyone for > Emacs to make it available. It is enough to suggest to > users that it is more conventional, and typically more > user-friendly, to use only DEF. > > With luck, this silly uber-control will be removed from > the docs someday. Don't be scared away from using it > when it suits your purpose. > For now, I am using the INITIAL-INPUT as that solves the purpose. But I will later try out the PREDICATE. > (Just one opinion.) > Thanks for that :) -- Kaushal Modi