emacs-devel
[Top][All Lists]
Advanced

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

Re: address@hidden: hexl-max-address in hexl-mode is incorrect]


From: Chong Yidong
Subject: Re: address@hidden: hexl-max-address in hexl-mode is incorrect]
Date: Wed, 22 Nov 2006 11:02:22 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.91 (gnu/linux)

> The hexl-max-address usually set to buffer-size, but when the buffer
> contain a multiple byte character or the file associated to the buffer
> is  encoded by multibyte coding system such as utf-16, the
> hexl-max-address is  usually less the the real byte of buffer.
>
> You can test like this:
>
> Test case 2:
> Open a new file, such as /tmp/test.txt. Use C-x RET f to set the file
> coding system to utf-16. Input any letters such as "ab", and save the
> buffer. Then change mode to hexl-mode. C-h v hexl-max-address show the
> value is still 2 which is the buffer-size rather than the sizze of the
> file.
>
> Here is my solution to set hexl-max-address which might help:
> (setq hexl-max-address
>       (1- (if buffer-file-name
>               (nth 7 (file-attributes buffer-file-name))
>             (length
>              (decode-coding-string (buffer-string)
> buffer-file-coding-system)))))

The (nth 7 (file-attributes buffer-file-name)) method returns the
correct byte count.  However, the
(decode-coding-string (buffer-string) buffer-file-coding-system)
method doesn't seem to work for me; it returns erratic incorrect
results.  In the case of a utf-16 buffer containing just "ab" without
an associated file, it returns 1; if there is an associated buffer, it
returns 0.




reply via email to

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