Skip to content

Commit 4e126e1

Browse files
committed
Merge pull request #1121 from geraldus/gman/fix-1109
Remove suggested imports completely
2 parents 3475238 + d32dca5 commit 4e126e1

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

haskell-interactive-mode.el

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ SESSION in specified FILE to remove IMPORT on given LINE."
581581
(cl-case (read-event
582582
(propertize (format "%sThe import line `%s' is redundant. Remove? (y, n, c: comment out) "
583583
(if (not first)
584-
"Please answer n, y or c: "
584+
"Please answer y, n or c: "
585585
"")
586586
import)
587587
'face
@@ -591,21 +591,38 @@ SESSION in specified FILE to remove IMPORT on given LINE."
591591
(save-excursion
592592
(goto-char (point-min))
593593
(forward-line (1- line))
594-
(goto-char (line-beginning-position))
595-
(delete-region (line-beginning-position)
596-
(line-end-position))))
594+
(let ((bounds (haskell-interactive-mode--import-statement-bounds)))
595+
(delete-region (car bounds) (cdr bounds))
596+
(kill-line 1))))
597597
(?n
598598
(message "Ignoring redundant import %s" import))
599599
(?c
600600
(haskell-process-find-file session file)
601601
(save-excursion
602602
(goto-char (point-min))
603603
(forward-line (1- line))
604-
(goto-char (line-beginning-position))
605-
(insert "-- "))))
604+
(let ((bounds (haskell-interactive-mode--import-statement-bounds)))
605+
(comment-region (car bounds) (cdr bounds))))))
606606
;; unwind
607607
(haskell-mode-toggle-interactive-prompt-state t))))
608608

609+
(defun haskell-interactive-mode--import-statement-bounds ()
610+
"For internal use in `haskell-process-suggest-remove-import'.
611+
This function supposed to be called having point placed on first
612+
line of import statement, if this is a case it search import
613+
statement bounds relying on layout and returns them as cons cell;
614+
otherwise returns nil."
615+
(save-excursion
616+
(goto-char (line-beginning-position))
617+
(when (looking-at-p (regexp-quote "import"))
618+
(let ((a (point))
619+
(z (line-end-position)))
620+
(forward-line 1)
621+
(while (looking-at-p (rx (and not-newline (1+ whitespace))))
622+
(setq z (line-end-position))
623+
(forward-line 1))
624+
(cons a z)))))
625+
609626
(defun haskell-process-find-file (session file)
610627
"Find the given file in the project."
611628
(find-file (cond ((file-exists-p (concat (haskell-session-current-dir session) "/" file))

tests/interactive-haskell-mode-tests.el

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,21 @@
3232
(require 'ert)
3333
(require 'haskell-interactive-mode)
3434

35-
(defun should-match (str)
36-
(should (eq 0 (string-match-p haskell-interactive-mode-error-regexp str))))
37-
3835
(ert-deftest haskell-interactive-error-regexp-test ()
3936
"Tests the regexp `haskell-interactive-mode-error-regexp'"
4037
(should (eq 0 (string-match-p haskell-interactive-mode-error-regexp
4138
"/home/user/Test.hs:24:30:")))
4239
(should (eq 0 (string-match-p haskell-interactive-mode-error-regexp
4340
"Test.hs:5:18:")))
44-
(should (eq 0 (string-match-p haskell-interactive-mode-error-regexp
45-
"Test.hs:7:6: Not in scope: type constructor or class ‘Ty’")))
41+
(should (eq 0 (string-match-p
42+
haskell-interactive-mode-error-regexp
43+
"Test.hs:7:6: Not in scope: type constructor or class ‘Ty’")))
4644
(should (eq 0 (string-match-p haskell-interactive-mode-error-regexp
4745
"Test.hs:9:5: Not in scope: ‘c’")))
4846
(should (eq nil (string-match-p haskell-interactive-mode-error-regexp
4947
;; leading space
5048
" Test.hs:8:9:")))
5149
)
50+
51+
(provide 'interactive-haskell-mode-tests)
52+
;;; interactive-haskell-mode-tests.el ends here

0 commit comments

Comments
 (0)