From: TheFlyingDutchman <zzbbaadd@aol.com>
To: help-gnu-emacs@gnu.org
Subject: Re: how to get list of vectors with value from file content...
Date: Thu, 2 Sep 2010 07:31:38 -0700 (PDT) [thread overview]
Message-ID: <eebab69e-fdb6-4d2c-9da1-45c18f3eeae9@u4g2000prn.googlegroups.com> (raw)
In-Reply-To: 2f5c2c80-a5da-4dfd-8102-44aca66b20e2@p37g2000pra.googlegroups.com
On Sep 2, 6:29 am, TheFlyingDutchman <zzbba...@aol.com> wrote:
> > (1) here's how i get the file content for each file:
>
> > (find-file "findreplace_01_A.txt" ) (setq findreplace_01_A (buffer-
> > string)) (kill-buffer )
> > (find-file "findreplace_01_B.txt" ) (setq findreplace_01_B (buffer-
> > string)) (kill-buffer )
> > (find-file "findreplace_02_A.txt" ) (setq findreplace_02_A (buffer-
> > string)) (kill-buffer )
> > (find-file "findreplace_02_B.txt" ) (setq findreplace_02_B (buffer-
> > string)) (kill-buffer )
> > (find-file "findreplace_03_A.txt" ) (setq findreplace_03_A (buffer-
> > string)) (kill-buffer )
> > (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:
>
> (setq findreplace_01_A
> (with-temp-buffer
> (insert-file-contents "findreplace_01_A.txt")
> (buffer-string)
> ))
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))
))))
next prev parent reply other threads:[~2010-09-02 14:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-02 10:16 how to get list of vectors with value from file content Xah Lee
2010-09-02 11:15 ` Marc Mientki
2010-09-02 21:15 ` Xah Lee
2010-09-02 12:42 ` TheFlyingDutchman
2010-09-02 13:00 ` TheFlyingDutchman
2010-09-02 13:29 ` TheFlyingDutchman
2010-09-02 14:31 ` TheFlyingDutchman [this message]
2010-09-02 21:02 ` Xah Lee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=eebab69e-fdb6-4d2c-9da1-45c18f3eeae9@u4g2000prn.googlegroups.com \
--to=zzbbaadd@aol.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).