Is there a simpler way?
No, I think you have that correctly. Something like this, then:
(defun hexl-me-this ()"Open a copy of the current buffer in `hexl-mode'." (interactive) (display-buffer (let* ((buf (current-buffer)) (mode major-mode) (coding buffer-file-coding-system) (file (or buffer-file-name dired-directory (expand-file-name (buffer-name) default-directory))) (tmp (concat temporary-file-directory "hexl" file)) (hexlbuf (or (get-file-buffer tmp) (create-file-buffer tmp)))) (with-current-buffer hexlbuf (setq buffer-file-name tmp) (buffer-disable-undo) (erase-buffer) (remove-hook 'change-major-mode-hook #'hexl-maybe-dehexlify-buffer t) (funcall mode) (set-buffer-file-coding-system coding) (insert-buffer-substring buf) (hexl-mode) (set-buffer-modified-p nil)) hexlbuf)))