unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Tyler Smith <tyler.smith@eku.edu>
To: help-gnu-emacs@gnu.org
Subject: read-from-minibuffer with default value string
Date: Sun, 05 Dec 2010 15:33:15 -0500	[thread overview]
Message-ID: <87zksk0xkk.fsf@guruji.demimonde> (raw)

Hi,

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.

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.

The following code works as I want it:

(setq collection-list
      '(("Advances in Ecological Research" "adv_ecol_res") 
	("Acta Oecologica" "acta_oecol") 
	("Acta Botanica Neerlandica" "acta_bot_neerl")))

;; Note that in my full code, collection-list contains three-element
;; lists, which is why I haven't used the normal (key . value) form of
;; normal alists.


(defun double-query ()
  (interactive)
  (let ((key (completing-read "Journal: " collection-list)))
    (if (setq code (cadr (assoc key collection-list)))
	(message "Pass <%s> to another function here" code)
      (if (y-or-n-p "Add to list?")
	  (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?

Thanks,

Tyler





             reply	other threads:[~2010-12-05 20:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-05 20:33 Tyler Smith [this message]
2010-12-06  3:39 ` read-from-minibuffer with default value string Drew Adams
2010-12-06 14:08   ` Tyler Smith
2010-12-06 15:49     ` Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zksk0xkk.fsf@guruji.demimonde \
    --to=tyler.smith@eku.edu \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).