* Is there an ELisp function for reading file contents in a string?
@ 2008-02-06 13:11 stephan.zimmer
2008-02-06 15:13 ` Juanma Barranquero
[not found] ` <mailman.7038.1202310789.18990.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 5+ messages in thread
From: stephan.zimmer @ 2008-02-06 13:11 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
does anybody know whether there is a function in elisp that just reads
the contents of a text file into a string?
So far, I haven't found anything that could be related to that. The
only, yet not very charming, possibility that I currently see is to
use the "insert-file" function in combination with the "buffer-
(sub)string" function and later erase the inserted file contents
again.
Thanks very much,
Stephan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Is there an ELisp function for reading file contents in a string?
2008-02-06 13:11 Is there an ELisp function for reading file contents in a string? stephan.zimmer
@ 2008-02-06 15:13 ` Juanma Barranquero
[not found] ` <mailman.7038.1202310789.18990.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 5+ messages in thread
From: Juanma Barranquero @ 2008-02-06 15:13 UTC (permalink / raw)
To: stephan.zimmer; +Cc: help-gnu-emacs
On Feb 6, 2008 2:11 PM, <stephan.zimmer@googlemail.com> wrote:
> The
> only, yet not very charming, possibility that I currently see is to
> use the "insert-file" function in combination with the "buffer-
> (sub)string" function and later erase the inserted file contents
> again.
Why "not charming"? You don't really need to erase the contents afterwards:
(defun file-as-string (file &optional beg end)
(with-temp-buffer
(insert-file-contents file nil beg end)
(buffer-string)))
What is the problem with that?
Juanma
^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <mailman.7038.1202310789.18990.help-gnu-emacs@gnu.org>]
* Re: Is there an ELisp function for reading file contents in a string?
[not found] ` <mailman.7038.1202310789.18990.help-gnu-emacs@gnu.org>
@ 2008-02-06 16:07 ` stephan.zimmer
2008-02-06 18:22 ` Ted Zlatanov
1 sibling, 0 replies; 5+ messages in thread
From: stephan.zimmer @ 2008-02-06 16:07 UTC (permalink / raw)
To: help-gnu-emacs
Juanma,
thanks a lot! I just started with elisp and was not aware of the "with-
temp-buffer" construction. This is exactly what I need.
Best,
Stephan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Is there an ELisp function for reading file contents in a string?
[not found] ` <mailman.7038.1202310789.18990.help-gnu-emacs@gnu.org>
2008-02-06 16:07 ` stephan.zimmer
@ 2008-02-06 18:22 ` Ted Zlatanov
2008-02-06 22:52 ` Juanma Barranquero
1 sibling, 1 reply; 5+ messages in thread
From: Ted Zlatanov @ 2008-02-06 18:22 UTC (permalink / raw)
To: help-gnu-emacs
On Wed, 6 Feb 2008 16:13:01 +0100 "Juanma Barranquero" <lekktu@gmail.com> wrote:
JB> On Feb 6, 2008 2:11 PM, <stephan.zimmer@googlemail.com> wrote:
>> The only, yet not very charming, possibility that I currently see is
>> to use the "insert-file" function in combination with the "buffer-
>> (sub)string" function and later erase the inserted file contents
>> again.
JB> Why "not charming"? You don't really need to erase the contents afterwards:
JB> (defun file-as-string (file &optional beg end)
JB> (with-temp-buffer
JB> (insert-file-contents file nil beg end)
JB> (buffer-string)))
JB> What is the problem with that?
I would suggest to the OP that he may also want to look at the
coding-system-for-read variable, in case the default coding system is
not what he needs (I've run into problems there).
insert-file-contents-literally might also be a good choice if
appropriate.
Ted
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Is there an ELisp function for reading file contents in a string?
2008-02-06 18:22 ` Ted Zlatanov
@ 2008-02-06 22:52 ` Juanma Barranquero
0 siblings, 0 replies; 5+ messages in thread
From: Juanma Barranquero @ 2008-02-06 22:52 UTC (permalink / raw)
To: Ted Zlatanov; +Cc: help-gnu-emacs
On Feb 6, 2008 7:22 PM, Ted Zlatanov <tzz@lifelogs.com> wrote:
> I would suggest to the OP that he may also want to look at the
> coding-system-for-read variable, in case the default coding system is
> not what he needs (I've run into problems there).
> insert-file-contents-literally might also be a good choice if
> appropriate.
Yes. I didn't want to complicate the problem with coding systems and
whatnot, but certainly the OP would be wise to look at the docs and
adapt it to his needs.
Juanma
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-02-06 22:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-06 13:11 Is there an ELisp function for reading file contents in a string? stephan.zimmer
2008-02-06 15:13 ` Juanma Barranquero
[not found] ` <mailman.7038.1202310789.18990.help-gnu-emacs@gnu.org>
2008-02-06 16:07 ` stephan.zimmer
2008-02-06 18:22 ` Ted Zlatanov
2008-02-06 22:52 ` Juanma Barranquero
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.