3

Emacs displays characters without glyphs as octal escape sequences "\OOO", e.g., from the start of a PDF file:

%PDF-1.4
%\344\343\317\322
1 0 obj
[/PDF/ImageB/ImageC/ImageI/Text]
endobj
4 0 obj
<</Length 5 0 R/Filter/FlateDecode>>
stream
9\323\317\221\321\356j\305
endstream

Can I set some (relatively simple) configuration to get those in hexadecimal escape sequences "\xFF"? As:

%PDF-1.4
%\xE4\xE3\xCF\xD2
1 0 obj
[/PDF/ImageB/ImageC/ImageI/Text]
endobj
4 0 obj
<</Length 5 0 R/Filter/FlateDecode>>
stream
9\xD3\xCF\x91\xD1\xEEj\xC5
endstream

(using text-mode, or fundamental-mode, or... but not hexl-mode)

1 Answer 1

2

I've never played with this before, but reading the Elisp manual a bit and experimenting makes me think that something like this is what you're looking for:

(let ((ii          128)
      (new-dtable  (make-display-table))
      (hex-string  nil))
  (while (< ii 256) ; Convert decimal codes 128 to 255.
    (setq hex-string  (format "%X" ii))
    (aset new-dtable ii
          (vector
           (make-glyph-code ?\ 'escape-glyph)
           (make-glyph-code ?x 'escape-glyph)
           (make-glyph-code (aref hex-string 0) 'escape-glyph)
           (make-glyph-code (aref hex-string 1) 'escape-glyph)))
    (setq ii  (1+ ii)))
  (set-window-display-table (selected-window) new-dtable))

If you then use, say C-q 3 4 4 RET, which normally inserts the octal escape sequence \344, it will insert a glyph showing xE4.

The relevant part of the Elisp manual I looked at are those under node Character Display.

5
  • Looks good, yet it does not work completely. I have no time now to investigate deeper, but it seems it is converting newly inserted characters, but not the pre-existant ones Dec 14, 2013 at 10:15
  • That sounds it has to do with the way the redisplay and the display table work. I'm no expert on that. You might need to force redisplay (e.g. force-mode-line-update with ALL arg) or even revisit the buffer (e.g. C-x v or revert). (You are welcome to upvote or accept the answer, BTW. ;-) )
    – Drew
    Dec 14, 2013 at 16:28
  • Upvoted because it is useful, not accepted (yet?) because it does not (yet) solve it. And I hate being asked to vote Dec 14, 2013 at 19:20
  • FYI - For me it does also convert pre-existing chars in the buffer. Did you try adding a call to force-mode-line-update (with non-nil arg)? For me the code works with both Emacs 24 (recent dev snapshot) and Emacs 23.4, on MS Windows.
    – Drew
    Dec 15, 2013 at 0:23
  • Try also iconifying (minimizing) and then restoring the frame, or just resizing the frame. Try also killing the buffer and re-creating it (at least to see whether that helps).
    – Drew
    Jan 12, 2016 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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