From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.devel Subject: Re: docs for insert-file-contents use 'bytes' Date: Wed, 01 Oct 2008 11:54:14 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <868wt845op.fsf@lifelogs.com> References: <86ljxa67xi.fsf@lifelogs.com> <86hc7y64vm.fsf@lifelogs.com> <8663od68yb.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1222880092 19858 80.91.229.12 (1 Oct 2008 16:54:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 1 Oct 2008 16:54:52 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 01 18:55:47 2008 connect(): Connection refused Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Kl4zB-0005cG-A6 for ged-emacs-devel@m.gmane.org; Wed, 01 Oct 2008 18:55:37 +0200 Original-Received: from localhost ([127.0.0.1]:47357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kl4y8-0007F8-AJ for ged-emacs-devel@m.gmane.org; Wed, 01 Oct 2008 12:54:32 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kl4y4-0007Et-A0 for emacs-devel@gnu.org; Wed, 01 Oct 2008 12:54:28 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kl4y0-0007ER-I0 for emacs-devel@gnu.org; Wed, 01 Oct 2008 12:54:27 -0400 Original-Received: from [199.232.76.173] (port=35340 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kl4y0-0007EO-Dm for emacs-devel@gnu.org; Wed, 01 Oct 2008 12:54:24 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:36794 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 1Kl4xz-0004z1-Pb for emacs-devel@gnu.org; Wed, 01 Oct 2008 12:54:24 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Kl4xy-00042Y-BM for emacs-devel@gnu.org; Wed, 01 Oct 2008 16:54:22 +0000 Original-Received: from 38.98.147.130 ([38.98.147.130]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 01 Oct 2008 16:54:22 +0000 Original-Received: from tzz by 38.98.147.130 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 01 Oct 2008 16:54:22 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 70 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 38.98.147.130 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" User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:EyEbSt20PegAQXeLoWCmMg+uBsc= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:104281 Archived-At: On Wed, 01 Oct 2008 09:44:31 +0900 Kenichi Handa wrote: KH> In article <8663od68yb.fsf@lifelogs.com>, Ted Zlatanov 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 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