From: Yuan Fu Date: Sat, 14 Jan 2023 07:05:45 +0000 (-0800) Subject: ; Fix c-ts-mode filling X-Git-Tag: emacs-29.0.90~720^2~7 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f02998939c6;p=emacs.git ; Fix c-ts-mode filling * lisp/progmodes/c-ts-mode.el: (c-ts-mode--comment-regexp): New variable. (c-ts-mode--fill-paragraph): Use the new variable, and make sure start-marker is always initialized. --- diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index ef5a9c2195a..c1f354c7bad 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -671,6 +671,11 @@ the semicolon. This function skips the semicolon." ;;; Filling +(defvar c-ts-mode--comment-regexp + ;; These covers C/C++, Java, JavaScript, TypeScript, Rust, C#. + (rx (or "comment" "line_comment" "block_comment")) + "Regexp pattern that matches a comment in C-like languages.") + (defun c-ts-mode--fill-paragraph (&optional arg) "Fillling function for `c-ts-mode'. ARG is passed to `fill-paragraph'." @@ -683,12 +688,12 @@ ARG is passed to `fill-paragraph'." ;; Bind to nil to avoid infinite recursion. (fill-paragraph-function nil) (orig-point (point-marker)) - (start-marker nil) + (start-marker (point-marker)) (end-marker nil) (end-len 0)) - ;; These covers C/C++, Java, JavaScript, TypeScript, Rust, C#. - (when (member (treesit-node-type node) - '("comment" "line_comment" "block_comment")) + (move-marker start-marker start) + (when (string-match-p c-ts-mode--comment-regexp + (treesit-node-type node)) ;; We mask "/*" and the space before "*/" like ;; `c-fill-paragraph' does. (atomic-change-group @@ -697,7 +702,7 @@ ARG is passed to `fill-paragraph'." (when (looking-at (rx (* (syntax whitespace)) (group "/") "*")) (goto-char (match-beginning 1)) - (setq start-marker (point-marker)) + (move-marker start-marker (point)) (replace-match " " nil nil nil 1)) ;; Include whitespaces before /*. (goto-char start)