@@ -581,7 +581,7 @@ SESSION in specified FILE to remove IMPORT on given LINE."
581
581
(cl-case (read-event
582
582
(propertize (format " %s The import line `%s' is redundant. Remove? (y, n, c: comment out) "
583
583
(if (not first)
584
- " Please answer n, y or c: "
584
+ " Please answer y, n or c: "
585
585
" " )
586
586
import)
587
587
'face
@@ -591,21 +591,38 @@ SESSION in specified FILE to remove IMPORT on given LINE."
591
591
(save-excursion
592
592
(goto-char (point-min ))
593
593
(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 ))))
597
597
(?n
598
598
(message " Ignoring redundant import %s " import))
599
599
(?c
600
600
(haskell-process-find-file session file)
601
601
(save-excursion
602
602
(goto-char (point-min ))
603
603
(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)) ))))
606
606
; ; unwind
607
607
(haskell-mode-toggle-interactive-prompt-state t ))))
608
608
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
+
609
626
(defun haskell-process-find-file (session file )
610
627
" Find the given file in the project."
611
628
(find-file (cond ((file-exists-p (concat (haskell-session-current-dir session) " /" file))
0 commit comments