Skip to content

Commit e01f269

Browse files
committed
Complete module header indentation issues
1 parent 4e98595 commit e01f269

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

sysver-bnf.el

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
"Define a grammar for the language to be given to SMIE")
121121

122122
;; indentation rules
123-
(setq smie-indent-basic sysver-default-indent) ; big to be sure it has an effect
124123
(defun sysver-smie-rules (kind token)
125124

126125
;; -----------------------------------------------------------------------------------------------
@@ -140,15 +139,15 @@
140139
;; the following sequence of rules are always run in sequence until the first one returns non-nil
141140
(cond
142141
;; default rules
143-
;; ('(:elem . args) smie-indent-basic)
144-
;; ('(:elem . basic) smie-indent-basic)
142+
;; ('(:elem . args) sysver-default-indent)
143+
;; ('(:elem . basic) sysver-default-indent)
145144
((and (eq kind :elem) (equal token 'empty-line-token))
146145
0)
147146

148147
;; ----------------------------------------------------------------------------------------------
149148
;; module structure
150149
((and (eq kind :before) (member token `("(" ,smie-syntoken-params-start-list)))
151-
smie-indent-basic)
150+
sysver-default-indent)
152151
((and (eq kind :before) (equal token ","))
153152
;; align to the end of "#(" and "(" start-list-delimiters
154153
(save-excursion
@@ -176,11 +175,15 @@
176175
;; loops (for, while)
177176

178177
;; case
178+
179+
;; as all these rules are applied in order and the function exits as the first returns non-nil,
180+
;; here the default option is placed
181+
;; (t sysver-default-indent)
179182
)
180183

181184
;; (pcase (cons method arg)
182185
;; ('(:before . "endmodule") 0)
183-
;; ('(:before . ";") smie-indent-basic)
186+
;; ('(:before . ";") sysver-default-indent)
184187
;; )
185188
)
186189

sysver.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ This is useful to let the user customize it via the customization options"
252252
;; re-fontify current buffer as the defaults are directly changed
253253
(font-lock-refresh-defaults)
254254

255-
;; set up indentation engine
255+
;; set up the indentation engine SMIE
256+
(setq smie-indent-basic sysver-default-indent)
256257
(smie-setup sysver-smie-grammar #'sysver-smie-rules
257258
:forward-token #'sysver-forward-token
258259
:backward-token #'sysver-backward-token)

test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ test_files := $(wildcard *.el)
2323
all: $(test_files)
2424

2525
$(test_files):
26-
emacs -batch -l ../sysver.el -l ert -l $@ -f ert-run-tests-batch-and-exit
26+
emacs -batch -L ../ -L . -l ert -l $@ -f ert-run-tests-batch-and-exit

test/sysver-indent.el

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
(make-string indent-test ?\ ) "(param3, param4, param5)\n"
1717
"endmodule")
1818
,(concat "module a_module_name_id1 #(param0,\n"
19-
(make-string (+ indent-test 2) ?\ ) "param1, param2)\n"
19+
;; The list of parameters after the first one in the previous line
20+
;; is indented to the parameter-list starting column.
21+
(make-string (+ (length "module a_module_name_id0 ") 2) ?\ )
22+
"param1, param2)\n"
2023
(make-string indent-test ?\ ) "(param3, param4, param5)\n"
2124
"endmodule")
2225
,(concat "module a_module_name_id2\n"
@@ -43,7 +46,6 @@
4346
(setq current-string (pop strings))
4447
(with-temp-buffer
4548
(sysver-utc-environment
46-
4749
current-string
4850

4951
;; set-up indentation parameters
@@ -53,4 +55,5 @@
5355
((save-excursion
5456
(indent-region (point-min) (point-max)))
5557
;; verify
56-
(should (equal (buffer-string) current-string))))))))))
58+
(should (equal (buffer-substring-no-properties (point-min) (point-max))
59+
current-string))))))))))

0 commit comments

Comments
 (0)