all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* read-from-minibuffer with default value string
@ 2010-12-05 20:33 Tyler Smith
  2010-12-06  3:39 ` Drew Adams
  0 siblings, 1 reply; 4+ messages in thread
From: Tyler Smith @ 2010-12-05 20:33 UTC (permalink / raw)
  To: help-gnu-emacs

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





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-12-06 15:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-05 20:33 read-from-minibuffer with default value string Tyler Smith
2010-12-06  3:39 ` Drew Adams
2010-12-06 14:08   ` Tyler Smith
2010-12-06 15:49     ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.