Skip to content

Proper fix for prog-fill-reindent-defun - #164

Merged
bbatsov merged 2 commits into
clojure-emacs:mainfrom
rrudakov:fix/indent-defun
Nov 7, 2026
Merged

bbatsov merged 2 commits into
clojure-emacs:mainfrom
rrudakov:fix/indent-defun

Conversation

@rrudakov

Copy link
Copy Markdown
Contributor

The fix introduced in #161 is incorrect, it sets prog-fill-reindent-defun to the default implementation which doesn't use Tree-sitter at all. The issue was in the way we used to set treesit-defun-type-regexp. Any top-level expression was considered a defun. This commit changes the predicate lambda, so only the direct children of "source" node are considered as defun's and additionally, if clojure-ts-toplevel-inside-comment-form is true, the direct children of the rich comment forms.


Before submitting a PR mark the checkboxes for the items you've done (if you
think a checkbox does not apply, then leave it unchecked):

  • You've run M-x checkdoc and fixed any warnings in the code you've written.
  • You've updated the changelog (if adding/changing user-visible functionality).
  • You've updated the readme (if adding/changing user-visible functionality).

Thanks!

@rrudakov
rrudakov force-pushed the fix/indent-defun branch 3 times, most recently from 5f5aff7 to cf263f3 Compare November 1, 2026 14:39
The fix introduced in clojure-emacs#161 is incorrect, it sets `prog-fill-reindent-defun` to
the default implementation which doesn't use Tree-sitter at all.  The issue was
in the way we used to set `treesit-defun-type-regexp`.  Any top-level expression
was considered a defun.  This commit changes the predicate lambda, so only the
direct children of "source" node are considered as defun's and additionally, if
`clojure-ts-toplevel-inside-comment-form` is true, the direct children of the
rich comment forms.
Emacs-32 introduced setopt-local and added extra validation for defcustoms.  If
defcustom with :set function is set via .dir-locals.el it must support 3-args
arity.
@rrudakov

rrudakov commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Emacs 32 now refuses setting variables with :set function from .dir-locals.el if setter doesn't support 3-arguments arity. This is actually visible in the CI logs from the main branch (https://github.com/clojure-emacs/clojure-ts-mode/actions/runs/41298557092/job/124824528357):

[22](https://github.com/clojure-emacs/clojure-ts-mode/actions/runs/41298557092/job/124824528357#step:5:123)
options set in .dir-locals.el
  should apply to the buffers in the directory, and only to those (14.88ms)
Warning (emacs): The setter of clojure-ts-indent-style lacks support for setopt-local
Warning (emacs): The setter of clojure-ts-extra-def-forms lacks support for setopt-local
Warning (emacs): The setter of clojure-ts-comment-macro-font-lock-body lacks support for setopt-local

But I'm not sure why tests pass on main.

Another issue was that clojure-ts--apply-local-variables didn't set indent-region-function according to clojure-ts-align-forms-automatically value, so clojure-ts-align-forms-automatically didn't have any effect in .dir-locals.el and indent-region-function was always set to default treesit-indent-region.

@bbatsov
bbatsov merged commit 4730922 into clojure-emacs:main Nov 7, 2026
5 checks passed
bbatsov added a commit that referenced this pull request Nov 7, 2026
Since #164 indent-region-function was only set when
clojure-ts-align-forms-automatically was on as the mode started, so
turning it on later in an open buffer, with setopt or setq-local, left
indent-region unaligned.  clojure-ts-indent-region checks the option
when it runs, which is also what makes a directory-local value work, so
it can be set unconditionally again.
bbatsov added a commit that referenced this pull request Nov 7, 2026
#164 made the setters take the buffer-local argument setopt-local
passes, but then they only set the variable: a buffer kept the
indentation rules of its old style, and its old faces until something
refontified it.  A directory-local value worked anyway, because
clojure-ts--apply-local-variables runs after it's set.
bbatsov added a commit that referenced this pull request Nov 7, 2026
#172 removed clojure-ts--markdown-inline-sexp-nodes along with its only
use, and #164 brought it back while rebasing.
@rrudakov
rrudakov deleted the fix/indent-defun branch November 7, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants