2011-05-21 47 views
1

我有一個「文本」文件,有一些無效的字節序列。 Emacs將它們渲染爲「\ 340 \ 360」,有沒有辦法讓強大的文本處理器以十六進制渲染它們,例如:「\ co0a」?謝謝。emacs中unibyte文本緩衝區:以hexa編碼?

編輯:我不會將自己的答案標記爲已接受,但只是想說它的工作正常。

回答

1

發現了它,以防萬一有人需要它太...(從here

(setq standard-display-table (make-display-table)) 
(let ((i ?\x80) hex hi low) 
    (while (<= i ?\xff) 
    (setq hex (format "%x" i)) 
    (setq hi (elt hex 0)) 
    (setq low (elt hex 1)) 
    (aset standard-display-table (unibyte-char-to-multibyte i) 
      (vector (make-glyph-code ?\\ 'escape-glyph) 
        (make-glyph-code ?x 'escape-glyph) 
        (make-glyph-code hi 'escape-glyph) 
        (make-glyph-code low 'escape-glyph))) 
    (setq i (+ i 1))))