Skip to content
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

## main (unreleased)

- [#NNN](https://github.com/clojure-emacs/clojure-ts-mode/pull/NNN): Stop `indent-region` from changing the text of docstrings, which it did differently with and without `clojure-ts-use-markdown-inline`.
- Fix indentation of namespaced maps in `fixed` indentation style.
- Add project root detection for ClojureCLR project.
- Add missing `defstruct` semantic indentation rule.
Expand Down
7 changes: 1 addition & 6 deletions clojure-ts-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1668,12 +1668,7 @@ used."
;; https://guide.clojure.style/#one-space-indent
((parent-is "^list_lit$") parent 1)
((parent-is "^anon_fn_lit$") parent 2)
(clojure-ts--match-with-metadata parent 0)
;; This is slow and only matches when point is inside of a docstring and
;; only when Markdown grammar is disabled. `indent-region' tries to match
;; all the rules from top to bottom, so order matters here (the slowest
;; rules should be at the bottom).
(clojure-ts--match-docstring parent 0))))
(clojure-ts--match-with-metadata parent 0))))

(defun clojure-ts--configured-indent-rules ()
"Return the configured indent rules."
Expand Down
70 changes: 70 additions & 0 deletions test/clojure-ts-mode-indentation-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,76 @@ DESCRIPTION is a string with the description of the spec."
((string-equal symbol-name "my.alias/my-letfn") '(1 ((:defn)) :form)))))


(describe "Docstring indentation"
(dolist (markdown-inline '(nil t))
(describe (format "with markdown-inline %s" markdown-inline)
(it "should preserve every docstring line"
(when markdown-inline
(assume (treesit-ready-p 'markdown-inline t)))
(let ((clojure-ts-use-markdown-inline markdown-inline))
(with-clojure-ts-buffer "(defn example
\"Summary.
content
(code example)

\"
[]
:ok)
"
(font-lock-ensure)
(indent-region (point-min) (point-max))
(expect (buffer-string) :to-equal "(defn example
\"Summary.
content
(code example)

\"
[]
:ok)
"))))
(it "should preserve protocol-method docstrings"
(when markdown-inline
(assume (treesit-ready-p 'markdown-inline t)))
(let ((clojure-ts-use-markdown-inline markdown-inline))
(with-clojure-ts-buffer "(defprotocol Example
(method [this]
\"Summary.
content
(code example)

\"))
"
(font-lock-ensure)
(indent-region (point-min) (point-max))
(expect (buffer-string) :to-equal "(defprotocol Example
(method [this]
\"Summary.
content
(code example)

\"))
"))))
(it "should preserve ordinary strings"
(when markdown-inline
(assume (treesit-ready-p 'markdown-inline t)))
(let ((clojure-ts-use-markdown-inline markdown-inline))
(with-clojure-ts-buffer "(def value
\"Ordinary string.
content
(code example)

\")
"
(font-lock-ensure)
(indent-region (point-min) (point-max))
(expect (buffer-string) :to-equal "(def value
\"Ordinary string.
content
(code example)

\")
")))))))

(describe "indentation"
(it "should not hang on end of buffer"
(with-clojure-ts-buffer "(let [a b]"
Expand Down
Loading