Skip to content

Commit ae3790a

Browse files
committed
Allow user to configure highlighting comment macro body
Either highlight the body normally, or the entire thing as a comment
1 parent 9fb5739 commit ae3790a

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

clojure-ts-mode.el

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
;; Maintainer: Danny Freeman <[email protected]>
77
;; URL: http://github.com/clojure-emacs/clojure-ts-mode
88
;; Keywords: languages clojure clojurescript lisp
9-
;; Version: 0.1.2
9+
;; Version: 0.1.3
1010
;; Package-Requires: ((emacs "29"))
1111

1212
;; This file is not part of GNU Emacs.
@@ -61,6 +61,13 @@
6161
(declare-function treesit-node-child "treesit.c")
6262
(declare-function treesit-node-child-by-field-name "treesit.c")
6363

64+
(defgroup clojure-ts nil
65+
"Major mode for editing Clojure code with tree-sitter."
66+
:prefix "clojure-ts-"
67+
:group 'languages
68+
:link '(url-link :tag "GitHub" "https://github.com/clojure-emacs/clojure-ts-mode")
69+
:link '(emacs-commentary-link :tag "Commentary" "clojure-mode"))
70+
6471
(defconst clojure-ts-mode-version
6572
(eval-when-compile
6673
(lm-version (or load-file-name buffer-file-name)))
@@ -258,7 +265,8 @@ Only intended for use at development time.")
258265
"defstruct")
259266
line-end))
260267

261-
(defvar clojure-ts--font-lock-settings
268+
(defun clojure-ts--font-lock-settings ()
269+
"Return font lock settings suitable for use in `treesit-font-lock-settings'."
262270
(treesit-font-lock-rules
263271
:feature 'string
264272
:language 'clojure
@@ -375,12 +383,15 @@ Only intended for use at development time.")
375383
:feature 'comment
376384
:language 'clojure
377385
:override t
378-
'((comment) @font-lock-comment-face
386+
`((comment) @font-lock-comment-face
379387
(dis_expr
380388
marker: "#_" @font-lock-comment-delimiter-face
381389
value: _ @font-lock-comment-face)
382-
((list_lit :anchor (sym_lit (sym_name) @font-lock-comment-delimiter-face))
383-
(:match "^comment$" @font-lock-comment-delimiter-face)))
390+
(,(append
391+
'(list_lit :anchor (sym_lit) @font-lock-comment-delimiter-face)
392+
(when clojure-ts-comment-macro-font-lock-body
393+
'(_ :* @font-lock-comment-face)))
394+
(:match "^\\(\\(clojure.core/\\)?comment\\)$" @font-lock-comment-delimiter-face)))
384395

385396
:feature 'deref ;; not part of clojure-mode, but a cool idea?
386397
:language 'clojure
@@ -522,6 +533,18 @@ Includes a dispatch value when applicable (defmethods)."
522533
By default `treesit-defun-name-function' is used to extract definition names.
523534
See `clojure-ts--standard-definition-node-name' for the implementation used.")
524535

536+
(defcustom clojure-ts-comment-macro-font-lock-body nil
537+
"Highlight the entire body of a comment macro as a comment.
538+
539+
When set to a non-nil value, applies the comment font-locking face to the entire
540+
body of comment macros.
541+
When nil (the default), the body of comment macros uses default font-locking
542+
rules for whatever expressions are in the body, except for the comment symbol
543+
itself."
544+
:safe #'booleanp
545+
:type 'boolean
546+
:package-version '(clojure-ts-mode . "0.1.3"))
547+
525548
(defvar clojure-ts--fixed-indent-rules
526549
;; This is in contrast to semantic
527550
;; fixed-indent-rules come from https://tonsky.me/blog/clojurefmt/
@@ -585,7 +608,7 @@ See `clojure-ts--standard-definition-node-name' for the implementation used.")
585608
(setq-local comment-start ";")
586609
(when (treesit-ready-p 'clojure)
587610
(treesit-parser-create 'clojure)
588-
(setq-local treesit-font-lock-settings clojure-ts--font-lock-settings
611+
(setq-local treesit-font-lock-settings (clojure-ts--font-lock-settings)
589612
treesit-defun-prefer-top-level t
590613
treesit-defun-tactic 'top-level
591614
treesit-defun-type-regexp (rx (or "list_lit" "vec_lit" "map_lit"))

0 commit comments

Comments
 (0)