@@ -97,6 +97,21 @@ itself."
97
97
:safe #'booleanp
98
98
:package-version '(clojure-ts-mode . " 0.2.1" ))
99
99
100
+ (defcustom clojure-ts-docstring-fill-column fill-column
101
+ " Value of `fill-column' to use when filling a docstring."
102
+ :type 'integer
103
+ :safe #'integerp
104
+ :package-version '(clojure-ts-mode . " 0.2.3" ))
105
+
106
+ (defcustom clojure-ts-docstring-fill-prefix-width 2
107
+ " Width of `fill-prefix' when filling a docstring.
108
+ The default value conforms with the de facto convention for
109
+ Clojure docstrings, aligning the second line with the opening
110
+ double quotes on the third column."
111
+ :type 'integer
112
+ :safe #'integerp
113
+ :package-version '(clojure-ts-mode . " 0.2.3" ))
114
+
100
115
(defvar clojure-ts--debug nil
101
116
" Enables debugging messages, shows current node in mode-line.
102
117
Only intended for use at development time." )
@@ -863,6 +878,27 @@ forms like deftype, defrecord, reify, proxy, etc."
863
878
'(semantic fixed )
864
879
clojure-ts-indent-style)))))
865
880
881
+ (defun clojure-ts--docstring-fill-prefix ()
882
+ " The prefix string used by `clojure-ts--fill-paragraph' .
883
+ It is simply `clojure-ts-docstring-fill-prefix-width' number of spaces."
884
+ (make-string clojure-ts-docstring-fill-prefix-width ? ))
885
+
886
+ (defun clojure-ts--fill-paragraph (&optional justify )
887
+ " Like `fill-paragraph' , but can handler Clojure docstrings.
888
+ If JUSTIFY is non-nil, justify as well as fill the paragraph."
889
+ (let ((current-node (treesit-node-at (point ))))
890
+ (if (clojure-ts--match-docstring nil current-node nil )
891
+ (let ((fill-column (or clojure-ts-docstring-fill-column fill-column))
892
+ (fill-prefix (clojure-ts--docstring-fill-prefix))
893
+ (beg-doc (treesit-node-start current-node))
894
+ (end-doc (treesit-node-end current-node)))
895
+ (save-restriction
896
+ (narrow-to-region beg-doc end-doc)
897
+ (fill-paragraph justify)))
898
+ (or (fill-comment-paragraph justify)
899
+ (fill-paragraph justify)))
900
+ t ))
901
+
866
902
(defconst clojure-ts--sexp-nodes
867
903
'(" #_" ; ; transpose-sexp near a discard macro moves it around.
868
904
" num_lit" " sym_lit" " kwd_lit" " nil_lit" " bool_lit"
@@ -963,6 +999,7 @@ See `clojure-ts--font-lock-settings' for usage of MARKDOWN-AVAILABLE."
963
999
(keyword string char symbol builtin type)
964
1000
(constant number quote metadata doc)
965
1001
(bracket deref function regex tagged-literals)))
1002
+ (setq-local fill-paragraph-function #'clojure-ts--fill-paragraph )
966
1003
(when (boundp 'treesit-thing-settings ) ; ; Emacs 30+
967
1004
(setq-local treesit-thing-settings clojure-ts--thing-settings)))
968
1005
0 commit comments