Skip to content

Commit 4740d6e

Browse files
committed
feat: Percise api
1 parent def622c commit 4740d6e

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

vs-edit-mode.el

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
;;; Code:
3333

3434
(eval-when-compile
35+
(require 'hideshow)
3536
(require 'sgml-mode)
3637

3738
(require 'mwim)
@@ -83,6 +84,11 @@
8384

8485
(declare-function sgml-skip-tag-forward "ext:sgml-mode.el")
8586

87+
(declare-function hs-hide-block "ext:hideshow.el")
88+
(declare-function hs-show-block "ext:hideshow.el")
89+
(declare-function hs-hide-all "ext:hideshow.el")
90+
(declare-function hs-show-all "ext:hideshow.el")
91+
8692
;;
8793
;; (@* "Entry" )
8894
;;
@@ -442,14 +448,14 @@
442448
(t ; Do nothing if no fold range found!
443449
))))
444450

445-
(defun vs-edit--close-node () ; internal
451+
(defun vs-edit--fold-close-node () ; internal
446452
"Close node at the end of line, inspired from Visual Studio."
447453
(save-excursion
448454
(vs-edit--to-smallest-range)
449455
(when (vs-edit--comment-p) (back-to-indentation))
450456
(ts-fold-close)))
451457

452-
(defun vs-edit--open-node () ; internal
458+
(defun vs-edit--fold-open-node () ; internal
453459
"Open node at the end of line, inspired from Visual Studio."
454460
(save-excursion
455461
(vs-edit--to-smallest-range)
@@ -465,19 +471,41 @@
465471
result)))
466472

467473
;;;###autoload
468-
(defun vs-edit-close-node ()
474+
(defun vs-edit-fold-close ()
469475
"Close the current scope of the node."
470476
(interactive)
471-
(when-let* ((ov (or (vs-edit--close-node) (ts-fold-close)))
477+
(when-let* ((ov (or (ignore-errors (vs-edit--fold-close-node))
478+
(ignore-errors (ts-fold-close))
479+
(progn (require 'hideshow)
480+
(hs-hide-block))))
472481
(beg (overlay-start ov))
473482
((< beg (point))))
474483
(goto-char beg)))
475484

476485
;;;###autoload
477-
(defun vs-edit-open-node ()
486+
(defun vs-edit-fold-open ()
478487
"Open the current scope of the node."
479488
(interactive)
480-
(or (vs-edit--open-node) (ts-fold-open)))
489+
(or (ignore-errors (vs-edit--fold-open-node))
490+
(ignore-errors (ts-fold-open))
491+
(progn (require 'hideshow)
492+
(hs-show-block))))
493+
494+
;;;###autoload
495+
(defun vs-edit-fold-close-all ()
496+
"Close all nodes in buffer."
497+
(interactive)
498+
(or (ignore-errors (ts-fold-close-all))
499+
(progn (require 'hideshow)
500+
(hs-hide-all))))
501+
502+
;;;###autoload
503+
(defun vs-edit-fold-open-all ()
504+
"Open all nodes in buffer."
505+
(interactive)
506+
(or (ignore-errors (ts-fold-open-all))
507+
(progn (require 'hideshow)
508+
(hs-show-all))))
481509

482510
(provide 'vs-edit-mode)
483511
;;; vs-edit-mode.el ends here

0 commit comments

Comments
 (0)