1 ;;; flymakemsg.el --- Show flymake compile errors in echo area
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: 2009-11-21 Sat
6 ;; Last-Updated: 2009-11-21 Sat
11 ;; Features that might be required by this library:
13 ;; `backquote', `bytecomp'.
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 ;; Show flymake error messages in minibuffer when point is on a
20 ;; flymake error overlay.
22 ;; To use it just load this file. Put this in .emacs:
24 ;; (require 'flymakemsg)
26 ;; This file run `defadvice' on some functions in `flymake-mode'.
27 ;; This code started from an idea in a paste.
29 ;; Note: This code breaks Emacs conventions since it does the
30 ;; defadvising when you just loads this file.
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;; This program is free software; you can redistribute it and/or
40 ;; modify it under the terms of the GNU General Public License as
41 ;; published by the Free Software Foundation; either version 3, or
42 ;; (at your option) any later version.
44 ;; This program is distributed in the hope that it will be useful,
45 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
46 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
47 ;; General Public License for more details.
49 ;; You should have received a copy of the GNU General Public License
50 ;; along with this program; see the file COPYING. If not, write to
51 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
52 ;; Floor, Boston, MA 02110-1301, USA.
54 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
58 (eval-when-compile (require 'flymake))
60 (defun flymakemsg-show-err-at-point ()
61 "If point is on a flymake error, show it in echo area.
62 Protected to run in timers and hooks."
64 (flymakemsg-show-err-at-point-1)
65 (error (message "%s" err))))
67 (defvar flymakemsg-last-errovl nil)
69 (defun flymakemsg-show-err-at-point-1 ()
70 "If point is on a flymake error, show it in echo area."
73 (let ((flyovl (flymakemsg-get-errovl (point))))
74 (unless (eq flyovl flymakemsg-last-errovl)
75 (setq flymakemsg-last-errovl flyovl)
77 (message "%s" (propertize
78 (overlay-get flyovl 'help-echo)
79 'face 'flymake-errline)))))))
81 (defun flymakemsg-get-errovl (POS)
82 "Get flymake error overlay at POS."
84 (dolist (ovl (overlays-at POS))
85 (when (eq 'flymake-errline (overlay-get ovl 'face))
86 (throw 'errovl ovl)))))
88 (defadvice flymake-mode (after
89 flymakemsg-ad-flymake-mode
91 "Turn on showing of flymake errors then point is on them.
92 This shows the error in the echo area."
94 nil ;;(add-hook 'post-command-hook 'flymakemsg-post-command t t)
95 (remove-hook 'post-command-hook 'flymakemsg-post-command t)))
97 (defadvice flymake-log (after
98 flymakemsg-ad-flymake-log
100 "Display error on current line if any."
101 ;;(message "flymake-log defadvice called")
102 (if (not flymake-err-info)
103 (remove-hook 'post-command-hook 'flymakemsg-post-command t)
104 (add-hook 'post-command-hook 'flymakemsg-post-command t t)
105 ;; Wait, because there is another message first.
106 (flymakemsg-start-msg-timer 3.0)))
108 (defun flymakemsg-post-command ()
109 ;; Wait to not disturb to much.
110 (flymakemsg-start-msg-timer 0.2))
112 (defvar flymakemsg-msg-timer nil)
114 (defun flymakemsg-cancel-msg-timer ()
115 (when (timerp flymakemsg-msg-timer)
116 (cancel-timer flymakemsg-msg-timer)))
118 (defun flymakemsg-start-msg-timer (delay)
119 (flymakemsg-cancel-msg-timer)
120 (run-with-idle-timer delay nil 'flymakemsg-show-err-at-point))
122 ;;; I have no idea why it was done the way below. It was in the paste.
123 ;;; It seems very unnecessary but I keep it for now.
125 ;; (defun fly-pyflake-determine-message (err)
126 ;; "pyflake is flakey if it has compile problems, this adjusts the
127 ;; message to display, so there is one ;)"
128 ;; (cond ((not (or (eq major-mode 'Python) (eq major-mode 'python-mode) t)))
129 ;; ((null (flymake-ler-file err))
130 ;; ;; normal message do your thing
131 ;; (flymake-ler-text err))
132 ;; (t ;; could not compile err
133 ;; (format "compile error, problem on line %s" (flymake-ler-line err)))))
135 ;; (let ((line-no (line-number-at-pos)))
136 ;; (dolist (elem flymake-err-info)
137 ;; (if (eq (car elem) line-no)
138 ;; (let ((err (car (second elem))))
139 ;; (message "%s" (fly-pyflake-determine-message err))))))
142 (provide 'flymakemsg)
143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
144 ;;; flymakemsg.el ends here