2014-08-07 14:59:18 +00:00
|
|
|
;; Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
;; Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
;;
|
|
|
|
;; Author: Soonho Kong
|
|
|
|
;;
|
|
|
|
|
2014-08-14 00:02:49 +00:00
|
|
|
(require 'lean-settings)
|
2014-09-15 20:02:02 +00:00
|
|
|
(require 'lean-option)
|
2014-08-14 00:02:49 +00:00
|
|
|
|
2015-03-05 19:42:59 +00:00
|
|
|
(defun lean-toggle-flycheck-mode ()
|
|
|
|
"Toggle flycheck-mode"
|
|
|
|
(interactive)
|
|
|
|
(cond
|
|
|
|
(flycheck-mode (flycheck-mode -1))
|
|
|
|
(t (flycheck-mode 1))))
|
|
|
|
|
2014-08-13 22:06:22 +00:00
|
|
|
(defun lean-flycheck-command ()
|
2014-08-25 18:25:36 +00:00
|
|
|
"Concat lean-flychecker-checker-name with options"
|
2014-09-19 16:37:56 +00:00
|
|
|
(let ((command
|
|
|
|
(cl-concatenate 'list
|
|
|
|
`(,(lean-get-executable lean-flycheck-checker-name))
|
|
|
|
lean-flycheck-checker-options
|
|
|
|
'("--cache")
|
|
|
|
'(source-original)
|
2014-09-30 01:19:08 +00:00
|
|
|
'((eval (lean-option-string t)))
|
2014-09-19 16:37:56 +00:00
|
|
|
'("--")
|
|
|
|
'(source-inplace))))
|
|
|
|
(when (string= system-type "windows-nt")
|
|
|
|
(setq command (cons "python" command)))
|
|
|
|
command))
|
2014-08-07 20:48:08 +00:00
|
|
|
|
|
|
|
(defun lean-flycheck-init ()
|
|
|
|
"Initialize lean-flychek checker"
|
2014-08-25 18:25:36 +00:00
|
|
|
(eval
|
|
|
|
`(flycheck-define-checker lean-checker
|
|
|
|
"A Lean syntax checker."
|
|
|
|
:command ,(lean-flycheck-command)
|
|
|
|
:error-patterns
|
2014-09-19 16:37:56 +00:00
|
|
|
((error line-start "FLYCHECK_BEGIN ERROR" (? "\r") "\n"
|
2014-09-15 03:23:25 +00:00
|
|
|
(file-name) ":" line ":" (? column ":") " error: "
|
2014-08-25 18:25:36 +00:00
|
|
|
(minimal-match
|
2014-10-29 22:54:36 +00:00
|
|
|
(message (one-or-more (zero-or-more not-newline) (? "\r") "\n")))
|
2014-09-30 21:14:11 +00:00
|
|
|
"FLYCHECK_END" (? "\r") line-end)
|
2014-11-24 16:35:49 +00:00
|
|
|
(warning line-start "FLYCHECK_BEGIN INFORMATION" (? "\r") "\n"
|
|
|
|
(file-name) ":" line ":" (? column ":") " information: "
|
|
|
|
(minimal-match
|
|
|
|
(message (one-or-more (zero-or-more not-newline) (? "\r") "\n")))
|
|
|
|
"FLYCHECK_END" (? "\r") line-end)
|
2014-11-26 17:35:22 +00:00
|
|
|
;; (warning line-start "FLYCHECK_BEGIN WARNING" (? "\r") "\n"
|
|
|
|
;; (file-name) ":" line ":" (? column ":") " warning: "
|
|
|
|
;; (minimal-match
|
|
|
|
;; (message (one-or-more (zero-or-more not-newline) (? "\r") "\n")))
|
|
|
|
;; "FLYCHECK_END" (? "\r") line-end)
|
|
|
|
)
|
2014-08-25 18:25:36 +00:00
|
|
|
:modes (lean-mode)))
|
|
|
|
(add-to-list 'flycheck-checkers 'lean-checker))
|
2014-08-07 20:48:08 +00:00
|
|
|
|
|
|
|
(defun lean-flycheck-turn-on ()
|
|
|
|
(interactive)
|
|
|
|
(unless lean-flycheck-use
|
|
|
|
(when (interactive-p)
|
|
|
|
(message "use flycheck in lean-mode"))
|
|
|
|
(setq lean-flycheck-use t))
|
|
|
|
(flycheck-mode t))
|
|
|
|
|
|
|
|
(defun lean-flycheck-turn-off ()
|
|
|
|
(interactive)
|
|
|
|
(when lean-flycheck-use
|
|
|
|
(when (interactive-p)
|
|
|
|
(message "no flycheck in lean-mode")))
|
|
|
|
(flycheck-mode 0)
|
|
|
|
(setq lean-flycheck-use nil))
|
|
|
|
|
|
|
|
(defun lean-flycheck-toggle-use ()
|
|
|
|
(interactive)
|
|
|
|
(if lean-flycheck-use
|
|
|
|
(lean-flycheck-turn-off)
|
|
|
|
(lean-flycheck-turn-on)))
|
|
|
|
|
2014-08-15 16:07:50 +00:00
|
|
|
(eval-after-load "flycheck"
|
2014-08-14 18:21:09 +00:00
|
|
|
'(defadvice flycheck-try-parse-error-with-pattern
|
|
|
|
(after lean-flycheck-try-parse-error-with-pattern activate)
|
|
|
|
"Add 1 to error-column."
|
|
|
|
(let* ((err ad-return-value)
|
2014-11-24 10:06:51 +00:00
|
|
|
(col (and err (flycheck-error-column err))))
|
2014-08-14 18:21:09 +00:00
|
|
|
(when (and (string= major-mode "lean-mode") col)
|
|
|
|
(setf (flycheck-error-column ad-return-value) (1+ col))))))
|
|
|
|
|
2014-09-05 23:08:54 +00:00
|
|
|
(defun lean-flycheck-delete-temporaries ()
|
|
|
|
"Delete temporaries files generated by flycheck."
|
|
|
|
(when (eq major-mode 'lean-mode)
|
|
|
|
(let* ((filename (buffer-file-name))
|
|
|
|
(tempname (format "%s_%s"
|
|
|
|
flycheck-temp-prefix
|
|
|
|
(file-name-nondirectory filename)))
|
|
|
|
(tempbase (file-name-base tempname))
|
|
|
|
(tempfile (expand-file-name tempbase
|
|
|
|
(file-name-directory filename)))
|
2014-09-09 06:48:39 +00:00
|
|
|
(exts '(".ilean" ".d" ".olean"))
|
2014-09-05 23:08:54 +00:00
|
|
|
(tempfiles (--map (concat tempfile it) exts)))
|
|
|
|
(mapc #'flycheck-safe-delete tempfiles))))
|
|
|
|
|
2014-09-30 01:19:08 +00:00
|
|
|
|
|
|
|
(defun lean-flycheck-error-list-buffer-width ()
|
|
|
|
"Return the width of flycheck-error list buffer"
|
|
|
|
(interactive)
|
|
|
|
(let* ((flycheck-error-window (get-buffer-window "*Flycheck errors*" t))
|
|
|
|
(window (selected-window))
|
|
|
|
(body-width (window-body-width window)))
|
|
|
|
(cond
|
|
|
|
;; If "*Flycheck errors" buffer is available, use its width
|
|
|
|
(flycheck-error-window
|
|
|
|
(window-body-width flycheck-error-window))
|
|
|
|
;; If lean-flycheck-msg-width is set, use it
|
|
|
|
(lean-flycheck-msg-width
|
|
|
|
lean-flycheck-msg-width)
|
|
|
|
;; Can we split vertically?
|
|
|
|
((window-splittable-p window nil)
|
|
|
|
body-width)
|
|
|
|
;; Can we split horizontally?
|
|
|
|
((window-splittable-p window t)
|
|
|
|
(/ body-width 2))
|
|
|
|
;; In worst case, just use the same width of current window
|
|
|
|
(t body-width))))
|
|
|
|
|
2014-08-07 14:59:18 +00:00
|
|
|
(provide 'lean-flycheck)
|