all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Juanma Barranquero" <lekktu@gmail.com>
To: Nordlöw <per.nordlow@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Efficiently checking the initial contents of a file
Date: Fri, 16 May 2008 13:08:13 +0200	[thread overview]
Message-ID: <f7ccd24b0805160408n5ea97303oa02bc127435b2c3a@mail.gmail.com> (raw)
In-Reply-To: <5f8b772a-e2ed-468c-89b3-2d9e40ed132b@m3g2000hsc.googlegroups.com>

On Fri, May 16, 2008 at 12:16 PM, Nordlöw <per.nordlow@gmail.com> 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.
>  Alt 2. Or do stuff directly the string?

  (with-temp-buffer
     (insert-file-contents "my-file" nil BEG END)
     ;; etc
     )

should be pretty fast, and more so with wisely chosen BEG / END
values. For additional speed you can use
insert-file-contents-literally, if you don't need code conversions,
decompression, etc.

> Which operations should be performed via a buffer and which should
> operate on a string?

Once the required part of the file is in the buffer, manipulating it
directly or using buffer-(sub)string depends on what do you want to do
with the text, but I wouldn't convert it to a string unless necessary,
i.e., I would use looking-at and re-search-forward rather than
buffer-string + string-match, for example.

 Juanma

  reply	other threads:[~2008-05-16 11:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-16 10:16 Efficiently checking the initial contents of a file Nordlöw
2008-05-16 11:08 ` Juanma Barranquero [this message]
2008-05-16 11:12 ` David Hansen
2008-05-16 11:15 ` Eli Zaretskii
     [not found] ` <mailman.11680.1210937109.18990.help-gnu-emacs@gnu.org>
2008-05-16 12:52   ` Nordlöw
2008-05-16 14:03     ` Juanma Barranquero
     [not found]     ` <mailman.11696.1210946594.18990.help-gnu-emacs@gnu.org>
2008-05-19  7:20       ` Nordlöw
2008-05-22 16:58         ` Thien-Thi Nguyen

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

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

  git send-email \
    --in-reply-to=f7ccd24b0805160408n5ea97303oa02bc127435b2c3a@mail.gmail.com \
    --to=lekktu@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=per.nordlow@gmail.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.