(outline--insert-button (if close-p 'close 'open))))
(or from (point-min)) (or to (point-max)))))
-(defun outline--fix-buttons-after-change (beg end _len)
+(defvar outline-after-change-functions nil
+ "List of functions to call after each text change in outline-mode.")
+
+(defun outline--fix-buttons-after-change (beg end len)
+ (run-hook-with-args 'outline-after-change-functions beg end len)
;; Handle whole lines
(save-excursion (goto-char beg) (setq beg (pos-bol)))
(save-excursion (goto-char end) (setq end (pos-eol)))
("Struct" "\\`struct_item\\'" nil nil)
("Fn" "\\`function_item\\'" nil nil)))
+ ;; Outline.
+ (setq-local treesit-outline-predicate
+ (rx bos (or "mod_item"
+ "enum_item"
+ "impl_item"
+ "type_item"
+ "struct_item"
+ "function_item"
+ "trait_item")
+ eos))
;; Indent.
(setq-local indent-tabs-mode nil
treesit-simple-indent-rules rust-ts-mode--indent-rules)
level))
(defun treesit--after-change (beg end _len)
- "Force updating the ranges after each text change."
+ "Force updating the ranges in BEG...END.
+Expected to be called after each text change."
(treesit-update-ranges beg end))
;;; Hideshow mode
#'treesit-outline-predicate--from-imenu))
(setq-local outline-search-function #'treesit-outline-search
outline-level #'treesit-outline-level)
- (add-hook 'outline-minor-mode-hook
- (lambda ()
- (if (bound-and-true-p outline-minor-mode)
- (add-hook 'after-change-functions
- #'treesit--after-change
- 0 t)
- (remove-hook 'after-change-functions
- #'treesit--after-change t)))
- nil t))
+ (add-hook 'outline-after-change-functions #'treesit--after-change nil t))
;; Remove existing local parsers.
(dolist (ov (overlays-in (point-min) (point-max)))