diff options
| author | Elías Gabriel Pérez | 2025-12-04 17:30:58 -0600 |
|---|---|---|
| committer | Juri Linkov | 2025-12-08 09:20:40 +0200 |
| commit | 8773933816f90680505004213a1594506450af6b (patch) | |
| tree | 9f87b0a434437e793845a0c6a878a52aa9b948f5 | |
| parent | a582f2bb577bd8e696d51e4d3a728426b33f59cc (diff) | |
| download | emacs-8773933816f90680505004213a1594506450af6b.tar.gz emacs-8773933816f90680505004213a1594506450af6b.zip | |
Fix 'treesit-hs-block-end' and 'treesit-hs-inside-comment-p' (Bug#79934)
* lisp/treesit.el (treesit-hs-block-end): Properly get the block
end.
(treesit-hs-inside-comment-p): Add support for single-line
comments.
| -rw-r--r-- | lisp/treesit.el | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el index 6809f1ec086..752ab73a473 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el | |||
| @@ -4255,8 +4255,7 @@ For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in | |||
| 4255 | (if (bobp) (point) (1- (point))) pred)) | 4255 | (if (bobp) (point) (1- (point))) pred)) |
| 4256 | (end (when thing (treesit-node-end thing))) | 4256 | (end (when thing (treesit-node-end thing))) |
| 4257 | (last (when thing (treesit-node-child thing -1))) | 4257 | (last (when thing (treesit-node-child thing -1))) |
| 4258 | (beg (if last (treesit-node-start last) | 4258 | (beg (treesit-node-start (or last thing)))) |
| 4259 | (if (bobp) (point) (1- (point)))))) | ||
| 4260 | (when (and thing (eq (point) end)) | 4259 | (when (and thing (eq (point) end)) |
| 4261 | (set-match-data (list beg end)) | 4260 | (set-match-data (list beg end)) |
| 4262 | t))) | 4261 | t))) |
| @@ -4313,14 +4312,29 @@ For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in | |||
| 4313 | 4312 | ||
| 4314 | (defun treesit-hs-inside-comment-p () | 4313 | (defun treesit-hs-inside-comment-p () |
| 4315 | "Tree-sitter implementation of `hs-inside-comment-predicate'." | 4314 | "Tree-sitter implementation of `hs-inside-comment-predicate'." |
| 4316 | (let* ((comment-pred | 4315 | (when-let* ((comment-pred |
| 4317 | (if (treesit-thing-defined-p 'comment (treesit-language-at (point))) | 4316 | (if (treesit-thing-defined-p 'comment (treesit-language-at (point))) |
| 4318 | 'comment "\\`comment\\'")) | 4317 | 'comment "\\`comment\\'")) |
| 4319 | (thing (or (treesit-thing-at (point) comment-pred) | 4318 | (thing (or (treesit-thing-at (point) comment-pred) |
| 4320 | (unless (bobp) | 4319 | (unless (bobp) |
| 4321 | (treesit-thing-at (1- (point)) comment-pred))))) | 4320 | (treesit-thing-at (1- (point)) comment-pred)))) |
| 4322 | (when thing | 4321 | (beg (treesit-node-start thing)) |
| 4323 | (list (treesit-node-start thing) (treesit-node-end thing))))) | 4322 | (end (treesit-node-end thing))) |
| 4323 | (unless (and (fboundp 'hs-hideable-region-p) (hs-hideable-region-p beg end)) | ||
| 4324 | (save-excursion | ||
| 4325 | (goto-char beg) | ||
| 4326 | (while (and (skip-chars-forward "[:blank:]") | ||
| 4327 | (when-let* ((c (treesit-thing-at (point) comment-pred))) | ||
| 4328 | (setq beg (treesit-node-start c))) | ||
| 4329 | (not (bobp)) | ||
| 4330 | (forward-line -1))) | ||
| 4331 | (goto-char beg) | ||
| 4332 | (while (and (skip-chars-forward "[:blank:]") | ||
| 4333 | (when-let* ((c (treesit-thing-at (point) comment-pred))) | ||
| 4334 | (setq end (treesit-node-end c))) | ||
| 4335 | (not (eobp)) | ||
| 4336 | (forward-line 1))))) | ||
| 4337 | (list beg end))) | ||
| 4324 | 4338 | ||
| 4325 | ;;; Show paren mode | 4339 | ;;; Show paren mode |
| 4326 | 4340 | ||