> - (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))
This removes a special case which seems unused but not uninteresting. More specifically it hints at a better solution to our problem. See patch below. Note that it doesn't address the similar problem with `original-point'. This one may require the use of encode-coding-string. Also it seems that hexl-mode doesn't like to be called in an empty buffer and my patch doesn't fix that part. Stefan --- orig/lisp/hexl.el +++ mod/lisp/hexl.el @@ -207,31 +207,26 @@ (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. (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))) @@ -713,7 +708,9 @@ ;; 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 (unibyte-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)))) _______________________________________________ emacs-pretest-bug mailing list emacs-pretest-bug@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug