From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: How to handle default value in read-string? Date: Fri, 21 Aug 2015 00:46:20 -0700 (PDT) Message-ID: <64f1708e-7ef3-4d15-b542-136c23bb1607@default> References: <87k2tc9jeu.fsf@mbork.pl> <93600d92-2698-483a-8c1b-f1333363f541@default> <87bne36ku5.fsf@mbork.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1440143222 17069 80.91.229.3 (21 Aug 2015 07:47:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 21 Aug 2015 07:47:02 +0000 (UTC) To: Marcin Borkowski , Help Gnu Emacs mailing list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Aug 21 09:46:49 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZSh2D-0003W6-5C for geh-help-gnu-emacs@m.gmane.org; Fri, 21 Aug 2015 09:46:45 +0200 Original-Received: from localhost ([::1]:40277 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSh2C-00058b-Cl for geh-help-gnu-emacs@m.gmane.org; Fri, 21 Aug 2015 03:46:44 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46917) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSh1y-00058G-Ak for help-gnu-emacs@gnu.org; Fri, 21 Aug 2015 03:46:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZSh1v-0007AQ-2n for help-gnu-emacs@gnu.org; Fri, 21 Aug 2015 03:46:30 -0400 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:32824) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSh1u-00079n-SY for help-gnu-emacs@gnu.org; Fri, 21 Aug 2015 03:46:27 -0400 Original-Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t7L7kM1N001426 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 21 Aug 2015 07:46:23 GMT Original-Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.13.8/8.13.8) with ESMTP id t7L7kM5l010484 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 21 Aug 2015 07:46:22 GMT Original-Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t7L7kLRQ031142; Fri, 21 Aug 2015 07:46:22 GMT In-Reply-To: <87bne36ku5.fsf@mbork.pl> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9 (901082) [OL 12.0.6691.5000 (x86)] X-Source-IP: userv0022.oracle.com [156.151.31.74] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 141.146.126.69 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:106740 Archived-At: > > (let ((icicle-default-value nil)) ...) > > > > A nil value of `icicle-default-value' tells Icicles not to put the > > default value in the prompt. Then you can add it to the prompt > > explicitly, so it will be there with and without Icicle mode: > > > > (defun foo (strg) > > (interactive > > (let ((icicle-default-value nil)) > > (list (read-string "String (default my-default): " > > nil nil "my-default"))))) >=20 > OK, so I sat to this today, and didn't manage to get it to work. > Here's my function: >=20 > (defun my-read-string (prompt &optional initial-input history > default-value inherit-input-method) > (let ((icicle-default-value nil) > =09(prompt-with-default > =09 (progn > =09 (string-match "\\(: \\)?$" prompt) > =09 (replace-match (format " (%s)\\1" default-value) > t nil prompt)))) > (read-string prompt-with-default initial-input history > default-value inherit-input-method))) >=20 > If I do M-: (my-read-string "foo: " nil nil "bar") with Icicles > off, everything is fine. If Icicles are on, however, this is > what I get: foo (bar) (bar): > What am I doing wrong? 1. Let me say first that you need not be hobbled here by Icicles. ;-) You can easily take Icicles out of the mix altogether if you like, by simply customizing option `icicle-functions-to-redefine', removing `read-string' from the list of functions to replace in Icicle mode. 2. Just binding `icicle-default-value' to nil should have done the trick. You can see that the example I gave works. But in fact there was a bug: `icicle-read-string' (unlike `icicle-completing-read', which has similar treatment of the prompt) hard-coded inserting the default value into the prompt. I've fixed that now, so all you should need to do, to inhibit default insertion, is bind `icicle-default-value' to nil - nothing else. I thought that was the case already, but it was not. 3. The reason my example worked, even though automatic inclusion of the default value was hardcoded, is this: When the default value _is_ to be included, Icicles tries to DTRT with prompts that might already hard-code the default value in various ways, as well as with prompts that do not show the default value. It recognizes certain patterns of default-value inclusion, and handles them properly. 4. To understand how it does this, and how you can adapt it to other prompt patterns you might encounter, see function `icicle-handle-default-for-prompt', option `icicle-default-in-prompt-format-function', and variable `minibuffer-default-in-prompt-regexps' in standard library `minibuf-eldef.el'. >From the doc string of `icicle-handle-default-for-prompt': In the existing PROMPT before modification, recognizes inclusion of a default value according to these possible patterns: `minibuffer-default-in-prompt-regexps' "(default ___):" "(default is ___):" " [___] " That is the default behavior for recognizing defaults in prompts. My example fit that (it passed "(default DEF):"), and yours did not, hence the difference in behavior. To modify the default recognition of default-in-prompt patterns, you can customize `minibuffer-default-in-prompt-regexps' if you use library `minibuf-eldef.el' (good). A prompt matching one of the recognized patterns gets its default removed, first. And then, if argument INCLUDE to `icicle-handle-default-for-prompt' is non-nil (which it was in the bugged `icicle-read-string'), the default value is added back to the prompt using format "(___): ". So regardless of the input format of a prompt (provided it is recognized), the resulting prompt has the same, common format. Icicles always adds the default value in the same way (format). You can control this resulting format by customizing option `icicle-default-in-prompt-format-function', whose default value is (lambda (default) (format " (%s)" default)). The function, whatever it is, places the formatted default value just before the `:' in the prompt. Again, the default value is inserted (using this function) only if `icicle-default-value' is non-nil. (That was the bug - `icicle-default-value' was being ignored for `icicle-read-string'.) Note that even with the bug, if you had known about this option you could have made your example work by customizing the option to make it a no-op (no insertion): (lambda (def) ""). Dunno whether all of this explanation makes things clearer, but in any case the `icicle-read-string' bug that hardcoded adding the default to the prompt should be fixed now, which will make your example work. And all you should need to do, to inhibit insertion of the default, is to bind (or customize) `icicle-default-value' to nil. Sorry for the trouble.