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

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

Re: hexl buffer of DOS file strange length


From: Eli Zaretskii
Subject: Re: hexl buffer of DOS file strange length
Date: Thu, 16 Aug 2001 22:45:12 +0300

> From: john <john@arrows.demon.co.uk>
> Date: Thu, 16 Aug 2001 18:31:54 +0100
> 
> I create a buffer containing
> 
> abc
> def
> ghi
> 
> Do
> M-x set-buffer-file-coding-system dos
> M-x hexl-mode
> 
> to find
> 00000000: 6162 630d 0a64 6566 0d0a 670d 690d 0a    abc..def..g.i..
> 
> I then find I cannot move the cursor beyond the 12th byte.

Thank you for your report.  Please try this change:

2001-08-16  Eli Zaretskii  <eliz@is.elta.co.il>

        * hexl.el (hexl-mode, hexl-mode-exit): Adjust hexl-max-address and
        original-point for extra CR characters that are added/removed when
        the buffer is written/read whose EOL type is -dos.

*** lisp/hexl.el        2001/07/15 16:15:34     1.65
--- lisp/hexl.el        2001/08/16 19:44:59
***************
*** 206,211 ****
--- 206,224 ----
          ;; 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))))
          (hexlify-buffer)
          (set-buffer-modified-p modified))
        (make-local-variable 'hexl-max-address)
***************
*** 306,311 ****
--- 319,329 ----
        (dehexlify-buffer)
        (remove-hook 'write-contents-hooks 'hexl-save-buffer)
        (set-buffer-modified-p modified)
+       (goto-char original-point)
+       (when (eq (coding-system-eol-type buffer-file-coding-system) 1)
+         (setq original-point (- original-point
+                                 (count-lines (point-min) (point))))
+         (or (bobp) (setq original-point (1+ original-point))))
        (goto-char original-point)))
  
    (remove-hook 'after-revert-hook 'hexl-after-revert-hook t)



reply via email to

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