From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Juanma Barranquero" Newsgroups: gmane.emacs.help Subject: Re: Dump file content into a variable, how to? Date: Tue, 19 Jun 2007 11:16:27 +0200 Message-ID: References: <20070619081728.GE3082@punkass.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1182244615 23968 80.91.229.12 (19 Jun 2007 09:16:55 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 19 Jun 2007 09:16:55 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: "Ismael Valladolid Torres" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jun 19 11:16:53 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 1I0ZpV-0006U1-37 for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Jun 2007 11:16:53 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I0ZpU-0007b8-6M for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Jun 2007 05:16:52 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I0Zp9-0007aR-G1 for help-gnu-emacs@gnu.org; Tue, 19 Jun 2007 05:16:31 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I0Zp7-0007Zu-Es for help-gnu-emacs@gnu.org; Tue, 19 Jun 2007 05:16:30 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I0Zp7-0007Zn-6X for help-gnu-emacs@gnu.org; Tue, 19 Jun 2007 05:16:29 -0400 Original-Received: from wx-out-0506.google.com ([66.249.82.227]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1I0Zp6-0002ZB-QT for help-gnu-emacs@gnu.org; Tue, 19 Jun 2007 05:16:29 -0400 Original-Received: by wx-out-0506.google.com with SMTP id h26so1921671wxd for ; Tue, 19 Jun 2007 02:16:28 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=rsC7sfS91wxnhBsM4iJsJ54E8sLHBNs3gCuH3HYnnW8J7/TMzQZy6gw2l/xqpNmifbxuqLgrqeYrL7e6Ni1tbb6mLCDBiRMdNVg7lu5DmOw8N1NW8SwAUFkT7FKKfBT3O6RhUwoVVtbUQHiDMZ2xvJQDW21RTMPTiirmFKiNzBA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=cK7epJdVBgW4vDjHfguCk5VRlky9F6HuN+6Em6idBIeF9dTKtyCYPakqscbAIqOntjwBZko9Z3C7KMa37wIFzCwFGBifMnUZrUkXu4X/mjHx6SZTjHBnoZ09dCFQHCdOY76bp0Mq1fqggZVeoj4nhD+2hy7DKFqfs6/0zaJL1cY= Original-Received: by 10.90.113.20 with SMTP id l20mr4561095agc.1182244588100; Tue, 19 Jun 2007 02:16:28 -0700 (PDT) Original-Received: by 10.90.87.8 with HTTP; Tue, 19 Jun 2007 02:16:27 -0700 (PDT) In-Reply-To: <20070619081728.GE3082@punkass.com> Content-Disposition: inline X-detected-kernel: Linux 2.4-2.6 (Google crawlbot) 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:45162 Archived-At: 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)))) Good luck, Juanma