throw any menu. use a buffer to display errors instead.

This commit is contained in:
Kazu Yamamoto 2010-04-01 11:58:44 +09:00
parent 95218aae07
commit 7518d60fcb
3 changed files with 37 additions and 13 deletions

View File

@ -19,13 +19,10 @@ checkSyntax opt file = do
hSetBinaryMode herr False hSetBinaryMode herr False
refine <$> hGetContents herr refine <$> hGetContents herr
where where
refine = unfoldLines . map shrinkSpaces . remove . lines refine = unfoldLines . remove . lines
remove = filter (\x -> not ("Linking" `isPrefixOf` x)) remove = filter (\x -> not ("Linking" `isPrefixOf` x))
. filter (\x -> not ("[" `isPrefixOf` x)) . filter (\x -> not ("[" `isPrefixOf` x))
. filter (/="") . filter (/="")
shrinkSpaces x
| isSpace (head x) = ' ' : dropWhile isSpace x
| otherwise = x
unfoldLines :: [String] -> String unfoldLines :: [String] -> String
unfoldLines [] = "" unfoldLines [] = ""
@ -34,8 +31,7 @@ unfoldLines (x:xs) = x ++ unfold xs
unfold [] = "\n" unfold [] = "\n"
unfold (l:ls) unfold (l:ls)
| isAlpha (head l) = ('\n':l) ++ unfold ls | isAlpha (head l) = ('\n':l) ++ unfold ls
| " Inferred" `isPrefixOf` l = "." ++ l ++ unfold ls | otherwise = (drop 4 l) ++ "\0" ++ unfold ls
| otherwise = l ++ unfold ls
---------------------------------------------------------------- ----------------------------------------------------------------

View File

@ -10,11 +10,13 @@
(require 'flymake) (require 'flymake)
(defvar ghc-error-buffer-name "*GHC Errors*")
(defvar ghc-flymake-allowed-file-name-masks (defvar ghc-flymake-allowed-file-name-masks
'("\\.l?hs$" ghc-flymake-init flymake-simple-cleanup flymake-get-real-file-name)) '("\\.l?hs$" ghc-flymake-init flymake-simple-cleanup flymake-get-real-file-name))
(defvar ghc-flymake-err-line-patterns (defvar ghc-flymake-err-line-patterns
'("^\\(.*\\.l?hs\\):\\([0-9]+\\):\\([0-9]+\\): \\(.+\\)" 1 2 3 4)) '("^\\(.*\\.l?hs\\):\\([0-9]+\\):\\([0-9]+\\):[ ]*\\(.+\\)" 1 2 3 4))
(add-to-list 'flymake-allowed-file-name-masks (add-to-list 'flymake-allowed-file-name-masks
ghc-flymake-allowed-file-name-masks) ghc-flymake-allowed-file-name-masks)
@ -22,6 +24,8 @@
(add-to-list 'flymake-err-line-patterns (add-to-list 'flymake-err-line-patterns
ghc-flymake-err-line-patterns) ghc-flymake-err-line-patterns)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ghc-flymake-init () (defun ghc-flymake-init ()
(let ((after-save-hook nil)) (let ((after-save-hook nil))
(save-buffer)) (save-buffer))
@ -29,20 +33,44 @@
(list ghc-module-command (append (ghc-module-command-args) (list ghc-module-command (append (ghc-module-command-args)
(list "check" file))))) (list "check" file)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ghc-display-errors ()
(interactive)
(let* ((data (ghc-flymake-data))
(buf (get-buffer-create ghc-error-buffer-name)))
(with-current-buffer buf
(erase-buffer)
(ghc-insert-errors data))
(display-buffer buf)))
(defun ghc-insert-errors (data)
(let ((title (nth 0 data))
(errs (nth 1 data)))
(insert title "\n")
(dolist (err errs)
(insert (ghc-replace-character (car err) 0 10) "\n"))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ghc-flymake-insert-type () (defun ghc-flymake-insert-type ()
(interactive) (interactive)
(let ((data (ghc-flymake-data))) (let ((data (ghc-flymake-first-data)))
(if (and data (if (and data
(string-match "Inferred type: \\([^:]+ :: \\)\\(forall [^.]+\\. \\)?\\(.*\\)" data)) (string-match "Inferred type: \\([^:]+ :: \\)\\(forall [^.]+\\. \\)?\\([^\0]*\\)" data))
(progn (progn
(beginning-of-line) (beginning-of-line)
(insert (match-string 1 data) (match-string 3 data) "\n")) (insert (match-string 1 data) (match-string 3 data) "\n"))
(message "No inferred type")))) (message "No inferred type"))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ghc-flymake-data () (defun ghc-flymake-data ()
(let* ((line-no (flymake-current-line-no)) (let* ((line-no (flymake-current-line-no))
(line-err-info-list (nth 0 (flymake-find-err-info flymake-err-info line-no))) (info (nth 0 (flymake-find-err-info flymake-err-info line-no))))
(menu-data (flymake-make-err-menu-data line-no line-err-info-list))) (flymake-make-err-menu-data line-no info)))
(nth 0 (nth 0 (nth 1 menu-data)))))
(defun ghc-flymake-first-data ()
(nth 0 (nth 0 (nth 1 (ghc-flymake-data)))))
(provide 'ghc-flymake) (provide 'ghc-flymake)

View File

@ -52,7 +52,7 @@
(define-key haskell-mode-map ghc-import-key 'ghc-load-module-buffer) (define-key haskell-mode-map ghc-import-key 'ghc-load-module-buffer)
(define-key haskell-mode-map ghc-previous-key 'flymake-goto-prev-error) (define-key haskell-mode-map ghc-previous-key 'flymake-goto-prev-error)
(define-key haskell-mode-map ghc-next-key 'flymake-goto-next-error) (define-key haskell-mode-map ghc-next-key 'flymake-goto-next-error)
(define-key haskell-mode-map ghc-help-key 'flymake-display-err-menu-for-current-line) (define-key haskell-mode-map ghc-help-key 'ghc-display-errors)
(define-key haskell-mode-map ghc-insert-type-key 'ghc-flymake-insert-type) (define-key haskell-mode-map ghc-insert-type-key 'ghc-flymake-insert-type)
(ghc-comp-init) (ghc-comp-init)
(setq ghc-initialized t))) (setq ghc-initialized t)))