Skip to content

Commit 5c52695

Browse files
authored
[Fix #30] Add clojure-ts-toplevel-inside-comment-form (#31)
This is the equivalent to clojure-toplevel-inside-comment-form in clojure-mode.
1 parent 8e61fe8 commit 5c52695

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## main (unreleased)
44

5+
- Add custom option `clojure-ts-toplevel-inside-comment-form` as an equivalent to `clojure-toplevel-inside-comment-form` in clojure-mode (#30)
6+
57
## 0.2.0
68

79
- Pin grammar revision in treesit-language-source-alist

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ Too highlight entire rich `comment` expression with the comment font face, set
3939
By default this is `nil`, so that anything within a `comment` expression is
4040
highlighted like regular clojure code.
4141

42+
### Navigation and Evaluation
43+
44+
To make forms inside of `(comment ...)` forms appear as toplevel forms for evaluation and navigation, set
45+
46+
``` emacs-lisp
47+
(setq clojure-ts-toplevel-inside-comment-form t)
48+
```
49+
4250
## Rationale
4351

4452
[clojure-mode](https://github.com/clojure-emacs/clojure-mode) has served us well

clojure-ts-mode.el

+10-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ itself."
9393
:type 'boolean
9494
:package-version '(clojure-ts-mode . "0.2.0"))
9595

96+
(defcustom clojure-ts-toplevel-inside-comment-form nil
97+
"Eval top level forms inside comment forms instead of the comment form itself."
98+
:type 'boolean
99+
:safe #'booleanp
100+
:package-version '(clojure-ts-mode . "0.2.1"))
101+
96102
(defvar clojure-ts--debug nil
97103
"Enables debugging messages, shows current node in mode-line.
98104
Only intended for use at development time.")
@@ -911,7 +917,10 @@ See `clojure-ts--font-lock-settings' for usage of MARKDOWN-AVAILABLE."
911917
(setq-local treesit-defun-prefer-top-level t)
912918
(setq-local treesit-defun-tactic 'top-level)
913919
(setq-local treesit-defun-type-regexp
914-
(rx (or "list_lit" "vec_lit" "map_lit")))
920+
(cons (rx (or "list_lit" "vec_lit" "map_lit"))
921+
(lambda (node)
922+
(or (not clojure-ts-toplevel-inside-comment-form)
923+
(not (clojure-ts--definition-node-p "comment" node))))))
915924
(setq-local treesit-simple-indent-rules
916925
(clojure-ts--configured-indent-rules))
917926
(setq-local treesit-defun-name-function

0 commit comments

Comments
 (0)