]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix treesit-thing-settings for c++-ts-mode (bug#65810)
authorYuan Fu <casouri@gmail.com>
Thu, 7 Sep 2023 23:08:42 +0000 (16:08 -0700)
committerYuan Fu <casouri@gmail.com>
Thu, 7 Sep 2023 23:08:42 +0000 (16:08 -0700)
* lisp/progmodes/c-ts-mode.el:
(c-ts-mode--thing-settings): New varaible.
(c-ts-base-mode): Use c-ts-mode--thing-settings.

lisp/progmodes/c-ts-mode.el

index 5f685e016d2af8de8688b765477480b6228ddf92..5b698eb09f4b26fced252ed6a7b9d9aa972106d5 100644 (file)
@@ -1014,6 +1014,36 @@ if `c-ts-mode-emacs-sources-support' is non-nil."
   (or (treesit-add-log-current-defun)
       (c-ts-mode--defun-name (c-ts-mode--emacs-defun-at-point))))
 
+;;; Things
+
+(defvar c-ts-mode--thing-settings
+  `(;; It's more useful to include semicolons as sexp so
+    ;; that users can move to the end of a statement.
+    (sexp (not ,(rx (or "{" "}" "[" "]" "(" ")" ","))))
+    ;; compound_statement makes us jump over too big units
+    ;; of code, so skip that one, and include the other
+    ;; statements.
+    (sentence
+     ,(regexp-opt '("preproc"
+                    "declaration"
+                    "specifier"
+                    "attributed_statement"
+                    "labeled_statement"
+                    "expression_statement"
+                    "if_statement"
+                    "switch_statement"
+                    "do_statement"
+                    "while_statement"
+                    "for_statement"
+                    "return_statement"
+                    "break_statement"
+                    "continue_statement"
+                    "goto_statement"
+                    "case_statement")))
+    (text ,(regexp-opt '("comment"
+                         "raw_string_literal"))))
+  "`treesit-thing-settings' for both C and C++.")
+
 ;;; Support for FOR_EACH_* macros
 ;;
 ;; FOR_EACH_TAIL, FOR_EACH_TAIL_SAFE, FOR_EACH_FRAME etc., followed by
@@ -1133,32 +1163,8 @@ BEG and END are described in `treesit-range-rules'."
   ;; spirit, especially when used for movement, is like "expression"
   ;; or "syntax unit". --yuan
   (setq-local treesit-thing-settings
-              `((c
-                 ;; It's more useful to include semicolons as sexp so
-                 ;; that users can move to the end of a statement.
-                 (sexp (not ,(rx (or "{" "}" "[" "]" "(" ")" ","))))
-                 ;; compound_statement makes us jump over too big units
-                 ;; of code, so skip that one, and include the other
-                 ;; statements.
-                 (sentence
-                  ,(regexp-opt '("preproc"
-                                 "declaration"
-                                 "specifier"
-                                 "attributed_statement"
-                                 "labeled_statement"
-                                 "expression_statement"
-                                 "if_statement"
-                                 "switch_statement"
-                                 "do_statement"
-                                 "while_statement"
-                                 "for_statement"
-                                 "return_statement"
-                                 "break_statement"
-                                 "continue_statement"
-                                 "goto_statement"
-                                 "case_statement")))
-                 (text ,(regexp-opt '("comment"
-                                      "raw_string_literal"))))))
+              `((c ,@c-ts-mode--thing-settings)
+                (cpp ,@c-ts-mode--thing-settings)))
 
   ;; Nodes like struct/enum/union_specifier can appear in
   ;; function_definitions, so we need to find the top-level node.