Skip to content

Commit

Permalink
Make indentation configurable and default to d2 fmt indent
Browse files Browse the repository at this point in the history
The `d2 fmt` will indent with 2 spaces, hence it is a good default.
  • Loading branch information
terlar committed Oct 3, 2024
1 parent 69374e0 commit 51d0231
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions d2-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
:group 'd2
:type '(repeat string))

(defcustom d2-indent 2
"Number of columns to indent d2 blocks."
:group 'd2
:type 'integer
:safe #'integerp)

(defconst d2-font-lock-keywords
`((,(regexp-opt '("shape" "md" ) 'words) . font-lock-keyword-face)
("---\\|-?->*\\+?\\|==>\\|===|->" . font-lock-variable-name-face)
Expand Down Expand Up @@ -262,11 +268,11 @@ and the indentation of the previous line."

((and (d2--decl-tags-contain current-token 'node)
(d2--decl-tags-contain previous-token 'subnode))
(+ 4 (d2--decl-column previous-token)))
(+ d2-indent (d2--decl-column previous-token)))

((and (d2--decl-tags-contain current-token 'subnode)
(d2--decl-tags-contain previous-token 'subnode))
(+ 4 (d2--decl-column previous-token)))
(+ d2-indent (d2--decl-column previous-token)))


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

((and (d2--decl-tags-contain current-token 'end)
(d2--decl-tags-contain previous-token 'end))
(max (- (d2--decl-column previous-token) 4) 0))
(max (- (d2--decl-column previous-token) d2-indent) 0))

((and (d2--decl-tags-contain current-token 'end)
(d2--decl-tags-contain previous-token 'subnode))
(d2--decl-column previous-token))

((and (d2--decl-tags-contain current-token 'end)
(d2--decl-tags-contain previous-token 'node))
(max (- (d2--decl-column previous-token) 4) 0))
(max (- (d2--decl-column previous-token) d2-indent) 0))

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

0 comments on commit 51d0231

Please sign in to comment.