diff options
| author | Richard M. Stallman | 1995-09-10 17:45:08 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-09-10 17:45:08 +0000 |
| commit | 6bbb008e7ed360c4ecbe5854a03ae246a08a93a3 (patch) | |
| tree | a60e2e839bfb22650d074959dbd2df41a3d1d905 | |
| parent | aaf6c7ef84d040792d9876b5e8f7a20d76a496c6 (diff) | |
| download | emacs-6bbb008e7ed360c4ecbe5854a03ae246a08a93a3.tar.gz emacs-6bbb008e7ed360c4ecbe5854a03ae246a08a93a3.zip | |
(hexl-current-address): New arg VALIDATE.
Handle point values in the ASCII text section and in the addresses.
(hexl-insert-char): Handle point located in the ASCII text.
| -rw-r--r-- | lisp/hexl.el | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/lisp/hexl.el b/lisp/hexl.el index 5fc08177e6b..ce13f52f372 100644 --- a/lisp/hexl.el +++ b/lisp/hexl.el | |||
| @@ -269,13 +269,20 @@ Ask the user for confirmation." | |||
| 269 | (set-buffer-modified-p modified) | 269 | (set-buffer-modified-p modified) |
| 270 | (goto-char original-point)))) | 270 | (goto-char original-point)))) |
| 271 | 271 | ||
| 272 | (defun hexl-current-address () | 272 | (defun hexl-current-address (&optional validate) |
| 273 | "Return current hexl-address." | 273 | "Return current hexl-address." |
| 274 | (interactive) | 274 | (interactive) |
| 275 | (let ((current-column (- (% (point) 68) 11)) | 275 | (let ((current-column (- (% (point) 68) 11)) |
| 276 | (hexl-address 0)) | 276 | (hexl-address 0)) |
| 277 | (setq hexl-address (+ (* (/ (point) 68) 16) | 277 | (if (< current-column 0) |
| 278 | (/ (- current-column (/ current-column 5)) 2))) | 278 | (if validate |
| 279 | (error "Point is not on a character in the file") | ||
| 280 | (setq current-column 0))) | ||
| 281 | (setq hexl-address | ||
| 282 | (+ (* (/ (point) 68) 16) | ||
| 283 | (if (>= current-column 41) | ||
| 284 | (- current-column 41) | ||
| 285 | (/ (- current-column (/ current-column 5)) 2)))) | ||
| 279 | hexl-address)) | 286 | hexl-address)) |
| 280 | 287 | ||
| 281 | (defun hexl-address-to-marker (address) | 288 | (defun hexl-address-to-marker (address) |
| @@ -577,17 +584,32 @@ You may also type up to 3 octal digits, to insert a character with that code" | |||
| 577 | 584 | ||
| 578 | (defun hexl-insert-char (ch num) | 585 | (defun hexl-insert-char (ch num) |
| 579 | "Insert a character in a hexl buffer." | 586 | "Insert a character in a hexl buffer." |
| 580 | (let ((address (hexl-current-address))) | 587 | (let ((address (hexl-current-address t))) |
| 581 | (while (> num 0) | 588 | (while (> num 0) |
| 582 | (delete-char 2) | 589 | (let ((hex-position |
| 583 | (insert (format "%02x" ch)) | 590 | (+ (* (/ address 16) 68) |
| 584 | (goto-char | 591 | 11 |
| 585 | (+ (* (/ address 16) 68) 52 (% address 16))) | 592 | (* 2 (% address 16)) |
| 586 | (delete-char 1) | 593 | (/ (% address 16) 2))) |
| 587 | (insert (hexl-printable-character ch)) | 594 | (ascii-position |
| 588 | (or (eq address hexl-max-address) | 595 | (+ (* (/ address 16) 68) 52 (% address 16))) |
| 589 | (setq address (1+ address))) | 596 | at-ascii-position) |
| 590 | (hexl-goto-address address) | 597 | (if (= (point) ascii-position) |
| 598 | (setq at-ascii-position t)) | ||
| 599 | (goto-char hex-position) | ||
| 600 | (delete-char 2) | ||
| 601 | (insert (format "%02x" ch)) | ||
| 602 | (goto-char ascii-position) | ||
| 603 | (delete-char 1) | ||
| 604 | (insert (hexl-printable-character ch)) | ||
| 605 | (or (eq address hexl-max-address) | ||
| 606 | (setq address (1+ address))) | ||
| 607 | (hexl-goto-address address) | ||
| 608 | (if at-ascii-position | ||
| 609 | (progn | ||
| 610 | (beginning-of-line) | ||
| 611 | (forward-char 51) | ||
| 612 | (forward-char (% address 16))))) | ||
| 591 | (setq num (1- num))))) | 613 | (setq num (1- num))))) |
| 592 | 614 | ||
| 593 | ;; hex conversion | 615 | ;; hex conversion |