[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 <matt.pr...@utoronto.ca> 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/
☄
- starting an external command from emacs, Matt Price, 2008/11/12
- Re: starting an external command from emacs, Xah, 2008/11/13
- Message not available
- Message not available
- Message not available
- Re: break a chunk of text into a list of lines, Andreas Politz, 2008/11/14
- interactive function: generate tab-completion list with another function, Matt Price, 2008/11/15
- syntax: anonymous vs. named functions, Matt Price, 2008/11/15
- RE: syntax: anonymous vs. named functions, Drew Adams, 2008/11/16
- RE: syntax: anonymous vs. named functions, Matt Price, 2008/11/16
- RE: syntax: anonymous vs. named functions, Drew Adams, 2008/11/16
- Message not available
- Re: syntax: anonymous vs. named functions, Andreas Politz, 2008/11/17