comparison lisp/hexl.el @ 54399:ad02f6299e9a

2004-03-15 Masatake YAMATO <jet@gyve.org> * hl-line.el (hl-line-range-function): New variable. (hl-line-move): New function. (global-hl-line-highlight): Use `hl-line-move'. (hl-line-highlight): Ditto. * scroll-bar.el (scroll-bar-columns): New function derived from ruler-mode.el. * fringe.el (fringe-columns): New function derived from ruler-mode.el. * ruler-mode.el (top-level): Require scroll-bar and fringe. (ruler-mode-left-fringe-cols) (ruler-mode-right-fringe-cols): Use `fringe-columns'. (ruler-mode-right-scroll-bar-cols) (ruler-mode-left-scroll-bar-cols): Use `scroll-bar-columns'. (ruler-mode-ruler-function): New variable. (ruler-mode-header-line-format): Call `ruler-mode-ruler-function' if the value for `ruler-mode-ruler-function'is given. * hexl.el (hexl-mode-hook): Make the hook customizable. (hexl-address-area, hexl-ascii-area, hexl-ascii-cursor): New customize variables. (hexlify-buffer): Put font-lock-faces on the address area and the ascii area. (hexl-activate-ruler): New function. (hexl-follow-line): New function. (hexl-highlight-line-range): New function. (hexl-mode-ruler): New function.
author Masatake YAMATO <jet@gyve.org>
date Mon, 15 Mar 2004 07:27:02 +0000
parents 2d1d046af00a
children 8c1cdd137199
comparison
equal deleted inserted replaced
54398:2decd50569f3 54399:ad02f6299e9a
75 (defcustom hexl-follow-ascii t 75 (defcustom hexl-follow-ascii t
76 "If non-nil then highlight the ASCII character corresponding to point." 76 "If non-nil then highlight the ASCII character corresponding to point."
77 :type 'boolean 77 :type 'boolean
78 :group 'hexl 78 :group 'hexl
79 :version "20.3") 79 :version "20.3")
80
81 (defcustom hexl-mode-hook '(hexl-follow-line hexl-activate-ruler)
82 "Normal hook run when entering Hexl mode."
83 :type 'hook
84 :options '(hexl-follow-line hexl-activate-ruler turn-on-eldoc-mode)
85 :group 'hexl)
86
87 (defface hexl-address-area
88 '((t (:inherit header-line)))
89 "Face used in address are of hexl-mode buffer."
90 :group 'hexl)
91
92 (defface hexl-ascii-area
93 '((t (:inherit header-line)))
94 "Face used in ascii are of hexl-mode buffer."
95 :group 'hexl)
80 96
81 (defvar hexl-max-address 0 97 (defvar hexl-max-address 0
82 "Maximum offset into hexl buffer.") 98 "Maximum offset into hexl buffer.")
83 99
84 (defvar hexl-mode-map nil) 100 (defvar hexl-mode-map nil)
646 (coding-system-for-write buffer-file-coding-system) 662 (coding-system-for-write buffer-file-coding-system)
647 (buffer-undo-list t)) 663 (buffer-undo-list t))
648 (apply 'call-process-region (point-min) (point-max) 664 (apply 'call-process-region (point-min) (point-max)
649 (expand-file-name hexl-program exec-directory) 665 (expand-file-name hexl-program exec-directory)
650 t t nil (split-string hexl-options)) 666 t t nil (split-string hexl-options))
667 (save-excursion
668 (goto-char (point-min))
669 (while (re-search-forward "^[0-9a-f]+:" nil t)
670 (put-text-property (match-beginning 0) (match-end 0)
671 'font-lock-face 'hexl-address-area))
672 (goto-char (point-min))
673 (while (re-search-forward " \\(.+$\\)" nil t)
674 (put-text-property (match-beginning 1) (match-end 1)
675 'font-lock-face 'hexl-ascii-area)))
651 (if (> (point) (hexl-address-to-marker hexl-max-address)) 676 (if (> (point) (hexl-address-to-marker hexl-max-address))
652 (hexl-goto-address hexl-max-address)))) 677 (hexl-goto-address hexl-max-address))))
653 678
654 (defun dehexlify-buffer () 679 (defun dehexlify-buffer ()
655 "Convert a hexl format buffer to binary. 680 "Convert a hexl format buffer to binary.
863 (setq hexl-ascii-overlay nil 888 (setq hexl-ascii-overlay nil
864 hexl-follow-ascii nil) 889 hexl-follow-ascii nil)
865 (remove-hook 'post-command-hook 'hexl-follow-ascii-find t) 890 (remove-hook 'post-command-hook 'hexl-follow-ascii-find t)
866 ))))) 891 )))))
867 892
893 (defun hexl-activate-ruler ()
894 "Activate `ruler-mode'"
895 (require 'ruler-mode)
896 (set (make-local-variable 'ruler-mode-ruler-function)
897 'hexl-mode-ruler)
898 (ruler-mode 1))
899
900 (defun hexl-follow-line ()
901 "Activate `hl-line-mode'"
902 (require 'frame)
903 (require 'fringe)
904 (require 'hl-line)
905 (set (make-local-variable 'hl-line-range-function)
906 'hexl-highlight-line-range)
907 (set (make-local-variable 'hl-line-face)
908 'highlight)
909 (hl-line-mode 1))
910
911 (defun hexl-highlight-line-range ()
912 "Return the range of address area for the point.
913 This function is assumed to be used as call back function for `hl-line-mode'."
914 (cons
915 (line-beginning-position)
916 ;; 9 stands for (length "87654321:")
917 (+ (line-beginning-position) 9)))
918
868 (defun hexl-follow-ascii-find () 919 (defun hexl-follow-ascii-find ()
869 "Find and highlight the ASCII element corresponding to current point." 920 "Find and highlight the ASCII element corresponding to current point."
870 (let ((pos (+ 51 921 (let ((pos (+ 51
871 (- (point) (current-column)) 922 (- (point) (current-column))
872 (mod (hexl-current-address) 16)))) 923 (mod (hexl-current-address) 16))))
873 (move-overlay hexl-ascii-overlay pos (1+ pos)) 924 (move-overlay hexl-ascii-overlay pos (1+ pos))
874 )) 925 ))
926
927 (defun hexl-mode-ruler ()
928 "Return a string ruler for hexl mode."
929 (let* ((highlight (mod (hexl-current-address) 16))
930 (s "87654321 0011 2233 4455 6677 8899 aabb ccdd eeff 0123456789abcdef")
931 (pos 0)
932 (spaces (+ (scroll-bar-columns 'left)
933 (fringe-columns 'left)
934 (or (car (window-margins)) 0))))
935 (set-text-properties 0 (length s) nil s)
936 ;; Turn spaces in the header into stretch specs so they work
937 ;; regardless of the header-line face.
938 (while (string-match "[ \t]+" s pos)
939 (setq pos (match-end 0))
940 (put-text-property (match-beginning 0) pos 'display
941 ;; Assume fixed-size chars
942 `(space :align-to (+ (scroll-bar . left)
943 left-fringe left-margin
944 ,pos))
945 s))
946 ;; Highlight the current column.
947 (put-text-property (+ 10 (/ (* 5 highlight) 2))
948 (+ 12 (/ (* 5 highlight) 2))
949 'face 'highlight s)
950 ;; Highlight the current ascii column
951 (put-text-property (+ 12 39 highlight) (+ 12 40 highlight)
952 'face 'highlight s)
953 ;; Add the leading space.
954 (concat (propertize (make-string (floor spaces) ? )
955 'display `(space :width ,spaces))
956 s)))
875 957
876 ;; startup stuff. 958 ;; startup stuff.
877 959
878 (if hexl-mode-map 960 (if hexl-mode-map
879 nil 961 nil