From 51c34f8494e932c1975cb1458e903b3eb2c26617 Mon Sep 17 00:00:00 2001 From: Jason Jackson <550839+jasonjckn@users.noreply.github.com> Date: Sat, 31 Oct 2026 02:39:42 -0700 Subject: [PATCH] Don't reindent lines inside docstrings --- CHANGELOG.md | 1 + clojure-ts-mode.el | 7 +-- test/clojure-ts-mode-indentation-test.el | 70 ++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76c4ff0..0e9c06c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el index b8a1855..005d4aa 100644 --- a/clojure-ts-mode.el +++ b/clojure-ts-mode.el @@ -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." diff --git a/test/clojure-ts-mode-indentation-test.el b/test/clojure-ts-mode-indentation-test.el index 110000d..2faef50 100644 --- a/test/clojure-ts-mode-indentation-test.el +++ b/test/clojure-ts-mode-indentation-test.el @@ -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]"