help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

read-from-minibuffer with default value string


From: Tyler Smith
Subject: read-from-minibuffer with default value string
Date: Sun, 05 Dec 2010 15:33:15 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]