* How to properly parse a buffer into a list ?
@ 2012-06-11 13:15 Philippe M. Coatmeur
2012-06-11 13:17 ` Pascal J. Bourguignon
2012-06-11 13:21 ` Ralf Fassel
0 siblings, 2 replies; 5+ messages in thread
From: Philippe M. Coatmeur @ 2012-06-11 13:15 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to properly parse a buffer into a list ?
2012-06-11 13:15 How to properly parse a buffer into a list ? Philippe M. Coatmeur
@ 2012-06-11 13:17 ` Pascal J. Bourguignon
2012-06-11 17:46 ` Philippe M. Coatmeur
2012-06-11 17:50 ` Philippe M. Coatmeur
2012-06-11 13:21 ` Ralf Fassel
1 sibling, 2 replies; 5+ messages in thread
From: Pascal J. Bourguignon @ 2012-06-11 13:17 UTC (permalink / raw)
To: help-gnu-emacs
Philippe M. Coatmeur <philippe.coatmeur@gmail.com> writes:
> Hi ; I have this perl-script that prints email elements separated by
> the string : "|_|".
If you could modify it so that it prints a sexp, it would be easier to
read it in emacs.
(("abc" "@" "example" "com")
("def" "@" "example" "com"))
you could then just use:
(with-current-buffer buf
(goto-char (point-min))
(read buf))
> 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..?
How do you separate email addresses then?
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to properly parse a buffer into a list ?
2012-06-11 13:15 How to properly parse a buffer into a list ? Philippe M. Coatmeur
2012-06-11 13:17 ` Pascal J. Bourguignon
@ 2012-06-11 13:21 ` Ralf Fassel
1 sibling, 0 replies; 5+ messages in thread
From: Ralf Fassel @ 2012-06-11 13:21 UTC (permalink / raw)
To: help-gnu-emacs
* Philippe M. Coatmeur <philippe.coatmeur@gmail.com>
| But it always returns "string not found" (when I explicitly run
| (re-search-forward "|_|") in said buffer it founds it)
I'd guess the try after the last match returns the error.
Try using the 'noerror' flag of 're-search-forward' (or plain
'search-forward', since you're not using regexps anyway-).
R'
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to properly parse a buffer into a list ?
2012-06-11 13:17 ` Pascal J. Bourguignon
@ 2012-06-11 17:46 ` Philippe M. Coatmeur
2012-06-11 17:50 ` Philippe M. Coatmeur
1 sibling, 0 replies; 5+ messages in thread
From: Philippe M. Coatmeur @ 2012-06-11 17:46 UTC (permalink / raw)
To: help-gnu-emacs
At Mon, 11 Jun 2012 15:17:54 +0200,
Pascal J. Bourguignon wrote:
>
> Philippe M. Coatmeur <philippe.coatmeur@gmail.com> writes:
>
> > Hi ; I have this perl-script that prints email elements separated by
> > the string : "|_|".
>
> If you could modify it so that it prints a sexp, it would be easier to
> read it in emacs.
>
> (("abc" "@" "example" "com")
> ("def" "@" "example" "com"))
>
> you could then just use:
>
> (with-current-buffer buf
> (goto-char (point-min))
> (read buf))
Simple, brilliant, bravo Pascal :) (Damnit, if it was'nt for the
second "i" in "brilliant", this sentence would be readable in both
english and french :( )
>
>
> > 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..?
>
> How do you separate email addresses then?
Well I overlooked this problem, but your solution solved it even
before we were introduced ;)
>
>
> --
> __Pascal Bourguignon__ http://www.informatimago.com/
> A bad day in () is better than a good day in {}.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to properly parse a buffer into a list ?
2012-06-11 13:17 ` Pascal J. Bourguignon
2012-06-11 17:46 ` Philippe M. Coatmeur
@ 2012-06-11 17:50 ` Philippe M. Coatmeur
1 sibling, 0 replies; 5+ messages in thread
From: Philippe M. Coatmeur @ 2012-06-11 17:50 UTC (permalink / raw)
To: help-gnu-emacs
At Mon, 11 Jun 2012 15:17:54 +0200,
Pascal J. Bourguignon wrote:
>
> Philippe M. Coatmeur <philippe.coatmeur@gmail.com> writes:
>
> > Hi ; I have this perl-script that prints email elements separated by
> > the string : "|_|".
>
> If you could modify it so that it prints a sexp, it would be easier to
> read it in emacs.
>
> (("abc" "@" "example" "com")
> ("def" "@" "example" "com"))
>
> you could then just use:
>
> (with-current-buffer buf
> (goto-char (point-min))
> (read buf))
>
Simple & brilliant, thx Pascal ; Way to go from 13 to 5 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..?
>
> How do you separate email addresses then?
I overlokeed this problem, but your solution solved it before we were
even introduced ;)
>
>
> --
> __Pascal Bourguignon__ http://www.informatimago.com/
> A bad day in () is better than a good day in {}.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-06-11 17:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-11 13:15 How to properly parse a buffer into a list ? Philippe M. Coatmeur
2012-06-11 13:17 ` Pascal J. Bourguignon
2012-06-11 17:46 ` Philippe M. Coatmeur
2012-06-11 17:50 ` Philippe M. Coatmeur
2012-06-11 13:21 ` Ralf Fassel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).