diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2006-11-23 18:34:44 +0000 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2006-11-23 18:34:44 +0000 |
commit | 312d24fbde1d80e5ea823de511eb362f16bac582 (patch) | |
tree | 634f311053f081bd2c8b0d34797fdf39845bbd5e /lisp/hexl.el | |
parent | 5978ab2c977ad4b14419b9f55dd5c694ca40af84 (diff) | |
download | emacs-312d24fbde1d80e5ea823de511eb362f16bac582.tar.gz |
(hexl-mode): Don't try to guess the max-address: get it from the horse's mouth.
(hexlify-buffer): Don't re-encode an arg that's already encoded.
Diffstat (limited to 'lisp/hexl.el')
-rw-r--r-- | lisp/hexl.el | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/lisp/hexl.el b/lisp/hexl.el index 47bfc76940c..ff7c4bf480e 100644 --- a/lisp/hexl.el +++ b/lisp/hexl.el @@ -207,31 +207,27 @@ You can use \\[hexl-find-file] to visit a file in Hexl mode. (unless (eq major-mode 'hexl-mode) (let ((modified (buffer-modified-p)) (inhibit-read-only t) - (original-point (- (point) (point-min))) - max-address) + (original-point (- (point) (point-min)))) (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 `hexl-mode' is invoked with an argument the buffer is assumed to + ;; be in hexl format. + (when (memq arg '(1 nil)) ;; 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. + ;; FIXME: This doesn't take into account multibyte coding systems. (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)) + (setq original-point (+ (count-lines (point-min) (point)) original-point)) (or (bolp) (setq original-point (1- original-point)))) (hexlify-buffer) (restore-buffer-modified-p modified)) - (make-local-variable 'hexl-max-address) - (setq hexl-max-address max-address) + (set (make-local-variable 'hexl-max-address) + (let* ((full-lines (/ (buffer-size) 68)) + (last-line (% (buffer-size) 68)) + (last-line-bytes (% last-line 52))) + (+ last-line-bytes (* full-lines 16) -1))) (condition-case nil (hexl-goto-address original-point) (error nil))) @@ -709,7 +705,9 @@ This discards the buffer's undo information." ;; Manually encode the args, otherwise they're encoded using ;; coding-system-for-write (i.e. buffer-file-coding-system) which ;; may not be what we want (e.g. utf-16 on a non-utf-16 system). - (mapcar (lambda (s) (encode-coding-string s locale-coding-system)) + (mapcar (lambda (s) + (if (not (multibyte-string-p s)) s + (encode-coding-string s locale-coding-system))) (split-string hexl-options))) (if (> (point) (hexl-address-to-marker hexl-max-address)) (hexl-goto-address hexl-max-address)))) |