GNU bug report logs - #46933
Possible bugs in filepos-to-bufferpos / bufferpos-to-filepos

Previous Next

Package: emacs;

Reported by: Gregory Heytings <gregory <at> heytings.org>

Date: Thu, 4 Mar 2021 21:22:02 UTC

Severity: normal

Full log


View this message in rfc822 format

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: handa <handa <at> gnu.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, gregory <at> heytings.org, 46933 <at> debbugs.gnu.org
Subject: bug#46933: Possible bugs in filepos-to-bufferpos / bufferpos-to-filepos
Date: Mon, 20 Jun 2022 02:59:52 +0200
handa <handa <at> gnu.org> writes:

> But it seems that the usage in Info-find-node-2 is:
>   a byte position in an existing file that may not be created by Emacs
>
> There's a case that they are different.  The method I wrote in the
> previous mail works only in the former case.   And it seems that the
> current implementation of filepos-to-bufferpos is the same because it
> tries to get byte sequence by encode-coding-region.
>
> For the latter case, perhaps something like the following code works.
>
> ;; Return the buffer position correspoinding to the byte position
> ;; FILEPOS in FILE provided that FILE is decoded by CODING-SYSTEM.
> (defun temp (file filepos coding-system)
>   (with-temp-buffer
>     (set-buffer-multibyte nil)
>     (insert-file-contents-literally file)
>     (let ((full (decode-coding-region 1 (point-max) coding-system t))
> 	  partial)
>       (while (and (setq partial (decode-coding-region 1 (1+ filepos)
> 						      coding-system t))
> 		  (not (eq (compare-strings full 0 (length partial)
> 					    partial 0 (length partial))
> 			   t)))
> 	  (setq filepos (1+ filepos)))
>       (1+ (length partial)))))
>
> If it is too slow, there are a few ways to make it faster.

(I'm going through old bug reports that unfortunately weren't resolved
at the time.)

If I understand correctly, the suggestion here is to use this function
in Info-find-node-2 instead of `filepos-to-bufferpos'?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




This bug report was last modified 3 years and 54 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.