(setq mew-ask-charset '("us-ascii" "iso-2022-jp"))
などと設定して、これ以外の文字を含むメールを送信しようとすると、
“utf-8 is used. OK?” と聞かれるが、本文のどこに該当の文字が含まれて
いるのか経験と勘(笑)で調べるしかなかった。そこで、“n” でキャンセル
した後、該当の文字の背景を紫色にするようにしてみた。
;; 「UNICODE 文字」の face を定義
(defvar mew-unicode-char-face-list
'((((class color) (type tty)) (:bold t))
(((class color) (background light)) (:background "purple"))
(((class color) (background dark)) (:background "purple"))
(t (:bold t))))
(defface mew-unicode-char-face mew-unicode-char-face-list
"UNICODE 文字"
:group 'mew-highlight)
(defvar mew-unicode-char-face 'mew-unicode-char-face)
(face-spec-set 'mew-unicode-char-face mew-unicode-char-face-list)
(defadvice mew-encode-undo
(after
mew-encode-undo-after-advice
activate)
"「UNICODE 文字」を強調表示"
(if mew-ask-charset
(let* ((beg (progn (mew-header-goto-body) (point)))
(end (or (mew-attach-begin) (point-max)))
(unicode-char-regexp (mew-cur-unicode-char-regexp beg end)))
(if (stringp unicode-char-regexp)
(save-excursion
(mew-elet
(goto-char beg)
(while (and (<= (point) end) (re-search-forward unicode-char-regexp end t))
(put-text-property
(match-beginning 0) (match-end 0) 'face 'mew-unicode-char-face))))))))
(defun mew-cur-unicode-char-regexp (beg end)
(let (pos unicode-char unicode-char-list)
(save-excursion
(goto-char beg)
(while (< (setq pos (point)) end)
(if (and (mew-unicode-char-p pos)
(setq unicode-char (char-to-string (char-after pos)))
(not (member unicode-char unicode-char-list)))
(setq unicode-char-list (cons unicode-char unicode-char-list)))
(forward-char 1)))
(if (consp unicode-char-list)
(concat "[" (mapconcat 'identity unicode-char-list "") "]+"))))
(defun mew-unicode-char-p (pos)
(let* ((char (char-after pos))
(eight-bit-p (and (not enable-multibyte-characters) (>= char 128)))
(charset (if eight-bit-p 'eight-bit
(char-charset char))))
(and (not (eq charset 'ascii))
(not (eq charset 'japanese-jisx0208)))))
さらに draft-mode で C-c C-l した時も色付けさせる設定。
(defadvice mew-highlight-body-region
(after
mew-highlight-body-region-after-advice
activate)
"「UNICODE 文字」を強調表示"
(if (and mew-ask-charset
(eq major-mode 'mew-draft-mode))
(let* ((BEG (ad-get-arg 0))
(END (ad-get-arg 1))
(unicode-char-regexp (mew-cur-unicode-char-regexp BEG END)))
(if (stringp unicode-char-regexp)
(save-excursion
(mew-elet
(goto-char BEG)
(while (and (<= (point) END) (re-search-forward unicode-char-regexp END t))
(put-text-property
(match-beginning 0) (match-end 0) 'face 'mew-unicode-char-face))))))))
追記(2009-03-02):
mew-cur-unicode-char-regexp() と mew-unicode-char-p() を変更しました。
前者は検索回数の削減、後者は Unicode 判断の変更です。