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

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

Re: Reading file in emacs


From: Pascal J. Bourguignon
Subject: Re: Reading file in emacs
Date: Wed, 08 Dec 2010 15:15:42 -0000
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/23.2 (gnu/linux)

Qiang Guo <mcknight0219@gmail.com> writes:
> I'm wondering if there is a way to read the content of files, say, to a
> variable rather than a buffer ? Of course, one way to do
> this is first read file into buffer and then edit the
> buffer. 

If you need to have the content of a file in a variable, then you
could bind a buffer to a variable:

(let ((my-buffer (current-buffer)))
  (with-temp-buffer
     (insert "hi")
     (insert (with-current-buffer my-buffer (buffer-substring 1 3)))
     (list my-buffer (buffer-substring (point-min) (point-max)))))

--> (#<buffer *followup to Qiang Guo on gnu.emacs.help*> 
     #("hiNe" 2 4 (fontified t face message-header-name)))

The point is that the data structure optimized in emacs to store long
sequences of characters (or "bytes" since in emacs characters are
integers), is the buffer.  If you try to manipulate strings, you may
find it's slower than doing the equivalent in a buffer. (At least,
that's the common wisdom about emacs buffers vs strings, you could
benchmark it).


> Here comes my second question, how to process file
> in a byte-by-byte fashion, for instance, instead of editing
> a line of text, I'd like to edit directly their binary
> representations ?


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/


reply via email to

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