Skip to content

Instantly share code, notes, and snippets.

@emasaka
Created December 28, 2023 02:41
Show Gist options
  • Save emasaka/dc4419edbaa5397c3a71fd768a832b0b to your computer and use it in GitHub Desktop.
Save emasaka/dc4419edbaa5397c3a71fd768a832b0b to your computer and use it in GitHub Desktop.
(defvar MOJIWARN-RE
(rx (| (any (?\u2F00 . ?\u2FDF) ; 康煕部首
(?\u2E80 . ?\u2EF3) ; CJK部首補助
(?\uFE10 . ?\uFE19) ) ; 縦書き用句読点
(: nonl ?\u3099) ; NFDの濁点
(: nonl ?\u309A) ; NFDの半濁点
(category alpha-numeric-two-byte) ; 全角英数字
(: upper upper lower) ))) ; double capitalize
(defvar MOJIWARN-FONT-LOCK-KEYWORDS
`((,MOJIWARN-RE . font-lock-warning-face)) )
(defvar MOJIWARN-INVISIBLE-CHARNAMES
'("ZERO WIDTH SPACE" "ZERO WIDTH NO-BREAK SPACE"
"ZERO WIDTH JOINER" "ZERO WIDTH NON-JOINER"
"LINE SEPARATOR" "PARAGRAPH SEPARATOR" ))
(defvar MOJIWARN-GLYPHLESS-CHAR-DISPLAY
(let ((tbl (copy-sequence glyphless-char-display)))
(dolist (n MOJIWARN-INVISIBLE-CHARNAMES)
(set-char-table-range tbl (char-from-name n) 'hex-code) )
tbl ))
(define-minor-mode mojiwarn-mode
"MojiWarn mode" ; document
nil ; initianl value
" mojiwarn" ; mode line string
nil ; keymap
(if mojiwarn-mode ; body
;; enter mojiwarn-mode
(progn
(font-lock-add-keywords nil MOJIWARN-FONT-LOCK-KEYWORDS)
(setq-local glyphless-char-display MOJIWARN-GLYPHLESS-CHAR-DISPLAY) )
;; leave mojiwarn-mode
(font-lock-remove-keywords nil MOJIWARN-FONT-LOCK-KEYWORDS)
(setq glyphless-char-display (default-value 'glyphless-char-display) )))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment