readonly時にモードラインの色を変える

2012/3/27 ライブラリ化した

ここを参考に。
EmacsWiki: Changing Cursor Dynamically

(defun my-set-mode-line-color-read-only ()
  ""
  (let ((state (if buffer-read-only
                   'readonly
                 (if overwrite-mode
                     'overwrite
                   'insert))))
    (unless (eq state my-set-mode-line-color-state)
      (set-face-foreground 'modeline
                           (nth 1
                                (assq state
                                      my-set-mode-line-color-color)))
      (set-face-background 'modeline
                           (nth 2
                                (assq state
                                      my-set-mode-line-color-color)))
      (setq my-set-mode-line-color-state state))))
(defvar my-set-mode-line-color-color
  '((readonly "blue" "white")
    (overwrite "red" "white")
    (insert nil nil))
  "")
(defvar my-set-mode-line-color-state nil "")
(add-hook 'post-command-hook 'my-set-mode-line-color-read-only)