@@ -133,6 +133,17 @@ double quotes on the third column."
133133 :type 'boolean
134134 :package-version '(clojure-ts-mode . " 0.3" ))
135135
136+ (defcustom clojure-ts-outline-variant 'comments
137+ " Determines how `clojure-ts-mode' integrates with `outline-minor-mode' .
138+
139+ If set to the symbol `comments' , then top-level comments starting with
140+ three or more semicolons will be treated as outline headings. If set to
141+ `imenu' , then def-like forms are treated as outline headings."
142+ :safe #'symbolp
143+ :type '(choice (const :tag " Use special comments" comments)
144+ (const :tag " Use imenu" imenu))
145+ :package-version '(clojure-ts-mode . " 0.4" ))
146+
136147(defcustom clojure-ts-align-reader-conditionals nil
137148 " Whether to align reader conditionals, as if they were maps."
138149 :package-version '(clojure-ts-mode . " 0.4" )
@@ -913,6 +924,20 @@ Includes a dispatch value when applicable (defmethods)."
913924By default `treesit-defun-name-function' is used to extract definition names.
914925See `clojure-ts--standard-definition-node-name' for the implementation used." )
915926
927+ ; ;; Outline settings
928+
929+ (defun clojure-ts--outline-predicate (node )
930+ " Return TRUE if NODE is an outline heading comment."
931+ (and (string= (treesit-node-type node) " comment" )
932+ (string-match-p " ^\\ (?:;;;;* \\ ).*" (treesit-node-text node))))
933+
934+ (defun clojure-ts--outline-level ()
935+ " Return the current level of the outline heading at point."
936+ (let* ((node (treesit-outline--at-point))
937+ (node-text (treesit-node-text node)))
938+ (string-match " ;;\\ (;+\\ ) " node-text)
939+ (- (match-end 1 ) (match-beginning 1 ))))
940+
916941(defcustom clojure-ts-indent-style 'semantic
917942 " Automatic indentation style to use when mode `clojure-ts-mode' is run.
918943
@@ -1708,6 +1733,13 @@ REGEX-AVAILABLE."
17081733 (setq-local indent-tabs-mode nil )
17091734 (setq-local comment-add 1 )
17101735 (setq-local comment-start " ;" )
1736+ (when (equal clojure-ts-outline-variant 'comments )
1737+ ; ; NOTE: If `imenu' option is selected for `clojure-ts-outline-variant' , all
1738+ ; ; necessary variables will be set automatically by
1739+ ; ; `treesit-major-mode-setup' .
1740+ (setq-local treesit-outline-predicate #'clojure-ts--outline-predicate
1741+ outline-search-function #'treesit-outline-search
1742+ outline-level #'clojure-ts--outline-level ))
17111743
17121744 (setq-local treesit-font-lock-settings
17131745 (clojure-ts--font-lock-settings markdown-available regex-available))
0 commit comments