Page 1 of 1

File reading

PostPosted: Tue Feb 22, 2011 3:23 am
by minibuffer
Hello! I'm starting Emacs Lisp, and my question is a basic question about file handling, how is it done in Elisp?

I'm coming from Python, so my problem is about the following:

Code: Select all
>>> f=open("")                                                                                     
>>> lines=f.readlines()   
>>> print lines[9:13]                                                                                       
['3\r\n', '00:01:36,300 --> 00:01:38,200\r\n', '{y:i}Oktober \xe4r inventeringstid.\r\n', '\r\n']             

How is this kind of simple file reading done in Elisp? (Open the file, read the lines, print the lines from 9 to 12...)

Re: File reading

PostPosted: Tue Feb 22, 2011 12:21 pm
by FAU
I think you have to slurp in the whole file via insert-file-contents into a buffer.

Check out Xah's excellent Emacs Lisp Tutorials:

You might want to have a look at this That should answer your question.

Re: File reading

PostPosted: Sat Jun 04, 2011 7:08 am
by findinglisp
Yes. In Emacs Lisp, you pretty much need to ignore the idea of files. The procedure is to load files into buffers and then examine the contents of the buffer. When you are done, possibly having modified the buffer, then you write the buffer back to a file.