2009-03 / 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

2009-03-01 (日)

Mew で "utf-8 is used. OK?" に相当する文字に色付け [Mew]

(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 判断の変更です。

2009-03 / 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

最終更新時間: 2018-12-14 18:34

検索


最近の話題
- 2018-12-13
  BitBar の Heroku plugin はいいぞ
- 2018-12-07
  ジム通いと食生活改善を5ヶ月続けたので中間報告をする
- 2018-11-28
  Heroku Meetup #23 "Heroku Dynamite!!" で話してきた #herokujp
- 2018-11-21
  先週 GA になった、heroku.yml を使った Docker Deploy を試した
- 2018-10-28
  Heroku CLI 用の zsh 設定は不要だった件
- 2018-10-17
  launchd を使って毎日深夜にだけ Time Machine を実行させる
- 2018-10-15
  Bash v3 以下でも set -u 時に変数が定義されてるか確認する方法
最近追記された記事
- 2016-10-26-1 (6日前)
- 2018-10-15-1 (53日前)
- 2018-04-30-1 (81日前)
- 2017-10-21-1 (349日前)
- 2017-01-10-1 (377日前)
- 2017-04-08-1 (397日前)
- 2017-06-02-1 (531日前)
- 2017-04-29-1 (593日前)
- 2017-04-13-1 (607日前)
- 2017-04-13-1 (609日前)
カテゴリ
- Anthy (3)
- Apache (11)
- Apple (1)
- ATOK (4)
- au (3)
- AWS (21)
- Bazaar (1)
- Berkshelf (2)
- BigQuery (1)
- BitBar (4)
- Book (93)
- Boxen (2)
- Bugsnag (1)
- capistrano (4)
- chalow (56)
- ChatWork (1)
- Chef (17)
- Chrome (3)
- Chromecast (1)
- CircleCI (10)
- clang (26)
- Comics (2)
- Cooking (10)
- cvs (15)
- cygwin (12)
- D3.js (1)
- Debian (55)
- Docker (4)
- E-mail (8)
- elasticsearch (4)
- Emacs (222)
- Emacs講座 (10)
- English (4)
- feedforce (7)
- fetchmail (3)
- Firefox (20)
- Fluentd (4)
- ftp (2)
- Game (21)
- GCP (1)
- Gem (5)
- Git (9)
- GitHub (20)
- golang (10)
- Google (1)
- gpg (4)
- GrowthForecast (7)
- Health (5)
- Heroku (13)
- Homebrew (10)
- HTML (6)
- iBook (1)
- iPhone (17)
- IRC (1)
- Jenkins (8)
- JS (1)
- Karabiner (1)
- KeySnail (3)
- Kibana (1)
- Kindle (1)
- Kubernetes (2)
- Langrich (7)
- LDAP (6)
- Life (22)
- Linux (7)
- Mackerel (1)
- macOS (1)
- Mew (18)
- MongoDB (1)
- Mozilla (19)
- Music (1)
- MySQL (1)
- NAS (4)
- nginx (6)
- NHK (1)
- Node (1)
- ntp (4)
- OOP (2)
- OpenID (2)
- openssl (1)
- Opera (2)
- OSX (41)
- Perl (14)
- PHP (19)
- PostgreSQL (1)
- procmail (4)
- Programing (3)
- Puppet (1)
- Python (2)
- Rails (13)
- Rake (2)
- RaspberryPi (2)
- RedHat (29)
- Redmine (3)
- RSpec (2)
- Ruby (52)
- samba (3)
- screen (7)
- sed (5)
- serverspec (6)
- sh (8)
- Slack (2)
- Solaris9 (22)
- Spring (2)
- ssh (4)
- StatusNet (21)
- svn (12)
- Swift (1)
- Tablet (1)
- tdiary (3)
- Twitter (15)
- Twmode (6)
- Ubuntu (5)
- UNIX (102)
- vagrant (8)
- Video (21)
- vim (1)
- Wercker (9)
- Windows (29)
- Wine (3)
- XML (11)
- XP (1)
- zsh (26)
- インストールメモ (33)
- クイックシェイプ (12)
- ネタ (15)
- 勉強会 (17)
- 携帯 (6)
- 正規表現 (4)
過去ログ
2018 : 01 02 03 04 05 06 07 08 09 10 11 12
2017 : 01 02 03 04 05 06 07 08 09 10 11 12
2016 : 01 02 03 04 05 06 07 08 09 10 11 12
2015 : 01 02 03 04 05 06 07 08 09 10 11 12
2014 : 01 02 03 04 05 06 07 08 09 10 11 12
2013 : 01 02 03 04 05 06 07 08 09 10 11 12
2012 : 01 02 03 04 05 06 07 08 09 10 11 12
2011 : 01 02 03 04 05 06 07 08 09 10 11 12
2010 : 01 02 03 04 05 06 07 08 09 10 11 12
2009 : 01 02 03 04 05 06 07 08 09 10 11 12
2008 : 01 02 03 04 05 06 07 08 09 10 11 12
2007 : 01 02 03 04 05 06 07 08 09 10 11 12
2006 : 01 02 03 04 05 06 07 08 09 10 11 12
2005 : 01 02 03 04 05 06 07 08 09 10 11 12
2004 : 01 02 03 04 05 06 07 08 09 10 11 12
2003 : 01 02 03 04 05 06 07 08 09 10 11 12
2002 : 01 02 03 04 05 06 07 08 09 10 11 12
2001 : 01 02 03 04 05 06 07 08 09 10 11 12
Google+