all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ted Zlatanov <tzz@lifelogs.com>
To: emacs-devel@gnu.org
Subject: Re: docs for insert-file-contents use 'bytes'
Date: Wed, 01 Oct 2008 11:54:14 -0500	[thread overview]
Message-ID: <868wt845op.fsf@lifelogs.com> (raw)
In-Reply-To: E1KkppP-0005vj-S6@etlken.m17n.org

On Wed, 01 Oct 2008 09:44:31 +0900 Kenichi Handa <handa@m17n.org> wrote: 

KH> In article <8663od68yb.fsf@lifelogs.com>, Ted Zlatanov <tzz@lifelogs.com> writes:
>> There could be a insert-file-decoded-contents that seeks to a byte
>> position and gets the next character at or after that position.  That's
>> not too hard to implement and it's fast.

KH> It's not that easy.  Some encoding requires to seek back an
KH> escape sequence to get the next character.  And, for UTF-16
KH> with BOM, we have to check the first 2-byte.

OK.  Does it ever require going more than N*2 (where N = max sequence
length for the encoding) bytes back?  Is N ever bigger than 10?  If not,
it may be complicated code but at least it will be fairly fast.

The semantics could be (given N as above):

1) jump to character number C: scan from beginning of file and count
characters up to C if the encoding has a variable length.  Otherwise the
offset is obvious.

2) jump to character around/at byte B: jump to B-N*2 and scan characters
forward until you find the one that straddles or begins at B.  Also
should have a way to report that character's actual starting byte
position.

3) jump to byte: operate as now, just a fseek

For my purposes (2) is most useful, but I can use (3) and bypass
encodings.  (1) is not good for me, since the application is to view
large files, but (1) is OK for small files.

On Tue, 30 Sep 2008 11:58:12 -0400 Stefan Monnier <monnier@IRO.UMontreal.CA> wrote: 

>> I want to use it to implement a paged view of large files.  We discussed
>> this in emacs-help and you suggested using insert-file-contents IIRC.

SM> This is a very good application indeed.

It's on my TODO list :)  I'm more concerned with fixing the docs,
though, as that was the original intent of my post.  Can they just warn
about the issue, as I suggested?

>> Because the text will be corrupted if you seek in the middle of a
>> multibyte sequence, and there's no way to know in advance if a position
>> is safe without at least some scanning.

SM> It's not exactly "corrupted" in the sense that, while it is not
SM> displayed correctly, it should be correctly saved back so no information
SM> is lost.  Basically, some of the bytes are decoded with the wrong
SM> coding-system, but this coding system is supposed to be safe.

SM> No doubt that it's not "good enough" in general.

Right, it's the interpretation of the data, not the data itself, that's
incorrect.  Variable-length encodings are annoying.

>> There could be a insert-file-decoded-contents that seeks to a byte
>> position and gets the next character at or after that position.  That's
>> not too hard to implement and it's fast.

SM> It wouldn't be good enough for your application because you might then
SM> lose the chars that straddle a boundary.

That's fine.  I would just seek back N bytes and resynchronize (see
above).  I could also make the mode only work with bytes, bypassing
encoding schemes.  This would be a good thing, actually, for cases where
the user might page or search through many megabytes of data quickly.

Ted





  reply	other threads:[~2008-10-01 16:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-29 19:58 docs for insert-file-contents use 'bytes' Ted Zlatanov
2008-09-29 20:12 ` Eli Zaretskii
2008-09-29 21:04   ` Ted Zlatanov
2008-09-30  6:06     ` Miles Bader
2008-09-30  7:19     ` Eli Zaretskii
2008-09-30 13:48       ` Ted Zlatanov
2008-09-30 15:58         ` Stefan Monnier
2008-09-30 16:29         ` Eli Zaretskii
2008-10-01  0:44         ` Kenichi Handa
2008-10-01 16:54           ` Ted Zlatanov [this message]
2008-10-02  1:33             ` Kenichi Handa
2008-10-02 13:42               ` Ted Zlatanov
2008-10-02 18:55                 ` Stefan Monnier
2008-10-03 13:55                   ` Ted Zlatanov
2008-10-02  1:58             ` Kenichi Handa

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=868wt845op.fsf@lifelogs.com \
    --to=tzz@lifelogs.com \
    --cc=emacs-devel@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 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.