File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 30
30
31
31
; ;; Code:
32
32
33
+ (defvar haskell-sort-imports-regexp
34
+ (concat " ^import[ ]+"
35
+ " \\ (qualified \\ )?"
36
+ " [ ]*\\ (\" [^\" ]*\" \\ )?"
37
+ " [ ]*\\ ([A-Za-z0-9_.']*.*\\ )" ))
38
+
33
39
;;;### autoload
34
40
(defun haskell-sort-imports ()
35
41
(interactive )
@@ -52,12 +58,21 @@ within that region."
52
58
(delete-region start (point ))
53
59
(mapc (lambda (import )
54
60
(insert import " \n " ))
55
- (sort imports #'string< ))
61
+ (sort imports (lambda (a b )
62
+ (string< (haskell-sort-imports-normalize a)
63
+ (haskell-sort-imports-normalize b)))))
56
64
(goto-char start)
57
65
(when (search-forward current-string nil t 1 )
58
66
(forward-char (- (length current-string)))
59
67
(forward-char current-offset))))))
60
68
69
+ (defun haskell-sort-imports-normalize (i )
70
+ " Normalize an import, if possible, so that it can be sorted."
71
+ (if (string-match haskell-sort-imports-regexp
72
+ i)
73
+ (match-string 3 i)
74
+ i))
75
+
61
76
(defun haskell-sort-imports-collect-imports ()
62
77
(let ((imports (list )))
63
78
(while (looking-at " import" )
You can’t perform that action at this time.
0 commit comments