Skip to content

Commit f61018e

Browse files
committed
ref
1 parent 8dbd9bf commit f61018e

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

foldvis-origami.el

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,19 @@ Arguments WEND and WSTART are the range for caching."
7777
;;;###autoload
7878
(defun foldvis-origami--refresh (&rest _)
7979
"Refresh indicators for all folding range."
80-
(origami-util-with-current-buffer buffer
81-
(when-let*
82-
((tree (ignore-errors (origami-get-fold-tree buffer)))
83-
(nodes-to-fold (elt tree 4))
84-
(wend (window-end nil t))
85-
(wstart (window-start))
86-
(nodes-to-fold
87-
(cl-remove-if-not (lambda (node)
88-
(foldvis-origami--within-window node wend wstart))
89-
nodes-to-fold)))
90-
(foldvis--remove-ovs)
91-
(thread-last nodes-to-fold
92-
(mapc #'foldvis-origami--create))
93-
(run-hooks 'foldvis-refresh-hook))))
80+
(when-let*
81+
((tree (ignore-errors (origami-get-fold-tree (current-buffer))))
82+
(nodes-to-fold (elt tree 4))
83+
(wend (window-end nil t))
84+
(wstart (window-start))
85+
(nodes-to-fold
86+
(cl-remove-if-not (lambda (node)
87+
(foldvis-origami--within-window node wend wstart))
88+
nodes-to-fold)))
89+
(foldvis--remove-ovs)
90+
(thread-last nodes-to-fold
91+
(mapc #'foldvis-origami--create))
92+
(run-hooks 'foldvis-refresh-hook)))
9493

9594
(provide 'foldvis-origami)
9695
;;; foldvis-origami.el ends here

foldvis-treesit-fold.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
;;;###autoload
3636
(defun foldvis-treesit-fold--enable ()
3737
"Enable the folding minor mode."
38-
(advice-add 'treesit-fold--after-command :after #'foldvis-treesit-fold--refresh))
38+
(advice-add 'treesit-fold--after-command :after #'foldvis-refresh))
3939

4040
;;;###autoload
4141
(defun foldvis-treesit-fold--disable ()
4242
"Disable the folding minor mode."
43-
(advice-remove 'treesit-fold--after-command #'foldvis-treesit-fold--refresh))
43+
(advice-remove 'treesit-fold--after-command #'foldvis-refresh))
4444

4545
;;;###autoload
4646
(defun foldvis-treesit-fold--valid ()

foldvis-ts-fold.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
(defun foldvis-ts-fold--enable ()
3737
"Enable the folding minor mode."
3838
(add-hook 'tree-sitter-after-change-functions #'foldvis--trigger-render nil t)
39-
(advice-add 'ts-fold--after-command :after #'foldvis-ts-fold--refresh))
39+
(advice-add 'ts-fold--after-command :after #'foldvis-refresh))
4040

4141
;;;###autoload
4242
(defun foldvis-ts-fold--disable ()
4343
"Disable the folding minor mode."
4444
(remove-hook 'tree-sitter-after-change-functions #'foldvis--trigger-render t)
45-
(advice-remove 'ts-fold--after-command #'foldvis-ts-fold--refresh))
45+
(advice-remove 'ts-fold--after-command #'foldvis-refresh))
4646

4747
;;;###autoload
4848
(defun foldvis-ts-fold--valid ()

foldvis.el

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,27 +167,31 @@ See macro `with-selected-window' description for arguments WINDOW and BODY."
167167

168168
(defun foldvis--choose-backend ()
169169
"Set the current possible backend."
170-
(let ((backend (cl-some (lambda (x)
171-
(when (foldvis--call-backend "-valid" x)
172-
x))
173-
foldvis-backends)))
174-
(when (and foldvis--backend
175-
(not (equal foldvis--backend backend))) ; has changed?
176-
;; TODO: ..
177-
)
178-
(setq foldvis--backend backend)))
170+
(let* ((backend (cl-some (lambda (x)
171+
(when (foldvis--call-backend "-valid" x)
172+
x))
173+
foldvis-backends))
174+
(changed (and foldvis--backend backend
175+
(not (equal foldvis--backend backend)))))
176+
(setq foldvis--backend backend)
177+
;; If backend has changed, re-render once.
178+
(when changed
179+
(foldvis--render-buffer))
180+
;; If backend has become nil, remove it.
181+
(unless backend
182+
(foldvis--remove-ovs-buffer))))
179183

180184
(defun foldvis--enable ()
181185
"Start folding minor mode."
182186
(foldvis--call-backend "-enable")
183187
(add-hook 'after-save-hook #'foldvis--trigger-render nil t)
184188
(add-hook 'post-command-hook #'foldvis--post-command nil t)
185189
(add-hook 'window-size-change-functions #'foldvis--size-change)
186-
(add-hook 'window-scroll-functions #'foldvis--scroll)
187-
(foldvis--render-buffer))
190+
(add-hook 'window-scroll-functions #'foldvis--scroll))
188191

189192
(defun foldvis--disable ()
190193
"Stop folding minor mode."
194+
(setq foldvis--backend nil)
191195
(foldvis--call-backend "-disable")
192196
(remove-hook 'after-save-hook #'foldvis--trigger-render t)
193197
(remove-hook 'post-command-hook #'foldvis--post-command t)
@@ -201,11 +205,7 @@ See macro `with-selected-window' description for arguments WINDOW and BODY."
201205
:group 'foldvis
202206
:init-value nil
203207
:lighter " FoldVis"
204-
(foldvis--choose-backend)
205-
(cond (foldvis--backend
206-
(if foldvis-mode (foldvis--enable) (foldvis--disable)))
207-
(t (message "No folding backend found: %s" foldvis--backend)
208-
(foldvis-mode -1))))
208+
(if foldvis-mode (foldvis--enable) (foldvis--disable)))
209209

210210
(defun foldvis--turn-on-foldvis-mode ()
211211
"Turn on the `foldvis-mode'."
@@ -380,6 +380,7 @@ Argument FOLDED holds folding state; it's a boolean."
380380

381381
(defun foldvis--post-command ()
382382
"Post command."
383+
(foldvis--choose-backend)
383384
(when foldvis--render-this-command-p
384385
(foldvis-refresh)
385386
(setq foldvis--render-this-command-p nil)))

0 commit comments

Comments
 (0)