Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make indentation configurable and default to d2 fmt indent #52

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -218,7 +224,7 @@
"Get the column number from DECL. It is the third item."
(cddr decl))
(defun d2--decl-tags-contain (decl tag)
"Check if any of the tags in DECL matches TAG."

Check failure on line 227 in d2-mode.el

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 26.3)

Probably "matches" should be imperative "match"

Check failure on line 227 in d2-mode.el

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 27.2)

Probably "matches" should be imperative "match"

Check failure on line 227 in d2-mode.el

View workflow job for this annotation

GitHub Actions / build (windows-latest, 26.3)

Probably "matches" should be imperative "match"
(seq-find (lambda (tag2)
(equal tag2 tag))
(d2--decl-tag decl)))
Expand Down Expand Up @@ -262,11 +268,11 @@

((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 (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
Loading