Skip to content

Commit 976917b

Browse files
committed
Add back padding option in haskell-align-imports (#183)
1 parent 3d834d4 commit 976917b

File tree

1 file changed

+55
-9
lines changed

1 file changed

+55
-9
lines changed

haskell-align-imports.el

+55-9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,30 @@
4848
;; When haskell-align-imports is run within the same buffer, the
4949
;; import list is transformed to:
5050
;;
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+
;;
5175
;; import One
5276
;; import Two as A
5377
;; import qualified Three
@@ -77,7 +101,18 @@
77101
(concat "^\\(import[ ]+\\)"
78102
"\\(qualified \\)?"
79103
"[ ]*\\(\"[^\"]*\" \\)?"
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)
81116

82117
;;;###autoload
83118
(defun haskell-align-imports ()
@@ -88,6 +123,8 @@
88123
(goto-char (point-min))
89124
(let* ((imports (haskell-align-imports-collect))
90125
(padding (haskell-align-imports-padding imports)))
126+
(loop for import in imports
127+
do (message "Import: %S" import))
91128
(mapc (lambda (x)
92129
(goto-char (cdr x))
93130
(delete-region (point) (line-end-position))
@@ -131,14 +168,23 @@
131168
"")
132169
b))
133170
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)))))))
142188

143189
(defun haskell-align-imports-chomp (str)
144190
"Chomp leading and tailing whitespace from STR."

0 commit comments

Comments
 (0)