From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.help Subject: Re: Is there an ELisp function for reading file contents in a string? Date: Wed, 06 Feb 2008 12:22:24 -0600 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <86zlue9c7z.fsf@lifelogs.com> References: <2cc58ccd-001d-42bc-ad4f-0824204ffc5a@i12g2000prf.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1202333674 14963 80.91.229.12 (6 Feb 2008 21:34:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 6 Feb 2008 21:34:34 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Feb 06 22:34:53 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JMruq-0003R4-5Y for geh-help-gnu-emacs@m.gmane.org; Wed, 06 Feb 2008 22:34:48 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JMruN-00082S-O9 for geh-help-gnu-emacs@m.gmane.org; Wed, 06 Feb 2008 16:34:19 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!goblin1!goblin.stu.neva.ru!news.albasani.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 24 Original-X-Trace: news.albasani.net FHYnw1d0EZ9MEG8+ObnTIZzccnNtBXxYchKc1FWBZ1BEwPPJ6QTr7oqLZOS5AvKTvS5vus+DFWQTwzkaTIeMrO2OjjxwT0DFua+M9u7iCgANkzln/EddgXWyJu+zApnn Original-X-Complaints-To: abuse@albasani.net Original-NNTP-Posting-Date: Wed, 6 Feb 2008 18:20:43 +0000 (UTC) X-User-ID: Q/k3AWMZyarbeZdyzQzLKLj61DFbOG0Tn5/a+30Q5VA= X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" Cancel-Lock: sha1:PmXXLqpqYIjOfSdnSK61Z38ewbc= sha1:QS2i7dA32vPgmTuPBDw2CFMiPDU= User-Agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.50 (gnu/linux) X-NNTP-Posting-Host: 6yxnrhvTFJV6fCE/QlgSBtnnSMnXjEy4Dx5u3kmgMEM= Original-Xref: shelby.stanford.edu gnu.emacs.help:155888 X-Mailman-Approved-At: Wed, 06 Feb 2008 16:31:32 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:51270 Archived-At: On Wed, 6 Feb 2008 16:13:01 +0100 "Juanma Barranquero" wrote: JB> On Feb 6, 2008 2:11 PM, wrote: >> The only, yet not very charming, possibility that I currently see is >> to use the "insert-file" function in combination with the "buffer- >> (sub)string" function and later erase the inserted file contents >> again. JB> Why "not charming"? You don't really need to erase the contents afterwards: JB> (defun file-as-string (file &optional beg end) JB> (with-temp-buffer JB> (insert-file-contents file nil beg end) JB> (buffer-string))) JB> What is the problem with that? I would suggest to the OP that he may also want to look at the coding-system-for-read variable, in case the default coding system is not what he needs (I've run into problems there). insert-file-contents-literally might also be a good choice if appropriate. Ted