Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clojure-ts-toplevel-inside-comment-form #31

Merged
merged 2 commits into from
Feb 7, 2024
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## main (unreleased)

- Add custom option `clojure-ts-toplevel-inside-comment-form` as an equivalent to `clojure-toplevel-inside-comment-form` in clojure-mode (#30)

## 0.2.0

- Pin grammar revision in treesit-language-source-alist
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ Too highlight entire rich `comment` expression with the comment font face, set
By default this is `nil`, so that anything within a `comment` expression is
highlighted like regular clojure code.

### Navigation and Evaluation

To make forms inside of `(comment ...)` forms appear as toplevel forms for evaluation and navigation, set

``` emacs-lisp
(setq clojure-ts-toplevel-inside-comment-form t)
```

## Rationale

[clojure-mode](https://github.com/clojure-emacs/clojure-mode) has served us well
Expand Down
11 changes: 10 additions & 1 deletion clojure-ts-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ itself."
:type 'boolean
:package-version '(clojure-ts-mode . "0.2.0"))

(defcustom clojure-ts-toplevel-inside-comment-form nil
"Eval top level forms inside comment forms instead of the comment form itself."
:type 'boolean
:safe #'booleanp
:package-version '(clojure-ts-mode . "0.2.1"))

(defvar clojure-ts--debug nil
"Enables debugging messages, shows current node in mode-line.
Only intended for use at development time.")
Expand Down Expand Up @@ -911,7 +917,10 @@ See `clojure-ts--font-lock-settings' for usage of MARKDOWN-AVAILABLE."
(setq-local treesit-defun-prefer-top-level t)
(setq-local treesit-defun-tactic 'top-level)
(setq-local treesit-defun-type-regexp
(rx (or "list_lit" "vec_lit" "map_lit")))
(cons (rx (or "list_lit" "vec_lit" "map_lit"))
(lambda (node)
(or (not clojure-ts-toplevel-inside-comment-form)
(not (clojure-ts--definition-node-p "comment" node))))))
(setq-local treesit-simple-indent-rules
(clojure-ts--configured-indent-rules))
(setq-local treesit-defun-name-function
Expand Down