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: read-from-minibuffer with default value string Date: Sun, 5 Dec 2010 19:39:09 -0800 Message-ID: References: <87zksk0xkk.fsf@guruji.demimonde> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1291606890 9404 80.91.229.12 (6 Dec 2010 03:41:30 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 6 Dec 2010 03:41:30 +0000 (UTC) To: "'Tyler Smith'" , Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 06 04:41:26 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PPRx7-0003n1-Cd for geh-help-gnu-emacs@m.gmane.org; Mon, 06 Dec 2010 04:41:25 +0100 Original-Received: from localhost ([127.0.0.1]:33544 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPRx6-00022L-Sp for geh-help-gnu-emacs@m.gmane.org; Sun, 05 Dec 2010 22:41:24 -0500 Original-Received: from [140.186.70.92] (port=44642 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPRwX-00020V-BW for help-gnu-emacs@gnu.org; Sun, 05 Dec 2010 22:40:50 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PPRwV-0001qI-V2 for help-gnu-emacs@gnu.org; Sun, 05 Dec 2010 22:40:49 -0500 Original-Received: from rcsinet10.oracle.com ([148.87.113.121]:59695) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PPRwV-0001q0-Ng for help-gnu-emacs@gnu.org; Sun, 05 Dec 2010 22:40:47 -0500 Original-Received: from rcsinet15.oracle.com (rcsinet15.oracle.com [148.87.113.117]) by rcsinet10.oracle.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id oB63eh2N024848 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 6 Dec 2010 03:40:44 GMT Original-Received: from acsmt355.oracle.com (acsmt355.oracle.com [141.146.40.155]) by rcsinet15.oracle.com (Switch-3.4.2/Switch-3.4.1) with ESMTP id oB61PuQp014356; Mon, 6 Dec 2010 03:40:42 GMT Original-Received: from abhmt014.oracle.com by acsmt353.oracle.com with ESMTP id 846040051291606760; Sun, 05 Dec 2010 19:39:20 -0800 Original-Received: from dradamslap1 (/10.159.238.104) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 05 Dec 2010 19:39:20 -0800 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <87zksk0xkk.fsf@guruji.demimonde> Thread-Index: AcuUu7soCi8eiX93ScOU7jw+tViSyAAMzjzA X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5994 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:75513 Archived-At: > I'm confused by the documentation for read-from-minibuffer. It says > that the INITIAL-CONTENTS argument is obsolete, but I can't > duplicate the functionality using DEFAULT-VALUE. You are correct that it does not _duplicate_ the functionality. > I'm working on a function that will query the user for input using > completing-read. If the value entered isn't in the collection used for > completing-read, then the user is asked if they want to add > the value to the collection. Note what you just said: "asked _if_" (i.e. whether). To me, that says `y-or-n-p'. What you really do however is ask them again to input the (same) KEY (and then for a corresponding CODE). You ask them for the (same) KEY as a proxy for directly asking _whether_ they want to add an entry for KEY. > (let* ((key (read-from-minibuffer (format "Journal > Title <%s>: " key) key)) > (code (read-from-minibuffer "Journal Bibtex Code: "))) > (push (list key code) collection-list) > (message "Pass <%s> to another function here" code)))))) > > This uses the obsolete INITIAL-CONTENTS argument. If I use the DEFAULT > value list, I either have to set the READ argument to nil, which means > that entering an empty string results in key being set to the empty > string rather than the default value; or I set READ to t, which means > that any text the user enters is treated as an expression, which > produces an error when the string contains a space. The strings will > often contain spaces, so this isn't good. > > How can I rewrite this to work without using INITIAL-CONTENTS? A few alternatives I can think of: 1. Use `read-string' with KEY as the DEFAULT-VALUE. This is likely what you want to do here. 2. Use `read-from-minibuffer' with INITIAL-CONTENTS, but also use a cons as HIST. That usage is not considered obsolete AFAIK. The doc string does suggest that _any_ use of this parameter is "obsolete" but it also mentions using it with a cons HIST value. And the Elisp manual does not say INITIAL-CONTENTS is "obsolete" at all - it says that it is "mostly deprecated" (equivocation), and it describes a use case where it is presumably not deprecated: Use of INITIAL-CONTENTS is mostly deprecated; we recommend using a non-`nil' value only in conjunction with specifying a cons cell for HIST. *Note Initial Input. That's not the same thing as being obsolete, and the mention of using a cons HIST seems to be outside of any deprecation/obsolescence. But see also node `Initial Input'. 3. Use `y-or-n-p' (or `yes-or-no-p') if you are not really letting users add a different KEY here from what they entered the first time (in `completing-read') and you just want to let them say _whether or not_ to add an entry with the _given_ KEY (you would then still read the CODE). IOW, you show them KEY in the `y-or-n-p' prompt, which asks for confirmation to add an entry. (4. You could even use `completing-read' with a singleton COLLECTION. You probably do not want to do that, but it is another alternative here.) FWIW, _personally_ (but who cares?) I do not consider INITIAL-CONTENTS to be obsolete. It provides _different_ behavior from a DEFAULT value (as you noticed). In particular, the value is inserted in the minibuffer, and that might be just what is wanted in some contexts. Emacs Dev opted for declaring INITIAL-CONTENTS obsolete and putting the default value inside prompts whenever they want to make it clear to users what the default is. Those are not quite the same thing. Since there is a difference in behaviors there can be uses for both. The reason given for this obsolescence/deprecation? From node `Initial Input': *We discourage use of a non-`nil' value for INITIAL*, because initial input is an intrusive interface. History lists and default values provide a much more convenient method to offer useful default inputs to the user. Intrusive? Maybe - clearly it offers you an editable value to start with. But convenience is in the eye of the user. If you have a key that empties the minibuffer (I use `M-k' - none is provided by default in vanilla Emacs), then it's pretty much a toss-up whether (a) a value is inserted initially and you sometimes remove it or (b) nothing is inserted and you sometimes use `M-n' to retrieve a value. I personally prefer to have even the DEFAULT value inserted in the minibuffer, because I often do want to edit it. I use `M-k' to clear it if I don't want it at all. I do that less on average than I would have to use `M-n' to retrieve a value to edit (or copy+paste from the prompt). That's me - but everyone is different. I don't think that one usage pattern should be considered so superior in general that the other should be deprecated. IMO, Emacs Dev should not have tried to be so controlling here - there was no need for that. But what do I know? [FWIW, in Icicles a user option controls the treatment of the DEFAULT value (when INTIAL-CONTENTS is nil or ""). Its possible values: nil - Do not insert default value or add it to prompt. t - Add default value to prompt. Do not insert it. `insert-start' - Insert default value and leave cursor at start. `insert-end' - Insert default value and leave cursor at end. `preselect-start' - Insert and preselect default value; leave cursor at beginning. `preselect-end' - Insert and preselect default value; leave cursor at end. My personal preference is `insert-end'. The default value is `t' (similar to vanilla Emacs behavior).]