M-t inserts inferred type!
This commit is contained in:
parent
91c04be421
commit
14ef0f8372
20
Check.hs
20
Check.hs
@ -18,17 +18,23 @@ checkSyntax opt file = do
|
|||||||
(_,_,herr,_) <- runInteractiveProcess (ghc opt) ["--make","-Wall",file,"-outputdir","dist/flymake","-o","dist/flymake/a.out"] Nothing Nothing
|
(_,_,herr,_) <- runInteractiveProcess (ghc opt) ["--make","-Wall",file,"-outputdir","dist/flymake","-o","dist/flymake/a.out"] Nothing Nothing
|
||||||
refine <$> hGetContents herr
|
refine <$> hGetContents herr
|
||||||
where
|
where
|
||||||
refine = unfoldLines start . map (dropWhile isSpace) . filter (/="") . lines
|
refine = unfoldLines . map shrinkSpaces . remove . lines
|
||||||
start = (file `isPrefixOf`)
|
remove = filter (\x -> not ("Linking" `isPrefixOf` x))
|
||||||
|
. filter (\x -> not ("[" `isPrefixOf` x))
|
||||||
|
. filter (/="")
|
||||||
|
shrinkSpaces x
|
||||||
|
| isSpace (head x) = ' ' : dropWhile isSpace x
|
||||||
|
| otherwise = x
|
||||||
|
|
||||||
unfoldLines :: (String -> Bool) -> [String] -> String
|
unfoldLines :: [String] -> String
|
||||||
unfoldLines _ [] = ""
|
unfoldLines [] = ""
|
||||||
unfoldLines p (x:xs) = x ++ unfold xs
|
unfoldLines (x:xs) = x ++ unfold xs
|
||||||
where
|
where
|
||||||
unfold [] = "\n"
|
unfold [] = "\n"
|
||||||
unfold (l:ls)
|
unfold (l:ls)
|
||||||
| p l = ('\n':l) ++ unfold ls
|
| isAlpha (head l) = ('\n':l) ++ unfold ls
|
||||||
| otherwise = (' ' :l) ++ unfold ls
|
| " Inferred" `isPrefixOf` l = "." ++ l ++ unfold ls
|
||||||
|
| otherwise = l ++ unfold ls
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -29,4 +29,20 @@
|
|||||||
(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-flymake-insert-type ()
|
||||||
|
(interactive)
|
||||||
|
(let ((data (ghc-flymake-data)))
|
||||||
|
(if (and data
|
||||||
|
(string-match "Inferred type: \\([^:]+ :: \\)\\(forall [^.]+\\. \\)?\\(.*\\)" data))
|
||||||
|
(progn
|
||||||
|
(beginning-of-line)
|
||||||
|
(insert (match-string 1 data) (match-string 3 data) "\n"))
|
||||||
|
(message "No inferred type"))))
|
||||||
|
|
||||||
|
(defun ghc-flymake-data ()
|
||||||
|
(let* ((line-no (flymake-current-line-no))
|
||||||
|
(line-err-info-list (nth 0 (flymake-find-err-info flymake-err-info line-no)))
|
||||||
|
(menu-data (flymake-make-err-menu-data line-no line-err-info-list)))
|
||||||
|
(nth 0 (nth 0 (nth 1 menu-data)))))
|
||||||
|
|
||||||
(provide 'ghc-flymake)
|
(provide 'ghc-flymake)
|
26
elisp/ghc.el
26
elisp/ghc.el
@ -30,12 +30,13 @@
|
|||||||
;;; Customize Variables
|
;;; Customize Variables
|
||||||
;;;
|
;;;
|
||||||
|
|
||||||
(defvar ghc-completion-key "\e\t")
|
(defvar ghc-completion-key "\e\t")
|
||||||
(defvar ghc-document-key "\e\C-d")
|
(defvar ghc-document-key "\e\C-d")
|
||||||
(defvar ghc-import-key "\e\C-m")
|
(defvar ghc-import-key "\e\C-m")
|
||||||
(defvar ghc-previous-key "\ep")
|
(defvar ghc-previous-key "\ep")
|
||||||
(defvar ghc-next-key "\en")
|
(defvar ghc-next-key "\en")
|
||||||
(defvar ghc-help-key "\e?")
|
(defvar ghc-help-key "\e?")
|
||||||
|
(defvar ghc-insert-type-key "\et")
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;;
|
;;;
|
||||||
@ -46,12 +47,13 @@
|
|||||||
|
|
||||||
(defun ghc-init ()
|
(defun ghc-init ()
|
||||||
(unless ghc-initialized
|
(unless ghc-initialized
|
||||||
(define-key haskell-mode-map ghc-completion-key 'ghc-complete)
|
(define-key haskell-mode-map ghc-completion-key 'ghc-complete)
|
||||||
(define-key haskell-mode-map ghc-document-key 'ghc-browse-document)
|
(define-key haskell-mode-map ghc-document-key 'ghc-browse-document)
|
||||||
(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 'flymake-display-err-menu-for-current-line)
|
||||||
|
(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)))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user