Skip to content

Commit 64d8fde

Browse files
committed
Semantic indentation docs
This style tries to emualte cljfmt's default settings. There are different styles of semantic formatting so this will be one option, maybe more in the future.
1 parent 85871fd commit 64d8fde

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

clojure-ts-mode.el

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,14 @@ By default `treesit-defun-name-function' is used to extract definition names.
499499
See `clojure-ts--standard-definition-node-name' for the implementation used.")
500500

501501
(defcustom clojure-ts-indent-style 'semantic
502-
"Automatic indentation style to use when mode clojure-ts-mode is run
502+
"Automatic indentation style to use when mode `clojure-ts-mode' is run.
503503
504504
The possible values for this variable are
505-
`semantic' - Tries to follow the same rules as the clojure style guide.
506-
See: https://guide.clojure.style/
505+
`semantic' - Semantic indentation.
506+
Tries to follow the same rules as cljfmt with default settings.
507+
See:
508+
- https://github.com/weavejester/cljfmt
509+
- https://guide.clojure.style/
507510
`fixed' - A simpler set of indentation rules that can be summarized as
508511
1. Multi-line lists that start with a symbol are always indented with
509512
two spaces.
@@ -512,8 +515,8 @@ The possible values for this variable are
512515
See: https://tonsky.me/blog/clojurefmt/"
513516
:safe #'symbolp
514517
:type
515-
'(choice (const :tag "Semantic indent rules, matching clojure style guide." semantic)
516-
(const :tag "Simple fixed indent rules." fixed))
518+
'(choice (const :tag "Semantic indentation rules." semantic)
519+
(const :tag "Simple fixed indentation rules." fixed))
517520
:package-version '(clojure-ts-mode . "0.2.0"))
518521

519522
(defvar clojure-ts--fixed-indent-rules
@@ -655,7 +658,8 @@ See `treesit-simple-indent-rules'."
655658
((eq clojure-ts-indent-style 'fixed) clojure-ts--fixed-indent-rules)
656659
(t (error
657660
(format
658-
"Invalid value for clojure-ts-indent-style. Valid values are 'semantic or 'fixed. Found %S"
661+
"Invalid value for clojure-ts-indent-style. Expected one of '%S, but found '%S instead."
662+
'(semantic fixed)
659663
clojure-ts-indent-style)))))
660664

661665
(defvar clojure-ts-mode-map

test/indentation.clj

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1+
(ns indentation
2+
(:require
3+
[clojure.string :as str])
4+
(:import
5+
(java.util Date
6+
UUID)))
7+
18
; https://tonsky.me/blog/clojurefmt/#ok-what-do-we-do-then
29
(when something
310
body)
411

12+
(defmethod dispatch :on-me
13+
[x]
14+
(bar x))
15+
516
(defn f [x]
617
body)
718

19+
(defn f
20+
([x] (f x nil))
21+
([x y] ))
22+
823
(defn f
924
[x]
1025
body)
@@ -34,12 +49,12 @@
3449

3550
; second cond is not aligned
3651
(or (condition-a)
37-
(condition-b))
52+
(condition-b))
3853

3954
; or/and are the only forms where this looks not ideal
4055
; other forms don’t win/lose much because of this change
4156
(filter even?
42-
(range 1 10))
57+
(range 1 10))
4358

4459
; my way is actually better if fn name is looooooooooong
4560
(clojure.core/filter even?

0 commit comments

Comments
 (0)