Skip to content

Instantly share code, notes, and snippets.

@chenfengyuan
Created July 30, 2012 14:15
Show Gist options
  • Save chenfengyuan/3207186 to your computer and use it in GitHub Desktop.
Save chenfengyuan/3207186 to your computer and use it in GitHub Desktop.
(defun split-per-3-lines (directory prefix suffix)
(interactive
(let (d p s)
(setq d (read-directory-name "Directory : "))
(setq p (read-string "prefix : "))
(setq s (read-string "suffix : "))
(list d p s)))
(save-excursion
(goto-char (point-min))
(let ((triplets
(loop
with pre = 1
for i from 0
do (forward-line 3)
collect (list pre (point) i)
do (forward-line)
do (setq pre (point))
until (= (point) (point-max)))))
(dolist (triplet triplets)
(let ((s (car triplet))
(e (cadr triplet))
(i (caddr triplet)))
(write-region s e (format "%s/%s%06d%s.txt" directory prefix i suffix)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment