[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#1939: suggestion: adding read-line function to elisp
From: |
xah lee |
Subject: |
bug#1939: suggestion: adding read-line function to elisp |
Date: |
Sat, 17 Jan 2009 10:13:51 -0800 |
summary:
i'd like to have a read-line function in elisp, that will read a
given file and return a list of lines.
The reason is that in almost all modern scripting langs (php, perl,
python, ruby), there's such a function, so that users can get a list
of lines of a file in about single line of code. Getting lines as
list is a very frequent need.
elisp is very suitable for tasks of text processing. So, having such
a convenience function seems appropriate.
Here's a implementation:
(defun read-lines (file)
"Return a list of lines in FILE."
(with-temp-buffer
(insert-file-contents file)
(split-string
(buffer-substring-no-properties 1 (point-max)) "\n" t)
)
)
Thanks.
The thought came from a recent newsgroup discussion in comp.lang.lisp
http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/
761fe827c8c9ea5e/
Here's a short article for some context:
• A Ruby Illustration of Lisp Problems
http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html
Xah
∑ http://xahlee.org/
☄
- bug#1939: suggestion: adding read-line function to elisp,
xah lee <=