@@ -53,18 +53,19 @@ within that region."
53
53
(progn (goto-char (region-beginning ))
54
54
(haskell-sort-imports-goto-import-start))
55
55
(haskell-sort-imports-goto-group-start))
56
- (let ((start (point ))
57
- (imports (haskell-sort-imports-collect-imports)))
58
- (delete-region start (point ))
59
- (mapc (lambda (import )
60
- (insert import " \n " ))
61
- (sort imports (lambda (a b )
62
- (string< (haskell-sort-imports-normalize a)
63
- (haskell-sort-imports-normalize b)))))
64
- (goto-char start)
65
- (when (search-forward current-string nil t 1 )
66
- (forward-char (- (length current-string)))
67
- (forward-char current-offset))))))
56
+ (let* ((start (point ))
57
+ (imports (haskell-sort-imports-collect-imports))
58
+ (sorted (sort (copy-list imports)
59
+ (lambda (a b )
60
+ (string< (haskell-sort-imports-normalize a)
61
+ (haskell-sort-imports-normalize b))))))
62
+ (when (not (equal imports sorted))
63
+ (delete-region start (point ))
64
+ (mapc (lambda (import ) (insert import " \n " )) sorted))
65
+ (goto-char start)
66
+ (when (search-forward current-string nil t 1 )
67
+ (forward-char (- (length current-string)))
68
+ (forward-char current-offset))))))
68
69
69
70
(defun haskell-sort-imports-normalize (i )
70
71
" Normalize an import, if possible, so that it can be sorted."
0 commit comments