diff options
| author | Stephen Eglen | 1998-01-17 17:02:13 +0000 |
|---|---|---|
| committer | Stephen Eglen | 1998-01-17 17:02:13 +0000 |
| commit | db6c5b923d7f3d7899641b0b88294dbe417df00e (patch) | |
| tree | 1e8e526ceaecc3e08aef9e070349fdf89040d2b5 | |
| parent | 0057b00a17eb058965e6fb5cde4454fcb04193b0 (diff) | |
| download | emacs-db6c5b923d7f3d7899641b0b88294dbe417df00e.tar.gz emacs-db6c5b923d7f3d7899641b0b88294dbe417df00e.zip | |
(hexl-follow-ascii): New function and variable to highlight the ASCII
character corresponding to the current element of the buffer.
| -rw-r--r-- | lisp/hexl.el | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/lisp/hexl.el b/lisp/hexl.el index daa4dc79c9c..ace1dfb08f9 100644 --- a/lisp/hexl.el +++ b/lisp/hexl.el | |||
| @@ -88,6 +88,11 @@ and \"-de\" when dehexlifying a buffer." | |||
| 88 | :type 'string | 88 | :type 'string |
| 89 | :group 'hexl) | 89 | :group 'hexl) |
| 90 | 90 | ||
| 91 | (defcustom hexl-follow-ascii t | ||
| 92 | "If non-nil then highlight the ASCII character corresponding to point." | ||
| 93 | :type 'boolean | ||
| 94 | :group 'hexl) | ||
| 95 | |||
| 91 | (defvar hexl-max-address 0 | 96 | (defvar hexl-max-address 0 |
| 92 | "Maximum offset into hexl buffer.") | 97 | "Maximum offset into hexl buffer.") |
| 93 | 98 | ||
| @@ -100,6 +105,10 @@ and \"-de\" when dehexlifying a buffer." | |||
| 100 | (defvar hexl-mode-old-require-final-newline) | 105 | (defvar hexl-mode-old-require-final-newline) |
| 101 | (defvar hexl-mode-old-syntax-table) | 106 | (defvar hexl-mode-old-syntax-table) |
| 102 | 107 | ||
| 108 | (defvar hexl-ascii-overlay nil | ||
| 109 | "Overlay used to highlight ASCII element corresponding to current point.") | ||
| 110 | (make-variable-buffer-local 'hexl-ascii-overlay) | ||
| 111 | |||
| 103 | ;; routines | 112 | ;; routines |
| 104 | 113 | ||
| 105 | (put 'hexl-mode 'mode-class 'special) | 114 | (put 'hexl-mode 'mode-class 'special) |
| @@ -229,7 +238,9 @@ You can use \\[hexl-find-file] to visit a file in hexl-mode. | |||
| 229 | (add-hook 'after-revert-hook 'hexl-after-revert-hook nil t) | 238 | (add-hook 'after-revert-hook 'hexl-after-revert-hook nil t) |
| 230 | 239 | ||
| 231 | (make-local-hook 'change-major-mode-hook) | 240 | (make-local-hook 'change-major-mode-hook) |
| 232 | (add-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer nil t)) | 241 | (add-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer nil t) |
| 242 | |||
| 243 | (if hexl-follow-ascii (hexl-follow-ascii 1))) | ||
| 233 | (run-hooks 'hexl-mode-hook)) | 244 | (run-hooks 'hexl-mode-hook)) |
| 234 | 245 | ||
| 235 | (defun hexl-after-revert-hook () | 246 | (defun hexl-after-revert-hook () |
| @@ -703,6 +714,44 @@ This discards the buffer's undo information." | |||
| 703 | (error "Decimal number out of range") | 714 | (error "Decimal number out of range") |
| 704 | (hexl-insert-char num arg)))) | 715 | (hexl-insert-char num arg)))) |
| 705 | 716 | ||
| 717 | (defun hexl-follow-ascii (&optional arg) | ||
| 718 | "Toggle following ASCII in Hexl buffers. | ||
| 719 | With prefix ARG, turn on following if and only if ARG is positive. | ||
| 720 | When following is enabled, the ASCII character corresponding to the | ||
| 721 | element under the point is highlighted. | ||
| 722 | Customize the variable `hexl-follow-ascii' to disable this feature." | ||
| 723 | (interactive "P") | ||
| 724 | (let ((on-p (if arg | ||
| 725 | (> (prefix-numeric-value arg) 0) | ||
| 726 | (not hexl-ascii-overlay)))) | ||
| 727 | |||
| 728 | (make-local-hook 'post-command-hook) | ||
| 729 | |||
| 730 | (if on-p | ||
| 731 | ;; turn it on | ||
| 732 | (if (not hexl-ascii-overlay) | ||
| 733 | (progn | ||
| 734 | (setq hexl-ascii-overlay (make-overlay 1 1) | ||
| 735 | hexl-follow-ascii t) | ||
| 736 | (overlay-put hexl-ascii-overlay 'face 'highlight) | ||
| 737 | (add-hook 'post-command-hook 'hexl-follow-ascii-find nil t))) | ||
| 738 | ;; turn it off | ||
| 739 | (if hexl-ascii-overlay | ||
| 740 | (progn | ||
| 741 | (delete-overlay hexl-ascii-overlay) | ||
| 742 | (setq hexl-ascii-overlay nil | ||
| 743 | hexl-follow-ascii nil) | ||
| 744 | (remove-hook 'post-command-hook 'hexl-follow-ascii-find t) | ||
| 745 | ))))) | ||
| 746 | |||
| 747 | (defun hexl-follow-ascii-find () | ||
| 748 | "Find and highlight the ASCII element corresponding to current point." | ||
| 749 | (let ((pos (+ 51 | ||
| 750 | (- (point) (current-column)) | ||
| 751 | (mod (hexl-current-address) 16)))) | ||
| 752 | (move-overlay hexl-ascii-overlay pos (1+ pos)) | ||
| 753 | )) | ||
| 754 | |||
| 706 | ;; startup stuff. | 755 | ;; startup stuff. |
| 707 | 756 | ||
| 708 | (if hexl-mode-map | 757 | (if hexl-mode-map |