insert foo = undefined if "No inferred type".
insert guessed type even if it is contains in second line or later.
This commit is contained in:
parent
5c4ded0630
commit
baa65be4a6
@ -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...
|
||||
|
@ -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)))
|
||||
|
||||
(defun ghc-flymake-err-list ()
|
||||
(mapcar 'car (ghc-flymake-err-get-errs (ghc-flymake-data))))
|
||||
|
||||
(provide 'ghc-flymake)
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user