]> git.eshelyaron.com Git - emacs.git/commitdiff
(hexl-mode, hexl-mode-exit): Adjust hexl-max-address and
authorEli Zaretskii <eliz@gnu.org>
Thu, 16 Aug 2001 19:48:00 +0000 (19:48 +0000)
committerEli Zaretskii <eliz@gnu.org>
Thu, 16 Aug 2001 19:48:00 +0000 (19:48 +0000)
original-point for extra CR characters that are added/removed when
the buffer is written/read whose EOL type is -dos.

lisp/ChangeLog
lisp/hexl.el

index 8f60cb09d8251ae29eeec6855dbac4d61bbfb414..b92af6254a0e3b2fe6030f4c3463b9867bc0dd1c 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2001-08-16  Miles Bader  <miles@gnu.org>
 
        * simple.el (line-move): Undo previous change.
index e44da8cacda3aefc3184717a22533d8cd6801190..ae3b88c61e2d1b3f3c7f21e9d6156f960cfb72ba 100644 (file)
@@ -206,6 +206,19 @@ You can use \\[hexl-find-file] to visit a file in Hexl mode.
          ;; 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,6 +319,12 @@ With arg, don't unhexlify buffer."
        (dehexlify-buffer)
        (remove-hook 'write-contents-hooks 'hexl-save-buffer)
        (set-buffer-modified-p modified)
+       (goto-char original-point)
+       ;; Maybe adjust point for the removed CR characters.
+       (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)