Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a keymap in the close overlay #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)))
(define-key map (kbd "TAB") 'ts-fold-open)
map))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use defvar-local here? And get rid of the make-local-variable part.


(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