@@ -97,6 +97,21 @@ itself."
9797  :safe  #'booleanp  
9898  :package-version  '(clojure-ts-mode .  " 0.2.1"  ))
9999
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+ 
100115(defvar  clojure-ts--debug  nil 
101116  " Enables debugging messages, shows current node in mode-line.
102117Only intended for use at development time."  )
@@ -863,6 +878,27 @@ forms like deftype, defrecord, reify, proxy, etc."
863878        '(semantic fixed )
864879        clojure-ts-indent-style)))))
865880
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+ 
866902(defconst  clojure-ts--sexp-nodes 
867903  '(" #_"   ; ; transpose-sexp near a discard macro moves it around.
868904    " 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."
963999                (keyword string char symbol builtin type)
9641000                (constant number quote  metadata doc)
9651001                (bracket deref function regex tagged-literals)))
1002+   (setq-local  fill-paragraph-function #'clojure-ts--fill-paragraph  )
9661003  (when  (boundp  'treesit-thing-settings ) ; ; Emacs 30+
9671004    (setq-local  treesit-thing-settings clojure-ts--thing-settings)))
9681005
0 commit comments