This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

File reading

3 posts · 4937 views

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:
>>> f=open("btf001.srt")                                                                                      
>>> 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

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. http://www.findinglisp.com/blog/