all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* 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

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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.