From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Hansen Newsgroups: gmane.emacs.help Subject: Re: Efficiently checking the initial contents of a file Date: Fri, 16 May 2008 13:12:58 +0200 Organization: disorganized Message-ID: <873aoi5wp1.fsf@localhorst.mine.nu> References: <5f8b772a-e2ed-468c-89b3-2d9e40ed132b@m3g2000hsc.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1210937156 18019 80.91.229.12 (16 May 2008 11:25:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 16 May 2008 11:25:56 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri May 16 13:26:29 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 1Jwy4r-0006RL-QT for geh-help-gnu-emacs@m.gmane.org; Fri, 16 May 2008 13:26:22 +0200 Original-Received: from localhost ([127.0.0.1]:53062 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jwy48-0007b4-Aq for geh-help-gnu-emacs@m.gmane.org; Fri, 16 May 2008 07:25:36 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Jwy3f-0007TE-Go for help-gnu-emacs@gnu.org; Fri, 16 May 2008 07:25:07 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Jwy3d-0007Rt-Tk for help-gnu-emacs@gnu.org; Fri, 16 May 2008 07:25:06 -0400 Original-Received: from [199.232.76.173] (port=33570 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jwy3d-0007Rj-Jz for help-gnu-emacs@gnu.org; Fri, 16 May 2008 07:25:05 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:43460 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Jwy3d-0006S6-3c for help-gnu-emacs@gnu.org; Fri, 16 May 2008 07:25:05 -0400 Original-Received: from root by ciao.gmane.org with local (Exim 4.43) id 1Jwy3b-0004rl-4T for help-gnu-emacs@gnu.org; Fri, 16 May 2008 11:25:03 +0000 Original-Received: from e178059088.adsl.alicedsl.de ([85.178.59.88]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 16 May 2008 11:25:03 +0000 Original-Received: from david.hansen by e178059088.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 16 May 2008 11:25:03 +0000 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Original-Lines: 16 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: e178059088.adsl.alicedsl.de Mail-Copies-To: nobody User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:xdhjQZ6f9uiOM22x8KsDDbc7vyI= X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) 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:54052 Archived-At: On Fri, 16 May 2008 03:16:13 -0700 (PDT) Nordlöw wrote: > How can I efficiently using pure emacs-lisp (without calling any > external process) investigate the first bytes of a file? > > My guess is > - Open parts of the file into a buffer or string. > - Alt 1. Switch to the buffer and do things. (with-temp-buffer ;; Read the first 42 characters (not bytes) into the temp buffer. (insert-file-contents filename nil 0 42) ;; Do whatever you want to do here. ) David