Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I use hexl-mode in emacs, it discards the buffer's undo info.
Is there another way to hex-edit the buffer and yet retain the undo info?

If there is no alternative hex-editor, is there a hex-viewer which can view the buffer? I have tried hexview-mode, but it doesn't view the actual buffer; it views the buffer's file (from disk), so I don't see the current edit.

share|improve this question

Here is a function which copies the contents of the current buffer into a new buffer and runs hexl-mode on that:

(defun hexify-buffer-copy()
    "Edit current buffer in hexl mode by copying it"
    (let ((orig-buffer (current-buffer)))
         (switch-to-buffer (create-file-buffer
             (buffer-file-name orig-buffer)))
         (insert-buffer orig-buffer)
         (setq buffer-undo-list nil)

Run with M-: (hexify-buffer-copy)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.