From 7e9d992defe2d74e65cf571d0bf20fe49f330d64 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Fri, 14 Jan 2011 13:38:12 +0900 Subject: [PATCH] perfect insertion of guessed type. --- elisp/ghc-flymake.el | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/elisp/ghc-flymake.el b/elisp/ghc-flymake.el index 4d3a292..397d552 100644 --- a/elisp/ghc-flymake.el +++ b/elisp/ghc-flymake.el @@ -74,16 +74,30 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defun ghc-extract-type (str) + (with-temp-buffer + (insert str) + (goto-char (point-min)) + (when (re-search-forward "Inferred type: " nil t) + (delete-region (point-min) (point))) + (when (re-search-forward "forall [^.]+\\. " nil t) + (replace-match "")) + (while (re-search-forward "\0 +" nil t) + (replace-match " ")) + (goto-char (point-min)) + (while (re-search-forward "\\[Char\\]" nil t) + (replace-match "String")) + (re-search-forward "\0" nil t) + (buffer-substring-no-properties (point-min) (1- (point))))) + (defun ghc-flymake-insert-from-warning () (interactive) (dolist (data (ghc-flymake-err-list)) (save-excursion (cond - ((string-match "Inferred type: \\([^:]+ :: \\)\\(forall [^.]+\\.\\( \\|\0 +\\)\\)?\\([^\0]*\\)" data) + ((string-match "Inferred type: " data) (beginning-of-line) - (insert (match-string 1 data) - (replace-regexp-in-string "\\[Char\\]" "String" (match-string 4 data)) - "\n")) + (insert (ghc-extract-type data) "\n")) ((string-match "lacks an accompanying binding" data) (beginning-of-line) (when (looking-at "^\\([^ ]+\\) *::")