From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: lisp read-from-minibuffer propels deep questions Date: Mon, 02 Apr 2012 22:57:35 -0600 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1333429053 28361 80.91.229.3 (3 Apr 2012 04:57:33 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 3 Apr 2012 04:57:33 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Apr 03 06:57:32 2012 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 1SEvoB-00028w-TQ for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Apr 2012 06:57:32 +0200 Original-Received: from localhost ([::1]:54500 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SEvoB-0006vB-BQ for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Apr 2012 00:57:31 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:36551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SEvo4-0006v4-Bm for help-gnu-emacs@gnu.org; Tue, 03 Apr 2012 00:57:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SEvo2-0008P5-EL for help-gnu-emacs@gnu.org; Tue, 03 Apr 2012 00:57:23 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:51310) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SEvo2-0008Oz-7G for help-gnu-emacs@gnu.org; Tue, 03 Apr 2012 00:57:22 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1SEvnv-0001zF-Ma for help-gnu-emacs@gnu.org; Tue, 03 Apr 2012 06:57:15 +0200 Original-Received: from c-71-237-25-24.hsd1.co.comcast.net ([71.237.25.24]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 03 Apr 2012 06:57:15 +0200 Original-Received: from kevin.d.rodgers by c-71-237-25-24.hsd1.co.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 03 Apr 2012 06:57:15 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 84 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: c-71-237-25-24.hsd1.co.comcast.net User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.28) Gecko/20120306 Thunderbird/3.1.20 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:84280 Archived-At: On 4/2/12 8:01 PM, Xah Lee wrote: > slightly frustrated with emacs lisp read-from-minibuffer. > > Spent now about a hour on this. > > what i want i simple, like this: > > (read-from-minibuffer > (format "Directory (default %s):" default-directory) default- > directory ) > > prompt user to enter a dir, with default at current dir. > > however, according to inline doc of read-from-minibuffer, the second > arg for default input is obsolete. Instead, you have to use the 6th > arg. Quote: > > (read-from-minibuffer PROMPT&optional INITIAL-CONTENTS KEYMAP READ > HIST DEFAULT-VALUE INHERIT-INPUT-METHOD) > > the doc is long so i won't paste here. See it by calling “describe- > function”. > > Now, so i do: > > (read-from-minibuffer > (format "Directory (default %s):" default-directory) nil nil nil nil > default-directory) > > doesn't work. Read the doc again, it turns out that the 4th arg must > be t in order for the default value to work, else you get empty string > if the user just press Enter. > > So i do > > (read-from-minibuffer > (format "Directory (default %s):" default-directory) nil nil t nil > default-directory) > > woops! no go! because if the 4th arg is t, it means the input as a > string will be fed to lisp reader, then interpreted as a lisp object. > Hot damn. This means, if you want a string, you have to feed it > 「"\"mystring\""」. (the outter string makes it a lisp string to be fed > to lisp reader, then, the inner string gets you a lisp string object) > > So, now i have to do this: > > (read-from-minibuffer > (format "Directory (default %s):" default-directory) nil nil t nil > (format "\"%s\"" default-directory) ) > > But no! Because, now if user actually enter a value, e.g. type 「mary」, > lisp reader freaks out. Again, it doesn't undertand what the letter > sequence 「mary」 is. It wants a string 「"\"mary\""」. So, user will have > to actually type 「"mary"」 for this to work. > > WTF? > > This line is supposed to be done in 20 seconds. Now i've spent 40min > on this. Now, my mind wanders to the deep question of humanity…. The READ arg is not meant to work around the fact that read-from-minibuffer returns an empty string if the user does not enter any text. INITIAL-CONTENTS may be deprecated but it is not obsolete: it still works. Here are 3 alternatives: (read-from-minibuffer "Directory: " default-directory) (let ((directory (read-from-minibuffer (format "Directory (default %s): " default-directory) nil nil nil nil default-directory))) (if (equal directory "") default-directory directory)) (let ((insert-default-directory t)) (read-directory-name "Directory: " default-directory)) -- Kevin Rodgers Denver, Colorado, USA