From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: John Mastro Newsgroups: gmane.emacs.help Subject: Re: How to handle default value in read-string? Date: Mon, 3 Aug 2015 14:17:34 -0700 Message-ID: References: <87k2tc9jeu.fsf@mbork.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1438636689 16794 80.91.229.3 (3 Aug 2015 21:18:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 3 Aug 2015 21:18:09 +0000 (UTC) To: Help Gnu Emacs mailing list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Aug 03 23:18:08 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 1ZMN7W-0000QV-Bx for geh-help-gnu-emacs@m.gmane.org; Mon, 03 Aug 2015 23:18:06 +0200 Original-Received: from localhost ([::1]:60523 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMN7V-00061l-JB for geh-help-gnu-emacs@m.gmane.org; Mon, 03 Aug 2015 17:18:05 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMN7L-00060p-Vw for help-gnu-emacs@gnu.org; Mon, 03 Aug 2015 17:17:56 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZMN7L-0003dm-5s for help-gnu-emacs@gnu.org; Mon, 03 Aug 2015 17:17:55 -0400 Original-Received: from mail-ob0-x234.google.com ([2607:f8b0:4003:c01::234]:34819) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMN7L-0003da-0P for help-gnu-emacs@gnu.org; Mon, 03 Aug 2015 17:17:55 -0400 Original-Received: by obbop1 with SMTP id op1so109056709obb.2 for ; Mon, 03 Aug 2015 14:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=RLyKrRbPysdCZzVlT23k873zsu0ENb8pMX+DrrQBUSg=; b=bRcsujBTtJzangEFhoA7xB3wmmixq+7PQ4C+vICau5bX/P4JXNHUwoIjIQYgnntV1N qtrI4MQcCGt0gf6B0zXu82Vs1WrPg+MG9qN8Kbcb7FfsLaUS9aErqr+GTMwH9JmU3zzt ljxMGc5Vi+8tAHzm97aO0upEOYP0+skLEnunKdcPHJAyNxQr8+xdFa9A2KBdqJsPfRGM WD6juqUU1pGj1mCbGB0EUEGBEwClQ9WMOfvZvWyEYdmR2x7mpMLlSYj2UXMY1ucReO6b O8ikKVoSp4g5eBqsRlBw4CEUsrSOYm83/zZ4hicG04bSR1Hwzf1ZahwPQlICzB+XB45H 0SAQ== X-Received: by 10.182.112.163 with SMTP id ir3mr114708obb.44.1438636674055; Mon, 03 Aug 2015 14:17:54 -0700 (PDT) Original-Received: by 10.76.168.70 with HTTP; Mon, 3 Aug 2015 14:17:34 -0700 (PDT) In-Reply-To: <87k2tc9jeu.fsf@mbork.pl> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c01::234 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:106223 Archived-At: > I'd like read-string to somehow indicate the default value. A natural > idea is to include it in the prompt, for example having a prompt like > > (format "Foo (%s): " default) > > However, Icicles' version of read-string already does exactly that, so > for Icicles users this would be superfluous. > > So here's the question: is there a better way than just have a prompt of > > (if icicle-mode (don't-include-default) (do-include-default))? There's no getting around that you'll need a condition somewhere. However, you can of course wrap it up in a helper function, so you're not repeating the condition every time you use `read-string'. (defun my-read-string (prompt &optional ...) (unless (bound-and-true-p icicle-mode) (setq prompt (concat prompt " (%s)" default))) (read-string prompt ...)) You could use advice to do the same thing but I don't think it would be an improvement in this case. -- john