The following elisp code defines a new minor mode hexl-bin-mode
that replaces the ascii-region with spaces. That should avoid side-effects caused by faces as they may appear in my first answer.
You can switch on the binary hexl mode by M-x hexl-bin-mode
or bind the command hexl-bin-mode
to any key you want with local-set-key
in hexl-mode-hook
.
(require 'hexl)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Make hexlify-buffer more versatile by adding a hook.
(defvar hexlify-hook nil
"Hook run after `hexlify-buffer'.")
(defun hexlify-hook (&rest _args) ;; For the case that the argument list of `hexlify-buffer' changes in future.
"Run functions registered at `hexlify-hook'."
(run-hooks 'hexlify-hook))
(advice-add 'hexlify-buffer :after #'hexlify-hook)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Define minor-mode for supporting `hexlify-remove-ascii-region'.
(defun hexlify-remove-ascii-region (&rest _args)
"Remove ASCII region generated by `hexlify-buffer'."
;; We cannot use `delete-rectangle' because there may be incomplete lines.
(save-excursion
(goto-char (point-min))
(let ((start (1- (hexl-ascii-start-column))))
(while
(progn
(forward-char start)
(replace-region (point) (line-end-position)
(make-string (- (line-end-position) (point)) ?\s))
(and (eq (forward-line) 0)
(null (eobp))))))))
(defun hexl-refresh ()
"Refresh hexl buffer after manipulation of ascii-region"
(let ((pt (point))
buffer-undo-list) ; prevents query of `dehexlify-buffer'
(dehexlify-buffer)
(hexlify-buffer)
(goto-char pt)))
(define-minor-mode hexl-bin-mode
"Don't show ascii region."
nil " B" nil
(if hexl-bin-mode
(progn
(cl-assert (derived-mode-p 'hexl-mode) nil
"hexl-bin-mode only available for hexl-mode")
(add-hook 'hexlify-hook #'hexlify-remove-ascii-region nil t)
(hexl-refresh))
(remove-hook 'hexlify-hook #'hexlify-remove-ascii-region t)
(when (derived-mode-p 'hexl-mode)
(hexl-refresh))))
(defun hexl-insert-char-ignore (oldfun ch num)
"Ignore `hexl-insert-char' in `hexl-bin-mode'."
(if hexl-bin-mode
(let ((address (hexl-current-address t)))
(while (> num 0)
(let ((hex-position (hexl-address-to-marker address))
(ascii-position
(+ (* (/ address 16) (hexl-line-displen))
(hexl-ascii-start-column)
(point-min)
(% address 16)))
at-ascii-position)
(if (= (point) ascii-position)
(setq at-ascii-position t))
(goto-char hex-position)
(delete-char 2)
(insert (format "%02x" ch))
(setq num (1- num)))))
(apply oldfun args)))
(advice-add 'hexl-insert-char :around #'hexl-insert-char-ignore)
hexl-follow-ascii
?hexl-follow-ascii
just controls the highlighting of the character corresponding to the current point-position. I had a look at hexl. There is no option for that workhorse that avoids the ascii string. My first simple approach would be to set the foreground equal to the background inhexl-ascii-region
.