bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#46933: Possible bugs in filepos-to-bufferpos / bufferpos-to-filepos


From: Lars Ingebrigtsen
Subject: bug#46933: Possible bugs in filepos-to-bufferpos / bufferpos-to-filepos
Date: Mon, 20 Jun 2022 02:59:52 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

handa <handa@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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]