unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: xah lee <xah@xahlee.org>
To: bug-gnu-emacs@gnu.org
Subject: bug#1939: suggestion: adding read-line function to elisp
Date: Sat, 17 Jan 2009 10:13:51 -0800	[thread overview]
Message-ID: <421D26F9-3257-44EE-97B0-A7276A97AD73@xahlee.org> (raw)

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/

             reply	other threads:[~2009-01-17 18:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-17 18:13 xah lee [this message]
2009-01-18  5:48 ` bug#1939: suggestion: adding read-line function to elisp Juanma Barranquero
     [not found] ` <mailman.5150.1232258617.26697.bug-gnu-emacs@gnu.org>
2009-01-20 18:29   ` Ted Zlatanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=421D26F9-3257-44EE-97B0-A7276A97AD73@xahlee.org \
    --to=xah@xahlee.org \
    --cc=1939@emacsbugs.donarmstrong.com \
    --cc=bug-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).