我有这个函数可以可视化隐藏的“︁”(0xfe01)字符。可以 这变得更加通用,以便字符串中的所有隐藏字符都得到 可视化?
(defun my-display-hidden (&optional remove)
"Show/hide the hidden '︁' (0xfe01) characters."
(interactive "P")
(if remove (remove-overlays)
(save-excursion
(goto-char (point-min))
(while (search-forward "︁" nil t) ; (0xfe01)
(let ((ov (make-overlay (match-beginning 0) (match-end 0))))
(overlay-put ov 'display
(buttonize "(0xfe01)"
(let ((pos (match-beginning 0)))
(lambda (_) (describe-char pos)))))
(overlay-put ov 'face 'font-lock-warning-face))))))
该函数可以扩展为以与以下类似的方式显示非 ASCII、零宽度字符。删除零宽度检查以覆盖所有非 ASCII 字符。
(defun my-show-nonascii (arg)
"Toggle display of nonascii zero-width characters in current buffer.
With prefix ARG, remove displays."
(interactive "P")
(if arg (remove-overlays (point-min) (point-max) 'nonascii t)
(save-excursion
(goto-char (point-min))
(while (re-search-forward "[[:nonascii:]]" nil t)
(when (zerop (char-width (char-after (match-beginning 0))))
(let ((ov (make-overlay (match-beginning 0) (match-end 0))))
(overlay-put ov 'display
(buttonize (format "(%d)" (char-after (match-beginning 0)))
(let ((pos (match-beginning 0)))
(lambda (_) (describe-char pos)))))
(overlay-put ov 'face 'font-lock-warning-face)
(overlay-put ov 'nonascii t)))))))