Repository navigation
Docstring indentation, option A (pick one of #167/#168): leave docstring text alone, like cljfmt - #167
Closed
jasonjckn wants to merge 1 commit into
Closed
Docstring indentation, option A (pick one of #167/#168): leave docstring text alone, like cljfmt#167jasonjckn wants to merge 1 commit into
jasonjckn wants to merge 1 commit into
Conversation
Merged
3 of 4 tasks
Member
|
Closing in favor of #168, which indents docstrings the way clojure-mode does. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is one of two alternative PRs for the same problem: #167 leaves docstring text alone (like cljfmt), #168 indents docstrings like clojure-mode. Please merge at most one; we'll close the other.
indent-regionnever re-indents lines inside a docstring. Removes a rule.indent-regionapplies clojure-mode's docstring rule, with and without Markdown. Adds a rule for both parsers.indent-regionchanges the text of docstrings, and how it changes them depends onclojure-ts-use-markdown-inlineand on whether the markdown-inline grammar is installed. With Markdown on, only the closing"moves. With Markdown off, every line moves to the opening quote's column + 1, which flattens indented code examples and undoes whatM-qjust did.This PR removes the docstring indentation rule, so
indent-regionleaves every line inside a docstring as it is, in both settings. This is what cljfmt does.Background
We found this by comparing clojure-mode's and clojure-ts-mode's
indent-regionover 73 real-world files (as-is, and with indentation stripped), using a formatter that runsindent-regionin batch Emacs.What each tool does to a line inside a top-level docstring:
main, markdown-inline on (default)main, markdown-inline off"at col 0M-qjust filled (col 2)"→ quote col"→ quote colclojure-in-docstring-pis true, and that checks forfont-lock-doc-face. So in an unfontified (batch) buffer clojure-mode never touches docstrings and looks like cljfmt; in a normal fontified buffer it moves lines indented less thanclojure-docstring-fill-prefix-widthto that column and keeps deeper lines.treesit-language-ata content line ismarkdown-inline, andtreesit-simple-indent-ruleshas only aclojureentry, so those lines are left alone. The closing"belongs to the Clojure parser (parentstr_lit), soclojure-ts--match-docstringfires and anchors it at the opening quote.M-q:clojure-ts--fill-paragraphusesclojure-ts-docstring-fill-prefix-width(2) spaces from column 0, like clojure-mode. With Markdown off,indent-regionthen moves those lines to column 3.This PR matches cljfmt, and clojure-mode in unfontified/batch use. #168 matches clojure-mode in normal fontified buffers instead.
Examples
Input:
clojure-ts-mode
main, markdown-inline on:clojure-ts-mode
main, markdown-inline off:With this PR (either setting), and cljfmt (same as the input):
clojure-mode 5.19, fontified buffer:
Tests
This PR adds a
Docstring indentationgroup, run once withclojure-ts-use-markdown-inlinenil and once with t (the t case is skipped withassumewhen the markdown-inline grammar isn't installed):should preserve every docstring line: fails onmainin both settings, passes with this PR.should preserve protocol-method docstrings: fails onmainin both settings, passes with this PR.should preserve ordinary strings: a control; passes onmainand with this PR.How it was checked locally (Eldev isn't installed here, so these are the same steps run directly):
byte-compile-error-on-warngives no warnings; checkdoc is clean; the changed.elfiles are indented asemacs-lisp-modeindents them.Notes
M-qstill fills docstrings withclojure-ts-docstring-fill-prefix-width.clojure-ts--match-docstringstays, sinceclojure-ts--fill-paragraphuses it. No other indent rule matches a line inside a docstring.About this PR
The code, tests and this description were generated by an AI (Claude, by Anthropic), at @jasonjckn's request. If AI-generated contributions are a problem for this project, please feel free to close this PR and #168 right away.
M-x checkdocand fixed any warnings in the code you've written.