|
48 | 48 | ;; When haskell-align-imports is run within the same buffer, the
|
49 | 49 | ;; import list is transformed to:
|
50 | 50 | ;;
|
| 51 | +;; import "abc" Eight |
| 52 | +;; import qualified Eighteen as PRELUDE hiding (A) |
| 53 | +;; import qualified "defg" Eleven as PRELUDE |
| 54 | +;; import Fifteen hiding (A) |
| 55 | +;; import Five (A) |
| 56 | +;; import qualified Four as PRELUDE |
| 57 | +;; import qualified "z" Fourteen (A,B) |
| 58 | +;; import "abc" Nine as TWO |
| 59 | +;; import "abc" Nineteen hiding (A) |
| 60 | +;; import One |
| 61 | +;; import qualified Seven (A,B) |
| 62 | +;; import qualified Seventeen hiding (A) |
| 63 | +;; import Six (A,B) |
| 64 | +;; import Sixteen as TWO hiding (A) |
| 65 | +;; import qualified "abc" Ten |
| 66 | +;; import "zotconpop" Thirteen (A,B) |
| 67 | +;; import qualified Three |
| 68 | +;; import "barmu" Twelve (A) |
| 69 | +;; import "abc" Twenty as TWO hiding (A) |
| 70 | +;; import Two as A |
| 71 | +;; |
| 72 | +;; If you want everything after module names to be padded out, too, |
| 73 | +;; customize `haskell-align-imports-pad-after-name', and you'll get: |
| 74 | +;; |
51 | 75 | ;; import One
|
52 | 76 | ;; import Two as A
|
53 | 77 | ;; import qualified Three
|
|
77 | 101 | (concat "^\\(import[ ]+\\)"
|
78 | 102 | "\\(qualified \\)?"
|
79 | 103 | "[ ]*\\(\"[^\"]*\" \\)?"
|
80 |
| - "[ ]*\\([A-Za-z0-9_.']*.*\\)")) |
| 104 | + "[ ]*\\([A-Za-z0-9_.']+\\)" |
| 105 | + "[ ]*\\([ ]*as [A-Z][^ ]*\\)?" |
| 106 | + "[ ]*\\((.*)\\)?" |
| 107 | + "\\([ ]*hiding (.*)\\)?" |
| 108 | + "\\( -- .*\\)?[ ]*$") |
| 109 | + "Regex used for matching components of an import.") |
| 110 | + |
| 111 | +(defcustom haskell-align-imports-pad-after-name |
| 112 | + nil |
| 113 | + "Pad layout after the module name also." |
| 114 | + :type 'boolean |
| 115 | + :group 'haskell-interactive) |
81 | 116 |
|
82 | 117 | ;;;###autoload
|
83 | 118 | (defun haskell-align-imports ()
|
|
88 | 123 | (goto-char (point-min))
|
89 | 124 | (let* ((imports (haskell-align-imports-collect))
|
90 | 125 | (padding (haskell-align-imports-padding imports)))
|
| 126 | + (loop for import in imports |
| 127 | + do (message "Import: %S" import)) |
91 | 128 | (mapc (lambda (x)
|
92 | 129 | (goto-char (cdr x))
|
93 | 130 | (delete-region (point) (line-end-position))
|
|
131 | 168 | "")
|
132 | 169 | b))
|
133 | 170 | ls))))
|
134 |
| - (list (funcall join (list (aref parts 0) |
135 |
| - (aref parts 1) |
136 |
| - (aref parts 2))) |
137 |
| - (aref parts 3) |
138 |
| - (funcall join (list (aref parts 4) |
139 |
| - (aref parts 5) |
140 |
| - (aref parts 6))) |
141 |
| - (aref parts 7)))) |
| 171 | + (if haskell-align-imports-pad-after-name |
| 172 | + (list (funcall join (list (aref parts 0) |
| 173 | + (aref parts 1) |
| 174 | + (aref parts 2))) |
| 175 | + (aref parts 3) |
| 176 | + (funcall join (list (aref parts 4) |
| 177 | + (aref parts 5) |
| 178 | + (aref parts 6))) |
| 179 | + (aref parts 7)) |
| 180 | + (list (funcall join (list (aref parts 0) |
| 181 | + (aref parts 1) |
| 182 | + (aref parts 2))) |
| 183 | + (funcall join (list (aref parts 3) |
| 184 | + (aref parts 4) |
| 185 | + (aref parts 5) |
| 186 | + (aref parts 6) |
| 187 | + (aref parts 7))))))) |
142 | 188 |
|
143 | 189 | (defun haskell-align-imports-chomp (str)
|
144 | 190 | "Chomp leading and tailing whitespace from STR."
|
|
0 commit comments