]> git.eshelyaron.com Git - emacs.git/commitdiff
Support namespaces in c++-ts-mode (bug#60397)
authorYuan Fu <casouri@gmail.com>
Sat, 7 Jan 2023 23:45:05 +0000 (15:45 -0800)
committerYuan Fu <casouri@gmail.com>
Sun, 8 Jan 2023 00:14:12 +0000 (16:14 -0800)
Not a complete fix.  See the next commit.

* lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Add rules.
(c-ts-mode--defun-name): Add namespace_definition.
(c-ts-base-mode): Add namespace_definition to
treesit-defun-type-regexp.

lisp/progmodes/c-ts-mode.el

index a6ab454012d80e1a61f54a11231d9b37f71d6ccf..43d714dbb205f26cd04793a04e2e183bd4b6b938 100644 (file)
@@ -151,7 +151,9 @@ MODE is either `c' or `cpp'."
            ((parent-is "call_expression") parent 0)
            ((parent-is "enumerator_list") parent-bol c-ts-mode-indent-offset)
            ,@(when (eq mode 'cpp)
-               '(((node-is "access_specifier") parent-bol 0)))
+               '(((node-is "access_specifier") parent-bol 0)
+                 ;; Indent the body of namespace definitions.
+                 ((parent-is "declaration_list") parent-bol c-ts-mode-indent-offset)))
            ((parent-is "field_declaration_list") parent-bol c-ts-mode-indent-offset)
            ((parent-is "initializer_list") parent-bol c-ts-mode-indent-offset)
            ((parent-is "if_statement") parent-bol c-ts-mode-indent-offset)
@@ -538,7 +540,8 @@ Return nil if NODE is not a defun node or doesn't have a name."
       (c-ts-mode--declarator-identifier
        (treesit-node-child-by-field-name node "declarator")))
      ((or "struct_specifier" "enum_specifier"
-          "union_specifier" "class_specifier")
+          "union_specifier" "class_specifier"
+          "namespace_definition")
       (treesit-node-child-by-field-name node "name")))
    t))
 
@@ -743,7 +746,8 @@ Set up:
                                   "struct_specifier"
                                   "enum_specifier"
                                   "union_specifier"
-                                  "class_specifier"))
+                                  "class_specifier"
+                                  "namespace_definition"))
                     #'c-ts-mode--defun-valid-p))
   (setq-local treesit-defun-skipper #'c-ts-mode--defun-skipper)
   (setq-local treesit-defun-name-function #'c-ts-mode--defun-name)