Skip to content

Commit

Permalink
Merge pull request #52 from terlar/main
Browse files Browse the repository at this point in the history
Make indentation configurable and default to d2 fmt indent
  • Loading branch information
andorsk authored Nov 7, 2024
2 parents 69374e0 + 51d0231 commit ec1d6a1
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 ec1d6a1

Please sign in to comment.