Emacsにおいて、Unicode不可視文字を表示機能を追加し、視認できるようにする。
nobreak-char-displayglyphless-char-displaybidi-display-reordering = left-to-rightbidi-paragraph-direction = left-to-rightEmacsは標準である程度検出できるが、ゼロ幅/Bidi系を明示的に炙り出す設定を入れる。
;; 不可視文字の可視化
(setq-default nobreak-char-display t)
;; 制御文字を可視化
(setq-default glyphless-char-display
'((format-control . hex)
(zero-width . hex)
(zero-width-non-joiner . hex)
(zero-width-joiner . hex)))
;; bidi攻撃対策(Trojan Source系)
(setq bidi-display-reordering 'left-to-right)
(setq bidi-paragraph-direction 'left-to-right)
(defface my-invisible-unicode-face
'((t (:background "red" :foreground "white")))
"Face for invisible unicode characters")
(defun my-highlight-invisible-unicode ()
(highlight-regexp
"[\u200B-\u200F\u202A-\u202E\u2060\uFEFF]"
'my-invisible-unicode-face))
(add-hook 'prog-mode-hook 'my-highlight-invisible-unicode)
(add-hook 'text-mode-hook 'my-highlight-invisible-unicode)
👉 これで:
が赤く浮き上がる
M-x occur RET [\u200B-\u200F\u202A-\u202E] RET