help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: break a chunk of text into a list of lines


From: Xah
Subject: Re: break a chunk of text into a list of lines
Date: Fri, 14 Nov 2008 11:33:22 -0800 (PST)
User-agent: G2/1.0

On Nov 14, 5:24 am, Matt Price <address@hidden> wrote:
> I have a python script that queries my evolution database and returns a
> series of lines, with one address per line:
>
> ...
>
> is there a simple way
> to take each line of a text block and turn it into a list of lines?

if your text is already a string, then you can use split-string to
turn it into a list, by using “\n” as separator.

You can turn a block of text into a string by using buffer-substring-
no-properties.

alternatively, the following i wrote in my early lisp day that does
what you want. I still use it.

(defun grab-lines (n)
"Delete the next n lines and return a list
where each element is a line."
(interactive)
(move-beginning-of-line 1)
(let (t1 t2 cl (lines '()))
  (dotimes (x n)
    (progn
      (setq t1 (point))
      (move-end-of-line nil)
      (setq t2 (point))
      (setq cl (buffer-substring-no-properties t1 t2))
      (delete-region t1 t2)
      (delete-char 1)
      (push cl lines)
      )
    )
  (setq lines (reverse lines))
;  (prin1 lines (current-buffer))
))

for some detail about this code, see:

• Elisp Lesson: Writing a google-earth Function
http://xahlee.org/emacs/google-earth.html

  Xah
∑ http://xahlee.org/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]