[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to properly parse a buffer into a list ?
From: |
Philippe M . Coatmeur |
Subject: |
How to properly parse a buffer into a list ? |
Date: |
Mon, 11 Jun 2012 13:15:37 +0000 |
User-agent: |
Wanderlust/2.15.9 (Almost Unreal) Emacs/24.1 Mule/6.0 (HANACHIRUSATO) |
Hi ; I have this perl-script that prints email elements separated by
the string : "|_|".
When I start-process-shell-command it I get a buffer containing my
elements, and I then parse this buffer using this function :
(defun buffer-to-list (buf)
"Make & return a list (of lists) LINES from lines in a buffer BUF"
(with-current-buffer buf
(save-excursion
(goto-char (point-min))
(let ((lines '()))
(while (not (eobp))
(push
(split-string
(buffer-substring (point) (point-at-eol)) "\|_\|")
lines)
(beginning-of-line 2))
lines))))
Problem is, this function moves in terms of lines (it puts evey single
line in a list cell), but my elements can easily span over several
lines, and I'd still wouldlike one such element to be a single list
cell..? I'm trying to simplify it to ignore the notion of line, and
just search for the separator string, like this :
(with-current-buffer buf
(goto-char (point-min))
(let ((cells '()))
(while (not (eobp))
(push
(buffer-substring (point) (re-search-forward "|_|"))
cells))
cells))
But it always returns "string not found" (when I explicitly run
(re-search-forward "|_|") in said buffer it founds it) so apparently
I'm not positioning the point where it should be, so my question
really is : What is the mecanics of search-looping through elements
between a separator string ?
Philippe
- How to properly parse a buffer into a list ?,
Philippe M . Coatmeur <=