help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there an ELisp function for reading file contents in a string?


From: Ted Zlatanov
Subject: Re: Is there an ELisp function for reading file contents in a string?
Date: Wed, 06 Feb 2008 12:22:24 -0600
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.50 (gnu/linux)

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]