Skip to content

Commit

Permalink
More work on flychecker syntax checkers
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wiegley committed Jan 19, 2013
1 parent d784b9f commit d5e5d1e
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 14 deletions.
95 changes: 83 additions & 12 deletions init.el
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2053,11 +2053,15 @@ FORM => (eval FORM)."
(progn (progn
(flycheck-declare-checker haskell-ghc (flycheck-declare-checker haskell-ghc
"Haskell checker using ghc" "Haskell checker using ghc"
:command '("ghc" "-v0" source-inplace) :command '("ghc" "-fno-code" "-v0" source-inplace)
:error-patterns :error-patterns
`((,(concat "^\\(?1:.*?\\):\\(?2:[0-9]+\\):\\(?3:[0-9]+\\):[ \t\n\r]*" `((,(concat "^\\(?1:.*?\\):\\(?2:[0-9]+\\):\\(?3:[0-9]+\\):[ \t\n\r]*"
"\\(?5:Warning: \\)?"
"\\(?4:\\(.\\|[ \t\n\r]\\)+?\\)\\(^\n\\|\\'\\)") "\\(?4:\\(.\\|[ \t\n\r]\\)+?\\)\\(^\n\\|\\'\\)")
error)) (if (let ((out (match-string 5 output)))
(and out (string= out "Warning: ")))
'warning
'error)))
:modes 'haskell-mode) :modes 'haskell-mode)


(push 'haskell-ghc flycheck-checkers) (push 'haskell-ghc flycheck-checkers)
Expand All @@ -2067,8 +2071,12 @@ FORM => (eval FORM)."
:command '("hdevtools" "check" source-inplace) :command '("hdevtools" "check" source-inplace)
:error-patterns :error-patterns
`((,(concat "^\\(?1:.*?\\):\\(?2:[0-9]+\\):\\(?3:[0-9]+\\):[ \t\n\r]*" `((,(concat "^\\(?1:.*?\\):\\(?2:[0-9]+\\):\\(?3:[0-9]+\\):[ \t\n\r]*"
"\\(?5:Warning: \\)?"
"\\(?4:\\(.\\|[ \t\n\r]\\)+?\\)\\(^\n\\|\\'\\)") "\\(?4:\\(.\\|[ \t\n\r]\\)+?\\)\\(^\n\\|\\'\\)")
error)) (if (let ((out (match-string 5 output)))
(and out (string= out "Warning: ")))
'warning
'error)))
:modes 'haskell-mode) :modes 'haskell-mode)


(push 'haskell-hdevtools flycheck-checkers) (push 'haskell-hdevtools flycheck-checkers)
Expand Down Expand Up @@ -2097,27 +2105,90 @@ FORM => (eval FORM)."


(push 'bash flycheck-checkers) (push 'bash flycheck-checkers)


(defun my-ghc-flymake-display-errors () (flycheck-declare-checker xmllint
"xmllint checker"
:command '("xmllint" "--noout" "--postvalid" source)
:error-patterns
'(("^\\(?1:.*\\):\\(?2:[0-9]+\\): parser error : \\(?4:.*\\)$" error))
:modes 'nxml-mode)

(push 'xmllint flycheck-checkers)

(flycheck-declare-checker jslint
"jslint checker"
:command '("jsl" "-process" source)
:error-patterns
'(("^\\(?1:.*\\)(\\(?2:[0-9]+\\)): error: \\(?4:.*\\)$" error)
("^\\(?1:.*\\)(\\(?2:[0-9]+\\)): \\(\\(lint \\)?warning\\): \\(?4:.*\\)$"
warning))
:modes 'js2-mode)

(push 'jslint flycheck-checkers)

(flycheck-declare-checker clang++-ledger
"Clang++ checker for Ledger"
:command
'("clang++" "-Wall" "-fsyntax-only"
"-I/Users/johnw/Products/ledger/debug" "-I../lib"
"-I../lib/utfcpp/source"
"-I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7"
"-include" "system.hh" "-c" source-inplace)
:error-patterns
'(("^\\(?1:.*\\):\\(?2:[0-9]+\\):\\(?3:[0-9]+\\): warning:\\s-*\\(?4:.*\\)"
warning)
("^\\(?1:.*\\):\\(?2:[0-9]+\\):\\(?3:[0-9]+\\): error:\\s-*\\(?4:.*\\)"
error))
:modes 'c++-mode
:predicate '(string-match "/ledger/" (buffer-file-name)))

(push 'clang++-ledger flycheck-checkers)

(defun my-flycheck-show-error-in-window ()
(interactive)
(flycheck-cancel-error-display-timer)
(when flycheck-mode
(let ((buf (get-buffer-create "*Flycheck Info*"))
(message (car (flycheck-overlay-messages-at (point)))))
(with-current-buffer buf
(delete-region (point-min) (point-max))
(insert message))
(display-buffer buf)
(fit-window-to-buffer (get-buffer-window buf)))))

(defun flycheck-show-error-at-point ()
"Show the first error message at point in minibuffer."
(interactive) (interactive)
(let ((inhibit-redisplay t) (flycheck-cancel-error-display-timer)
(errs (ghc-flymake-err-list))) (when flycheck-mode
(if (= 1 (length errs)) (if (flycheck-may-show-message)
(message (car errs)) (let* ((buf (get-buffer-create "*Flycheck Info*"))
(ghc-flymake-display-errors) (wind (get-buffer-window buf))
(fit-window-to-buffer (get-buffer-window "*GHC Info*"))))) (message (car (flycheck-overlay-messages-at (point)))))
(if message
(if (> (length (split-string message "\n")) 8)
(my-flycheck-show-error-in-window)
(if wind (delete-window wind))
(message "%s" message))
(message nil)))
;; Try again if the minibuffer is busy at the moment
(flycheck-show-error-at-point-soon))))


(defun my-flycheck-mode-hook () (defun my-flycheck-mode-hook ()
(bind-key "M-?" 'flycheck-show-error-at-point flycheck-mode-map) (bind-key "M-?" 'my-flycheck-show-error-in-window flycheck-mode-map)
(bind-key "M-p" 'previous-error flycheck-mode-map) (bind-key "M-p" 'previous-error flycheck-mode-map)
(bind-key "M-n" 'next-error flycheck-mode-map)) (bind-key "M-n" 'next-error flycheck-mode-map))


(add-hook 'flycheck-mode-hook 'my-flycheck-mode-hook) (add-hook 'flycheck-mode-hook 'my-flycheck-mode-hook)


(add-hook 'prog-mode-hook 'flycheck-mode) (add-hook 'prog-mode-hook 'flycheck-mode)
(add-hook 'nxml-mode-hook 'flycheck-mode)
(add-hook 'js2-mode-hook 'flycheck-mode)
(add-hook 'haskell-mode-hook 'flycheck-mode)) (add-hook 'haskell-mode-hook 'flycheck-mode))


:config :config
(defalias 'flycheck-show-error-at-point-soon 'flycheck-show-error-at-point)) (progn
(defalias 'flycheck-show-error-at-point-soon 'flycheck-show-error-at-point)
(defalias 's-collapse-whitespace 'identity)))


;;;_ , flyspell ;;;_ , flyspell


Expand Down
1 change: 0 additions & 1 deletion settings.el
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@
'(haskell-indentation-ifte-offset 4) '(haskell-indentation-ifte-offset 4)
'(haskell-indentation-layout-offset 4) '(haskell-indentation-layout-offset 4)
'(haskell-indentation-left-offset 4) '(haskell-indentation-left-offset 4)
'(haskell-mode-hook (quote (turn-on-haskell-indentation turn-on-font-lock turn-on-haskell-decl-scan ghc-init my-haskell-mode-hook)))
'(haskell-program-name "ghci") '(haskell-program-name "ghci")
'(haskell-saved-check-command "~/.cabal/bin/hlint" t) '(haskell-saved-check-command "~/.cabal/bin/hlint" t)
'(hippie-expand-try-functions-list (quote (yas/hippie-try-expand try-complete-file-name-partially try-complete-file-name try-expand-all-abbrevs try-expand-list try-expand-line try-expand-dabbrev try-expand-dabbrev-all-buffers try-expand-dabbrev-from-kill try-complete-lisp-symbol-partially try-complete-lisp-symbol))) '(hippie-expand-try-functions-list (quote (yas/hippie-try-expand try-complete-file-name-partially try-complete-file-name try-expand-all-abbrevs try-expand-list try-expand-line try-expand-dabbrev try-expand-dabbrev-all-buffers try-expand-dabbrev-from-kill try-complete-lisp-symbol-partially try-complete-lisp-symbol)))
Expand Down
2 changes: 1 addition & 1 deletion site-lisp/flycheck

0 comments on commit d5e5d1e

Please sign in to comment.