idomatic batch processing of text in emacs?

Posted by Stephen on Stack Overflow See other posts from Stack Overflow or by Stephen
Published on 2010-05-21T05:26:09Z Indexed on 2010/05/21 5:30 UTC
Read the original article Hit count: 347

Filed under:
|

In python, you might do something like

fout = open('out','w')
fin = open('in')
for line in fin:
    fout.write(process(line)+"\n")
fin.close()
fout.close()

(I think it would be similar in many other languages as well). In emacs lisp, would you do something like

(find-file 'out')
(setq fout (current-buffer)
(find-file 'in')
(setq fin (current-buffer)
(while moreLines
 (setq begin (point))
 (move-end-of-line 1)
 (setq line (buffer-substring-no-properties begin (point))
 ;; maybe
 (print (process line) fout)
 ;; or
 (save-excursion 
  (set-buffer fout)
  (insert (process line)))
 (setq moreLines (= 0 (forward-line 1))))
(kill-buffer fin)
(kill-buffer fout)

which I got inspiration (and code) from here. Or should I try something entirely different? And how to remove the "" from the print statement? Thanks!

© Stack Overflow or respective owner

Related posts about emacs

Related posts about emacs-lisp