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: lisp read-from-minibuffer propels deep questions Date: Mon, 2 Apr 2012 22:35:49 -0700 Message-ID: <4AAE721518A14E20A72E8C545C6A6435@us.oracle.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1333431377 9389 80.91.229.3 (3 Apr 2012 05:36:17 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 3 Apr 2012 05:36:17 +0000 (UTC) To: "'Xah Lee'" , Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Apr 03 07:36:16 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 1SEwPb-0007Rx-FG for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Apr 2012 07:36:11 +0200 Original-Received: from localhost ([::1]:34147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SEwPa-0004gY-Om for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Apr 2012 01:36:10 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:39016) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SEwPP-0004Tb-PI for help-gnu-emacs@gnu.org; Tue, 03 Apr 2012 01:36:01 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SEwPN-0008VC-Oi for help-gnu-emacs@gnu.org; Tue, 03 Apr 2012 01:35:59 -0400 Original-Received: from rcsinet15.oracle.com ([148.87.113.117]:39480) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SEwPN-0008Uu-Ht for help-gnu-emacs@gnu.org; Tue, 03 Apr 2012 01:35:57 -0400 Original-Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by rcsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q335Zrmp006613 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 3 Apr 2012 05:35:54 GMT Original-Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q335Zqgk003357 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 3 Apr 2012 05:35:53 GMT Original-Received: from abhmt111.oracle.com (abhmt111.oracle.com [141.146.116.63]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q335ZqBa003897; Tue, 3 Apr 2012 00:35:52 -0500 Original-Received: from dradamslap1 (/10.159.53.212) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 02 Apr 2012 22:35:52 -0700 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: Thread-Index: Ac0RPkb5CuObHfulTP+osn4+luOJswAFR20Q X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-Source-IP: ucsinet21.oracle.com [156.151.31.93] X-CT-RefId: str=0001.0A090207.4F7A8C3A.0072,ss=1,re=0.000,fgs=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) X-Received-From: 148.87.113.117 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:84282 Archived-At: > (read-from-minibuffer > (format "Directory (default %s):" default-directory) > default-directory ) > > prompt user to enter a dir, with default at current dir. Try `read-directory-name'. (Its doc too is a bit confusing, IMO.) Here are a couple ways to read the name of a directory. The first requires the input to be an existing directory; the second does not. (expand-file-name (read-directory-name (format "Directory (default %s): " default-directory) default-directory default-directory t)) (let ((insert-default-directory t)) (read-directory-name "Directory: " default-directory)) You can also use `read-file-name'. Both of those functions let the user use completion: they are file/dir-name aware. `read-from-minibuffer' on the other hand just reads a string (and optionally calls the Lisp reader on it). > however, according to inline doc of read-from-minibuffer, the second > arg for default input is obsolete. (FWIW, I disagree with that pronouncement by Emacs Devel, but so be it.) The doc actually says, at the very end, that you can use the second arg if the HIST arg is a cons, i.e., is a non-nil history list. Example: (read-from-minibuffer "Directory: " default-directory nil nil file-name-history) or just (read-from-minibuffer "Directory: " default-directory) if you don't care about using the file-name history (`M-p'). If you avoid using the "deprecated" INITIAL-CONTENTS arg (like a good boy), then you must test the string input by the user, and if it is "" then return DEFAULT-VALUE: (let ((input (read-from-minibuffer (format "Directory (default %s): " default-directory) nil nil nil nil default-directory))) (when (string= "" input) (setq input default-directory)) input) But again, `read-from-minibuffer' does not know anything about file or dir names or how to complete them (unless you jump through hoops, providing it a file/dir-name completion keymap). > Instead, you have to use the 6th arg. Nope, as you discovered, nothing gets inserted in the minibuffer, and empty input means "" is returned. > 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. Nope, as you discovered. That's something else again. > 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) No, don't even think of going down that road. `read-from-minibuffer' is a very general function, which is one reason its doc is confusing (not that that is an excuse). It is used to implement `completing-read', `read-file-name', and so on. The 4th arg is only for situations where you want to get user input as a Lisp sexp and then evaluate it. > But no! ... 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.. Try using `read-file-name' or `read-directory-name'. They should help.