used to communicate the tree-sitter parsing results to
'show-paren-mode'.
+*** New treesit thing 'comment'.
+The new variable 'forward-comment-function' is set to the new function
+'treesit-forward-comment' if a major mode defines the thing 'comment'.
+
+++
*** New function 'treesit-language-display-name'.
This new function returns the display name of a language given the
(if (> arg 0) #'treesit-end-of-thing #'treesit-beginning-of-thing)
'sentence (abs arg))))
+(defun treesit-forward-comment (&optional count)
+ "Tree-sitter `forward-comment-function' implementation.
+
+COUNT is the same as in `forward-comment'."
+ (let ((res t) thing)
+ (while (> count 0)
+ (skip-chars-forward " \t\n")
+ (setq thing (treesit-thing-at (point) 'comment))
+ (if (and thing (eq (point) (treesit-node-start thing)))
+ (progn
+ (goto-char (min (1+ (treesit-node-end thing)) (point-max)))
+ (setq count (1- count)))
+ (setq count 0 res nil)))
+ (while (< count 0)
+ (skip-chars-backward " \t\n")
+ (setq thing (treesit-thing-at (max (1- (point)) (point-min)) 'comment))
+ (if (and thing (eq (point) (treesit-node-end thing)))
+ (progn
+ (goto-char (treesit-node-start thing))
+ (setq count (1+ count)))
+ (setq count 0 res nil)))
+ res))
+
(defun treesit-default-defun-skipper ()
"Skips spaces after navigating a defun.
This function tries to move to the beginning of a line, either by
(setq-local forward-list-function #'treesit-forward-list)
(setq-local down-list-function #'treesit-down-list)
(setq-local up-list-function #'treesit-up-list)
- (setq-local show-paren-data-function 'treesit-show-paren-data))
+ (setq-local show-paren-data-function #'treesit-show-paren-data))
(when (treesit-thing-defined-p 'sentence nil)
(setq-local forward-sentence-function #'treesit-forward-sentence))
+ (when (treesit-thing-defined-p 'comment nil)
+ (setq-local forward-comment-function #'treesit-forward-comment))
+
;; Imenu.
(when (or treesit-aggregated-simple-imenu-settings
treesit-simple-imenu-settings)
int dummy2;
unsigned short int quit_count = 0;
+ if (!NILP (Vforward_comment_function))
+ return calln (Vforward_comment_function, count);
+
CHECK_FIXNUM (count);
count1 = XFIXNUM (count);
stop = count1 > 0 ? ZV : BEGV;
DEFSYM (Qcomment_end_can_be_escaped, "comment-end-can-be-escaped");
Fmake_variable_buffer_local (Qcomment_end_can_be_escaped);
+ DEFVAR_LISP ("forward-comment-function", Vforward_comment_function,
+ doc: /* If non-nil, `forward-comment' delegates to this function.
+Should take the same arguments and behave similarly to `forward-comment'. */);
+ Vforward_comment_function = Qnil;
+
defsubr (&Ssyntax_table_p);
defsubr (&Ssyntax_table);
defsubr (&Sstandard_syntax_table);