Skip to content

Commit

Permalink
Add a keymap in the close overlay
Browse files Browse the repository at this point in the history
This map allows to bind a keybind to the closed overlay to open it with
a key when inside it without having to bind a key to `ts-fold-open`
that would need to be global
  • Loading branch information
mattiasdrp committed Aug 26, 2022
1 parent f0804a2 commit 9d8f8d9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ts-fold.el
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,22 @@ the fold in a cons cell. See `ts-fold-range-python' for an example."
(let ((tree-sitter-mode t))
(ts-fold-open-all)))

(defvar ts-fold-close-keymap-default
(let ((map (make-sparse-keymap)))
(keymap-set map "TAB" 'ts-fold-open)
map))

(defvar ts-fold-close-keymap 'ts-fold-close-keymap-default
"Keymap used within ts-fold-close overlay.
It should be set before the overlay is created.")

(make-local-variable 'ts-fold-close-keymap)

;;;###autoload
(define-minor-mode ts-fold-mode
"Folding code using tree sitter."
:init-value nil
:keymap ts-fold-close-keymap
:lighter "TS-Fold"
(if ts-fold-mode (ts-fold--enable) (ts-fold--disable)))

Expand Down Expand Up @@ -218,6 +230,7 @@ This function is borrowed from `tree-sitter-node-at-point'."
(let* ((beg (car range)) (end (cdr range)) (ov (make-overlay beg end)))
(overlay-put ov 'creator 'ts-fold)
(overlay-put ov 'invisible 'ts-fold)
(overlay-put ov 'keymap ts-fold-close-keymap-default)
(overlay-put ov 'display (or (and ts-fold-summary-show
(ts-fold-summary--get (buffer-substring beg end)))
ts-fold-replacement))
Expand Down

0 comments on commit 9d8f8d9

Please sign in to comment.