Skip to content

Commit 51d0231

Browse files
committed
Make indentation configurable and default to d2 fmt indent
The `d2 fmt` will indent with 2 spaces, hence it is a good default.
1 parent 69374e0 commit 51d0231

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

d2-mode.el

+10-4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@
8989
:group 'd2
9090
:type '(repeat string))
9191

92+
(defcustom d2-indent 2
93+
"Number of columns to indent d2 blocks."
94+
:group 'd2
95+
:type 'integer
96+
:safe #'integerp)
97+
9298
(defconst d2-font-lock-keywords
9399
`((,(regexp-opt '("shape" "md" ) 'words) . font-lock-keyword-face)
94100
("---\\|-?->*\\+?\\|==>\\|===|->" . font-lock-variable-name-face)
@@ -262,11 +268,11 @@ and the indentation of the previous line."
262268

263269
((and (d2--decl-tags-contain current-token 'node)
264270
(d2--decl-tags-contain previous-token 'subnode))
265-
(+ 4 (d2--decl-column previous-token)))
271+
(+ d2-indent (d2--decl-column previous-token)))
266272

267273
((and (d2--decl-tags-contain current-token 'subnode)
268274
(d2--decl-tags-contain previous-token 'subnode))
269-
(+ 4 (d2--decl-column previous-token)))
275+
(+ d2-indent (d2--decl-column previous-token)))
270276

271277

272278
((and (d2--decl-tags-contain current-token 'node)
@@ -279,15 +285,15 @@ and the indentation of the previous line."
279285

280286
((and (d2--decl-tags-contain current-token 'end)
281287
(d2--decl-tags-contain previous-token 'end))
282-
(max (- (d2--decl-column previous-token) 4) 0))
288+
(max (- (d2--decl-column previous-token) d2-indent) 0))
283289

284290
((and (d2--decl-tags-contain current-token 'end)
285291
(d2--decl-tags-contain previous-token 'subnode))
286292
(d2--decl-column previous-token))
287293

288294
((and (d2--decl-tags-contain current-token 'end)
289295
(d2--decl-tags-contain previous-token 'node))
290-
(max (- (d2--decl-column previous-token) 4) 0))
296+
(max (- (d2--decl-column previous-token) d2-indent) 0))
291297

292298
(t (progn (message "uknown syntax %s" current-token)
293299
(d2--decl-column current-token)))))))

0 commit comments

Comments
 (0)