flymakeのエラー表示を改善する

flymakeは便利ですよね。ただエラーメッセージが見づらいなぁというのが
あっていろいろ考えていました。

ミニバッファに表示

node-jslintでflymake - すぎゃーんメモ


@さんの記事で、next-errorでジャンプしたときに
ミニバッファにエラーメッセージを表示するというのを見て、
これは使えるかなと思ったんですが、エラー行からミニバッファまで
距離があると視線をいちいち動かさないといけないし、文字が小さいし
もう少しなんとかならないかなと思いました。

ポップアップで表示

flymake のエラーメッセージを popup-tip で表示 - とりあえず暇だったし何となく始めたブログ


@さんの popup.elを使ってエラーを表示するという
記事を見て、これと@さんの設定を組み合わせたら、
next-errorの度にポップアップして、エラー行のすぐ近くにエラー
メッセージを表示できるなってことで、試してみたんですが、まだ
パンチが足りない感じがしました。

改善する

何が足りないって、エラーメッセージなのに強調さが足りない。
エラーなんだから、強調しすぎても強調しすぎることないと思うので、
上記のアイデアを強調してみました。その結果が以下のとおりです。



これでエラーが一目瞭然ですね。

コード

設定コードを以下に示します。
追記: デフォルト値の設定の部分が誤っていたので修正.

;; setting for flymake
(require 'flymake)

(global-set-key (kbd "M-e") 'flymake-goto-next-error)
(global-set-key (kbd "M-E") 'flymake-goto-prev-error)

;; Show error message under current line
(require 'popup)
(defun flymake-display-err-menu-for-current-line ()
  (interactive)
  (let* ((line-no (flymake-current-line-no))
         (line-err-info-list (nth 0 (flymake-find-err-info flymake-err-info line-no))))
    (when line-err-info-list
      (let* ((count (length line-err-info-list))
             (menu-item-text nil))
        (while (> count 0)
          (setq menu-item-text (flymake-ler-text (nth (1- count) line-err-info-list)))
          (let* ((file (flymake-ler-file (nth (1- count) line-err-info-list)))
                 (line (flymake-ler-line (nth (1- count) line-err-info-list))))
            (if file
                (setq menu-item-text (concat menu-item-text " - " file "(" (format "%d" line) ")"))))
          (setq count (1- count))
          (if (> count 0) (setq menu-item-text (concat menu-item-text "\n")))
          )
        (popup-tip menu-item-text)))))

;; If you don't set :height, :bold face parameter of 'pop-tip-face,
;; then seting those default values
(if (eq 'unspecified (face-attribute 'popup-tip-face :height))
    (set-face-attribute 'popup-tip-face nil :height 1.0))
(if (eq 'unspecified (face-attribute 'popup-tip-face :weight))
    (set-face-attribute 'popup-tip-face nil :weight 'normal))

(defun my/display-error-message ()
  (let ((orig-face (face-attr-construct 'popup-tip-face)))
    (set-face-attribute 'popup-tip-face nil
                        :height 1.5 :foreground "firebrick"
                        :background "LightGoldenrod1" :bold t)
    (unwind-protect
        (flymake-display-err-menu-for-current-line)
      (while orig-face
        (set-face-attribute 'popup-tip-face nil (car orig-face) (cadr orig-face))
        (setq orig-face (cddr orig-face))))))

(defadvice flymake-goto-prev-error (after flymake-goto-prev-error-display-message)
  (my/display-error-message))
(defadvice flymake-goto-next-error (after flymake-goto-next-error-display-message)
  (my/display-error-message))

(ad-activate 'flymake-goto-prev-error 'flymake-goto-prev-error-display-message)
(ad-activate 'flymake-goto-next-error 'flymake-goto-next-error-display-message)

おわりに

年のせいか、いろいろ楽しないとしんどいわ、と思うようになりました。
文字は大きく、視線はあまり動かさずできるよう改善を行っていこうと
思います。