GNU bug report logs -
#1939
suggestion: adding read-line function to elisp
Previous Next
Reported by: xah lee <xah <at> xahlee.org>
Date: Sat, 17 Jan 2009 18:20:02 UTC
Severity: wishlist
Done: Chong Yidong <cyd <at> stupidchicken.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
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/
☄
This bug report was last modified 16 years and 186 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.