From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: Canonical way to add a pre-filter to completing-read Date: Thu, 10 May 2018 07:10:05 -0700 (PDT) Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1525961363 10712 195.159.176.226 (10 May 2018 14:09:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 10 May 2018 14:09:23 +0000 (UTC) To: Kaushal Modi , Help Gnu Emacs mailing list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu May 10 16:09:19 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 1fGmFv-0002cO-LW for geh-help-gnu-emacs@m.gmane.org; Thu, 10 May 2018 16:09:15 +0200 Original-Received: from localhost ([::1]:34147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGmI2-00044a-Rm for geh-help-gnu-emacs@m.gmane.org; Thu, 10 May 2018 10:11:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGmGy-0003f5-DV for help-gnu-emacs@gnu.org; Thu, 10 May 2018 10:10:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGmGs-0003el-FD for help-gnu-emacs@gnu.org; Thu, 10 May 2018 10:10:20 -0400 Original-Received: from userp2130.oracle.com ([156.151.31.86]:60286) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fGmGs-0003cy-5S for help-gnu-emacs@gnu.org; Thu, 10 May 2018 10:10:14 -0400 Original-Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w4ADondm189678; Thu, 10 May 2018 14:10:10 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : subject : references : in-reply-to : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=RLEUNn603ogkVlhs8h5Bo+xLV6OQj9K7pfOC+UaTd4s=; b=RZC0Nav1OD3ZYBMzilQMKTiNJdAsVBOKkSJI0LWh6OoNdX80MeTcOdVdTU8zT5RU5Z9e cHxRduRKDBiFQHPf7mOz3aY54UG0VPQKUnnIe+MatM1dFOm+1MmfrWAhjFpr4NXiiRxh 1QDHYFtPvUXnv5nwQUQ65PIJ3526XCaoz0xpfjltmcEQmK8d3jqsfGtdNc3TV90zJ1Mr DjBJLImCVlawdHqUGsA9SjSP+dSJR0aygCclh79E7UcvdhbyXBGSYeapdCP7kRfDrXe5 pppa+SnW0qoGOzOkPNMBBO8Sie7NofOGkTIj+P3GIPjhZsx/RfEBW8FGqdmbZ6uMROhO /w== Original-Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2hv6kpbsma-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 May 2018 14:10:10 +0000 Original-Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w4AEAA4P005054 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 May 2018 14:10:10 GMT Original-Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w4AEA8jH019921; Thu, 10 May 2018 14:10:09 GMT In-Reply-To: X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.4690.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8888 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1805100134 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 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:116700 Archived-At: > I want to use completing-read to provide a "pre-filter" to > narrow down the completion list. 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.) 2. Provide a PREDICATE arg that filters as needed. E.g., (lambda (xx) (string-match-p "bc" xx)). 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. ---- Wrt INITIAL-INPUT: It should not be considered deprecated. There was never any need for that. It should have been enough for the manual or doc string to just explain the difference between DEF and INITIAL-INPUT, and to suggest that in many (most?) cases it can be more user-friendly or more useful to use only DEF. The "deprecation" of this arg was uncalled for, IMHO. ---- If you use Icicles: 1. There are 3 possibilities for filtering with a predicate: a. Use argument PREDICATE. As usual, it filters raw COMPLETIONS, e.g., alist elements or obarray symbols, and it does so before you type anything in the minibuffer. Nothing new here. b. Bind variable `icicle-must-pass-after-match-predicate' around the `completing-read' call. It filters the _displayed_ candidates (strings - what you see in `*Completions*'), and it does so _after_ matching your minibuffer input. c. Bind variable `icicle-must-pass-predicate': same as `icicle-must-pass-after-match-predicate', but before matching your current input. These can be used in combination. PREDICATE filters all initial candidates, even when that might be wasteful (not so performant) because you've typed some text that would more quickly rule out many of them, if matched first. Different use cases call for different matching orders. Sometimes it makes sense to use only PREDICATE, filtering all raw candidates ahead of time. Sometimes it makes sense to do input-matching first, before applying a given predicate. 2. Option `icicle-default-value' controls arg DEF: whether it is shown in the prompt, gets substituted for an empty INITIAL-INPUT, and so on. In particular, 4 of the 6 values insert the default value into the minibuffer: `insert-start' - Insert DEF and leave cursor at start. `insert-end' - Insert DEF and leave cursor at end. `preselect-start' - Insert & preselect DEF; cursor at start. `preselect-end' - Insert & preselect DEF; cursor at end. > 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. (Just one opinion.)