Skip to content

Commit

Permalink
Merge pull request haskell#1165 from haskell/revert-1121-gman/fix-1109
Browse files Browse the repository at this point in the history
Revert "Remove suggested imports completely"
  • Loading branch information
chrisdone committed Feb 19, 2016
2 parents 1e86061 + b9df600 commit 7430512
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
29 changes: 6 additions & 23 deletions haskell-interactive-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ SESSION in specified FILE to remove IMPORT on given LINE."
(cl-case (read-event
(propertize (format "%sThe import line `%s' is redundant. Remove? (y, n, c: comment out) "
(if (not first)
"Please answer y, n or c: "
"Please answer n, y or c: "
"")
import)
'face
Expand All @@ -594,38 +594,21 @@ SESSION in specified FILE to remove IMPORT on given LINE."
(save-excursion
(goto-char (point-min))
(forward-line (1- line))
(let ((bounds (haskell-interactive-mode--import-statement-bounds)))
(delete-region (car bounds) (cdr bounds))
(kill-line 1))))
(goto-char (line-beginning-position))
(delete-region (line-beginning-position)
(line-end-position))))
(?n
(message "Ignoring redundant import %s" import))
(?c
(haskell-process-find-file session file)
(save-excursion
(goto-char (point-min))
(forward-line (1- line))
(let ((bounds (haskell-interactive-mode--import-statement-bounds)))
(comment-region (car bounds) (cdr bounds))))))
(goto-char (line-beginning-position))
(insert "-- "))))
;; unwind
(haskell-mode-toggle-interactive-prompt-state t))))

(defun haskell-interactive-mode--import-statement-bounds ()
"For internal use in `haskell-process-suggest-remove-import'.
This function supposed to be called having point placed on first
line of import statement, if this is a case it search import
statement bounds relying on layout and returns them as cons cell;
otherwise returns nil."
(save-excursion
(goto-char (line-beginning-position))
(when (looking-at-p (regexp-quote "import"))
(let ((a (point))
(z (line-end-position)))
(forward-line 1)
(while (looking-at-p (rx (and not-newline (1+ whitespace))))
(setq z (line-end-position))
(forward-line 1))
(cons a z)))))

(defun haskell-process-find-file (session file)
"Find the given file in the project."
(find-file (cond ((file-exists-p (concat (haskell-session-current-dir session) "/" file))
Expand Down
11 changes: 5 additions & 6 deletions tests/interactive-haskell-mode-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,20 @@
(require 'ert)
(require 'haskell-interactive-mode)

(defun should-match (str)
(should (eq 0 (string-match-p haskell-interactive-mode-error-regexp str))))

(ert-deftest haskell-interactive-error-regexp-test ()
"Tests the regexp `haskell-interactive-mode-error-regexp'"
(should (eq 0 (string-match-p haskell-interactive-mode-error-regexp
"/home/user/Test.hs:24:30:")))
(should (eq 0 (string-match-p haskell-interactive-mode-error-regexp
"Test.hs:5:18:")))
(should (eq 0 (string-match-p
haskell-interactive-mode-error-regexp
"Test.hs:7:6: Not in scope: type constructor or class ‘Ty’")))
(should (eq 0 (string-match-p haskell-interactive-mode-error-regexp
"Test.hs:7:6: Not in scope: type constructor or class ‘Ty’")))
(should (eq 0 (string-match-p haskell-interactive-mode-error-regexp
"Test.hs:9:5: Not in scope: ‘c’")))
(should (eq nil (string-match-p haskell-interactive-mode-error-regexp
;; leading space
" Test.hs:8:9:")))
)

(provide 'interactive-haskell-mode-tests)
;;; interactive-haskell-mode-tests.el ends here

0 comments on commit 7430512

Please sign in to comment.