File reading

Discussion of Emacs Lisp

File reading

Postby minibuffer » Tue Feb 22, 2011 3:23 am

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...)
Posts: 5
Joined: Mon Feb 21, 2011 4:55 pm

Re: File reading

Postby FAU » Tue Feb 22, 2011 12:21 pm

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.
Posts: 24
Joined: Tue Nov 02, 2010 2:47 am
Location: Edmonton, AB

Re: File reading

Postby findinglisp » Sat Jun 04, 2011 7:08 am

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.
Cheers, Dave
Slowly but surely the world is finding Lisp.
Posts: 440
Joined: Sat Jun 28, 2008 7:49 am
Location: Austin, TX

Return to Emacs Lisp

Who is online

Users browsing this forum: No registered users and 1 guest