Skip to content

Commit a10a600

Browse files
committed
Merge pull request #1100 from bergey/pr-haskell-goto-first-error
Implement haskell-goto-first-error
2 parents 6c09f0b + 788a70c commit a10a600

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

doc/haskell-mode.texi

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,21 @@ associated with at most one GHCi session, so when you call
723723
no session associated yet, you're asked which GHCi session to create or
724724
associate with.
725725

726+
@section Goto Error
727+
728+
In a Haskell source buffer associated with a GHCi session, errors that
729+
prevent the file from loading are highlighted with
730+
@code{haskell-error-face}. You can move between these error lines with
731+
732+
@table @kbd
733+
@item M-n
734+
is bound to @code{haskell-goto-next-error}
735+
@item M-p
736+
is bound to @code{haskell-goto-prev-error}
737+
@item C-c M-p
738+
is bound to @code{haskell-goto-first-error}
739+
@end table
740+
726741
@section Using GHCi-ng
727742

728743
Put @code{:set +c} in your @code{.ghci} or run it in the REPL. Then use

haskell-load.el

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ correspondingly-named overlay properties of OVL."
346346
(t
347347
(message "No further notes from Haskell compiler."))))
348348

349+
(defun haskell-goto-first-error ()
350+
(interactive)
351+
(haskell-goto-error-overlay
352+
(first-overlay-in-if 'haskell-check-overlay-p
353+
(buffer-end 0) (buffer-end 1))))
354+
349355
(defun haskell-goto-prev-error ()
350356
(interactive)
351357
(haskell-goto-error-overlay

haskell.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
(define-key map [?\C-c ?\C-z] 'haskell-interactive-switch)
5555
(define-key map (kbd "M-n") 'haskell-goto-next-error)
5656
(define-key map (kbd "M-p") 'haskell-goto-prev-error)
57+
(define-key map (kbd "C-c M-p") 'haskell-goto-first-error)
5758
map)
5859
"Keymap for using haskell-interactive-mode.")
5960

tests/haskell-load-tests.el

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
;;; haskell-load-tests.el
2+
3+
;;; Code:
4+
5+
(require 'ert)
6+
(require 'haskell-test-utils)
7+
8+
(require 'haskell-load)
9+
10+
(defun insert-errors ()
11+
(insert "import Control.Applicativ\nimport Data.Mayb\nimport Data.String")
12+
(goto-char 1)
13+
(let ((applicativ (progn
14+
(search-forward "Control.Applicativ")
15+
(make-overlay (match-beginning 0) (match-end 0)))))
16+
(overlay-put applicativ 'haskell-check t)
17+
(overlay-put applicativ 'haskell-msg-type 'error)
18+
(overlay-put applicativ 'haskell-msg "Could not find module ‘Control.Applicativ’\n Perhaps you meant Control.Applicative (from base-4.8.1.0)\n Use -v to see a list of the files searched for."))
19+
(let ((mayb (progn
20+
(search-forward "Data.Mayb")
21+
(make-overlay (match-beginning 0) (match-end 0)))))
22+
(overlay-put mayb 'haskell-check t)
23+
(overlay-put mayb 'haskell-msg-type 'error)
24+
(overlay-put mayb 'haskell-msg "Could not find module ‘Data.Mayb’\n Perhaps you meant\n Data.Maybe (from base-4.8.1.0)\n Data.Map (from containers-0.5.6.2@conta_LKCPrTJwOTOLk4OU37YmeN)\n Use -v to see a list of the files searched for."))
25+
(goto-char 1))
26+
27+
(ert-deftest goto-first-error-before ()
28+
(with-temp-switch-to-buffer
29+
(insert-errors)
30+
(haskell-goto-first-error)
31+
(should (looking-at-p "Control.Applicativ"))))
32+
33+
(ert-deftest goto-first-error-after ()
34+
(with-temp-switch-to-buffer
35+
(insert-errors)
36+
(search-forward "Data.String")
37+
(haskell-goto-first-error)
38+
(should (looking-at-p "Control.Applicativ"))))
39+
40+
(ert-deftest goto-first-error-between ()
41+
(with-temp-switch-to-buffer
42+
(insert-errors)
43+
(search-forward "import Data.Mayb")
44+
(haskell-goto-first-error)
45+
(should (looking-at-p "Control.Applicativ"))))
46+
47+
(ert-deftest goto-next-error-before ()
48+
(with-temp-switch-to-buffer
49+
(insert-errors)
50+
(haskell-goto-next-error)
51+
(should (looking-at-p "Control.Applicativ"))))
52+
53+
(ert-deftest goto-next-error-between ()
54+
(with-temp-switch-to-buffer
55+
(insert-errors)
56+
(search-forward "import" nil nil 2)
57+
(haskell-goto-next-error)
58+
(should (looking-at-p "Data.Mayb"))))
59+
60+
(ert-deftest goto-next-error-after ()
61+
(with-temp-switch-to-buffer
62+
(insert-errors)
63+
(search-forward "import" nil nil 3)
64+
(haskell-goto-next-error)
65+
(should (looking-at-p " Data.String"))))
66+
67+
(ert-deftest goto-prev-error-before ()
68+
(with-temp-switch-to-buffer
69+
(insert-errors)
70+
(haskell-goto-prev-error)
71+
(should (looking-at-p "import Control.Applicativ"))))
72+
73+
(ert-deftest goto-prev-error-between ()
74+
(with-temp-switch-to-buffer
75+
(insert-errors)
76+
(search-forward "import" nil nil 2)
77+
(haskell-goto-prev-error)
78+
(should (looking-at-p "Control.Applicativ"))))
79+
80+
(ert-deftest goto-prev-error-after ()
81+
(with-temp-switch-to-buffer
82+
(insert-errors)
83+
(search-forward "import Data.String")
84+
(haskell-goto-prev-error)
85+
(should (looking-at-p "Data.Mayb"))))

0 commit comments

Comments
 (0)