diff --git a/elisp/ghc-command.el b/elisp/ghc-command.el index 8ffa01b..14da057 100644 --- a/elisp/ghc-command.el +++ b/elisp/ghc-command.el @@ -19,8 +19,10 @@ (beginning-of-line) (looking-at "^[^ ]+ *::")) (ghc-insert-function-template)) + ((ghc-flymake-have-errs-p) + (ghc-flymake-insert-from-warning)) (t - (ghc-flymake-insert-type)))) + (message "Nothing to be done")))) (defun ghc-insert-module-template () ;; xxx mod from filename... diff --git a/elisp/ghc-flymake.el b/elisp/ghc-flymake.el index b8514f1..9163e15 100644 --- a/elisp/ghc-flymake.el +++ b/elisp/ghc-flymake.el @@ -34,43 +34,57 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defun ghc-display-errors () +(defun ghc-flymake-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))) + (if (not (ghc-flymake-have-errs-p)) + (message "No errors or warnings") + (let ((buf (get-buffer-create ghc-error-buffer-name)) + (title (ghc-flymake-err-title)) + (errs (ghc-flymake-err-list))) + (with-current-buffer buf + (erase-buffer) + (ghc-flymake-insert-errors title errs)) + (display-buffer buf)))) -(defun ghc-insert-errors (data) - (let ((title (nth 0 data)) - (errs (nth 1 data))) +(defun ghc-flymake-insert-errors (title errs) + (save-excursion (insert title "\n") - (dolist (err errs) - (insert (ghc-replace-character (car err) ghc-null ghc-newline) "\n")) - (goto-char (point-min)))) + (mapc (lambda (x) (insert x "\n")) errs))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defun ghc-flymake-insert-type () +(defun ghc-flymake-insert-from-warning () (interactive) - (let ((data (ghc-flymake-first-data))) - (if (and data - (string-match "Inferred type: \\([^:]+ :: \\)\\(forall [^.]+\\. \\)?\\([^\0]*\\)" data)) - (progn + (dolist (data (ghc-flymake-err-list)) + (save-excursion + (cond + ((string-match "Inferred type: \\([^:]+ :: \\)\\(forall [^.]+\\. \\)?\\([^\0]*\\)" data) (beginning-of-line) (insert (match-string 1 data) (match-string 3 data) "\n")) - (message "No inferred type")))) + ((string-match "Not in scope: `\\([^']+\\)'" data) + (save-match-data + (unless (re-search-forward "^$" nil t) + (goto-char (point-max)) + (insert "\n"))) + (insert "\n" (match-string 1 data) " = undefined\n")))))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defun ghc-flymake-err-get-title (x) (nth 0 x)) +(defun ghc-flymake-err-get-errs (x) (nth 1 x)) + +(defalias 'ghc-flymake-have-errs-p 'ghc-flymake-data) + (defun ghc-flymake-data () (let* ((line-no (flymake-current-line-no)) (info (nth 0 (flymake-find-err-info flymake-err-info line-no)))) (flymake-make-err-menu-data line-no info))) -(defun ghc-flymake-first-data () - (nth 0 (nth 0 (nth 1 (ghc-flymake-data))))) +(defun ghc-flymake-err-title () + (ghc-flymake-err-get-title (ghc-flymake-data))) -(provide 'ghc-flymake) \ No newline at end of file +(defun ghc-flymake-err-list () + (mapcar 'car (ghc-flymake-err-get-errs (ghc-flymake-data)))) + +(provide 'ghc-flymake) diff --git a/elisp/ghc.el b/elisp/ghc.el index ee3a87e..d022738 100644 --- a/elisp/ghc.el +++ b/elisp/ghc.el @@ -57,7 +57,7 @@ (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-next-key 'flymake-goto-next-error) - (define-key haskell-mode-map ghc-help-key 'ghc-display-errors) + (define-key haskell-mode-map ghc-help-key 'ghc-flymake-display-errors) (define-key haskell-mode-map ghc-insert-key 'ghc-insert-template) (define-key haskell-mode-map ghc-sort-key 'ghc-sort-lines) (define-key haskell-mode-map ghc-check-key 'ghc-save-buffer)