emacs-pretest-bug
[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: Ye Wenbin
Subject: Re: address@hidden: hexl-max-address in hexl-mode is incorrect]
Date: Thu, 23 Nov 2006 15:01:29 +0800
User-agent: Opera Mail/9.01 (Linux)

Sorry for the mistaken. And I found that use file size may cause some
error because the buffer may be modified.

This my patch:

diff -utbB /home/ywb/lisp/hexl.el /home/ywb/lisp/hexli.el
--- lisp/hexl.el        2006-10-30 14:47:26.000000000 +0800
+++ lisp/hexli.el       2006-11-23 14:58:49.000000000 +0800
@@ -207,31 +207,20 @@
   (unless (eq major-mode 'hexl-mode)
     (let ((modified (buffer-modified-p))
           (inhibit-read-only t)
-          (original-point (- (point) (point-min)))
-          max-address)
-      (and (eobp) (not (bobp))
-           (setq original-point (1- original-point)))
-      (if (not (or (eq arg 1) (not arg)))
-          ;; if no argument then we guess at hexl-max-address
-          (setq max-address (+ (* (/ (1- (buffer-size)) 68) 16) 15))
-        (setq max-address (1- (buffer-size)))
-        ;; If the buffer's EOL type is -dos, we need to account for
-        ;; extra CR characters added when hexlify-buffer writes the
-        ;; buffer to a file.
-        (when (eq (coding-system-eol-type buffer-file-coding-system) 1)
-          (setq max-address (+ (count-lines (point-min) (point-max))
-                               max-address))
-          ;; But if there's no newline at the last line, we are off by
-          ;; one; adjust.
-          (or (eq (char-before (point-max)) ?\n)
-              (setq max-address (1- max-address)))
-          (setq original-point (+ (count-lines (point-min) (point))
-                                  original-point))
-          (or (bolp) (setq original-point (1- original-point))))
+          original-point max-address)
+      ;; Characters are multibyte in some coding systems.  Should encoding
+      ;; the buffer with buffer-file-coding-system, then set the origianl
+      ;; point and max address
+      (setq original-point
+            (length
+             (encode-coding-string (buffer-substring (point-min)
+                                                     (point))
+                                   buffer-file-coding-system)))
+      (set (make-local-variable 'hexl-max-address)
+           (1- (length (encode-coding-string (buffer-string)
+                                             buffer-file-coding-system))))
         (hexlify-buffer)
-        (restore-buffer-modified-p modified))
-      (make-local-variable 'hexl-max-address)
-      (setq hexl-max-address max-address)
+      (restore-buffer-modified-p modified)
       (condition-case nil
           (hexl-goto-address original-point)
         (error nil)))

On Thu, 23 Nov 2006 00:59:14 +0800, Chong Yidong <address@hidden> 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.

However, the (decode-coding-string (buffer-string) buffer-file-coding-system)
method doesn't seem to work for me; it returns erratic incorrect
results.

Actually, I think the correct thing to do is to ENcode the buffer
string, not DEcode it.

(length (encode-coding-string (buffer-string) buffer-file-coding-system))

This seems to produce the correct results.



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/




reply via email to

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