From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ismael Valladolid Torres Newsgroups: gmane.emacs.help Subject: Re: Dump file content into a variable, how to? Date: Tue, 19 Jun 2007 13:20:16 +0200 Message-ID: <20070619112016.GA3195@punkass.com> References: <20070619081728.GE3082@punkass.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7BIT X-Trace: sea.gmane.org 1182252049 17547 80.91.229.12 (19 Jun 2007 11:20:49 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 19 Jun 2007 11:20:49 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Juanma Barranquero Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jun 19 13:20:45 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1I0blH-0005mA-0v for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Jun 2007 13:20:39 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I0blG-0005Si-Gs for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Jun 2007 07:20:38 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I0bkz-0005SC-QG for help-gnu-emacs@gnu.org; Tue, 19 Jun 2007 07:20:21 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I0bkx-0005Rj-AQ for help-gnu-emacs@gnu.org; Tue, 19 Jun 2007 07:20:21 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I0bkx-0005Rg-0n for help-gnu-emacs@gnu.org; Tue, 19 Jun 2007 07:20:19 -0400 Original-Received: from tidos.tid.es ([193.145.240.2] helo=correo.tid.es) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1I0bkw-0005Fh-ND for help-gnu-emacs@gnu.org; Tue, 19 Jun 2007 07:20:18 -0400 Original-Received: from tid (filvit [192.168.48.202]) by tid.hi.inet (iPlanet Messaging Server 5.2 HotFix 2.14 (built Aug 8 2006)) with ESMTP id <0JJV004R6RHTT3@tid.hi.inet> for help-gnu-emacs@gnu.org; Tue, 19 Jun 2007 13:20:17 +0200 (MEST) Original-Received: from palmer.hi.inet ([10.95.14.0]) by tid.hi.inet (iPlanet Messaging Server 5.2 HotFix 2.14 (built Aug 8 2006)) with ESMTPS id <0JJV007PNRHT45@tid.hi.inet> for help-gnu-emacs@gnu.org; Tue, 19 Jun 2007 13:20:17 +0200 (MEST) Original-Received: from ismael by palmer.hi.inet with local (Exim 4.63) (envelope-from ) id 1I0bku-00019k-Bc; Tue, 19 Jun 2007 13:20:16 +0200 In-reply-to: Content-disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) X-detected-kernel: Solaris 8 (1) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:45165 Archived-At: Juanma Barranquero escribe: > On 6/19/07, Ismael Valladolid Torres wrote: > > >I want my .emacs to dired on launch a given directory. The name of the > >directory is stored into a file ~/.removable. So I need to "cat" the > >file content into a variable, then maybe do a file-directory-p and > >finally dired the directory. > > A simple way is > > (with-temp-buffer > (insert-file-contents "your-file" > (setq your-variable (buffer-string)) > ;;; your code here > ) > > If you need the literal contents of the file you can use > `insert-file-contents-literally' instead. There are a few more tricks, > but depends on what you intend to do. > > Here's a function to do what you requested. You may call it > interactively or just pass the filename as argument, like this > > (dired-from-file "~/.removable") > > or even > > (dired-from-file ".removable") > > (it defaults to ~/). It's more complex than strictly necessary because > I've opted to program quite defensively. > > (defun dired-from-file (file) > "Ejecuta `dired' en un directorio extraido de FILE." > (interactive "f") > (condition-case nil > (with-temp-buffer > (insert-file-contents (expand-file-name file "~/")) > (let ((dir (convert-standard-filename > (replace-regexp-in-string "\n$" "" (buffer-string))))) > (if (file-accessible-directory-p (directory-file-name dir)) > (dired dir) > (message "%S no accesible" dir)))) > (error (message "Error leyendo %S" file)))) > Code below did it: (when (file-readable-p (expand-file-name "~/.removable")) (with-temp-buffer (insert-file-contents (expand-file-name "~/.removable")) (setq doc (concat (replace-regexp-in-string "\n$" "" (buffer-string)) "/share/doc")) (dired doc))) Gracias. ;) Cordially, Ismael -- Ismael Valladolid Torres m. +34679156321 La media hostia j. ivalladt@gmail.com http://lamediahostia.blogspot.com/