[Top][All Lists]

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

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

From: Kevin Rodgers
Subject: Re: address@hidden: hexl-max-address in hexl-mode is incorrect]
Date: Wed, 22 Nov 2006 10:15:01 -0700
User-agent: Thunderbird (Windows/20061025)

Chong Yidong wrote:
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

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))
             (decode-coding-string (buffer-string)

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.

How about: (- (position-bytes (point-max)) (position-bytes (point-min)))


reply via email to

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