From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: TheFlyingDutchman Newsgroups: gmane.emacs.help Subject: Re: how to get list of vectors with value from file content... Date: Thu, 2 Sep 2010 07:31:38 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <90f84f94-37e7-4dc7-ade3-5ef12ad6ce63@b4g2000pra.googlegroups.com> <2f5c2c80-a5da-4dfd-8102-44aca66b20e2@p37g2000pra.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1291864217 25306 80.91.229.12 (9 Dec 2010 03:10:17 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 9 Dec 2010 03:10:17 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 09 04:10:12 2010 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.69) (envelope-from ) id 1PQWtX-0001qy-42 for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 04:10:11 +0100 Original-Received: from localhost ([127.0.0.1]:52572 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQWiJ-0004yp-M1 for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 21:58:35 -0500 Original-Path: usenet.stanford.edu!postnews.google.com!u4g2000prn.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 74 Original-NNTP-Posting-Host: 75.36.152.5 Original-X-Trace: posting.google.com 1283437898 30204 127.0.0.1 (2 Sep 2010 14:31:38 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Thu, 2 Sep 2010 14:31:38 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: u4g2000prn.googlegroups.com; posting-host=75.36.152.5; posting-account=9bWHAAoAAAAxSFC_2O_ssTETNW9NhMbW User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.5; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; AskTbBT5/5.8.0.12304),gzip(gfe) Original-Xref: usenet.stanford.edu gnu.emacs.help:181080 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:76515 Archived-At: On Sep 2, 6:29=A0am, TheFlyingDutchman wrote: > > (1) here's how i get the file content for each file: > > > =A0 (find-file "findreplace_01_A.txt" ) (setq findreplace_01_A (buffer- > > string)) (kill-buffer ) > > =A0 (find-file "findreplace_01_B.txt" ) (setq findreplace_01_B (buffer- > > string)) (kill-buffer ) > > =A0 (find-file "findreplace_02_A.txt" ) (setq findreplace_02_A (buffer- > > string)) (kill-buffer ) > > =A0 (find-file "findreplace_02_B.txt" ) (setq findreplace_02_B (buffer- > > string)) (kill-buffer ) > > =A0 (find-file "findreplace_03_A.txt" ) (setq findreplace_03_A (buffer- > > string)) (kill-buffer ) > > =A0 (find-file "findreplace_03_B.txt" ) (setq findreplace_03_B (buffer- > > string)) (kill-buffer ) > > > seems a kludge to me. Is there a better way? > > With find-file, if the file doesn't exist (in this case it should) > there is no error. This way generates an error if a file is missing: > > =A0 (setq findreplace_01_A > =A0 =A0 =A0 (with-temp-buffer > =A0 =A0 =A0 =A0 =A0(insert-file-contents "findreplace_01_A.txt") > =A0 =A0 =A0 =A0 =A0(buffer-string) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 )) A function can be created to get a file string: (defun get-file-string (fileName) (let ( fileString ) (setq fileString (with-temp-buffer (insert-file-contents fileName) (buffer-string))))) allowing: (setq findreplace_01_A (get-file-string "findreplace_01_A.txt")) and a loop can be used with the function: (progn (defvar findReplacePairsList nil "A list of replacement pairs. Each element is a vector of 2 elements. Each element is a string, from a file content.") (let ( ( fileNames (vector "findreplace_01_A.txt" "findreplace_01_B.txt" "findreplace_02_A.txt" "findreplace_02_B.txt" "findreplace_03_A.txt" "findreplace_03_B.txt")) (fileStrings (make-vector 6 "")) (i 0 ) ) (while (< i 6) (aset fileStrings i (get-file-string (elt fileNames i))) (setq i (1+ i) ) ) (setq findReplacePairsList (list (vector (elt fileStrings 0) (elt fileStrings 1)) (vector (elt fileStrings 2) (elt fileStrings 3)) (vector (elt fileStrings 4) (elt fileStrings 5)) ))))