From: Yuan Fu Date: Sat, 7 Jan 2023 23:45:05 +0000 (-0800) Subject: Support namespaces in c++-ts-mode (bug#60397) X-Git-Tag: emacs-29.0.90~806 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=7c356934fbb07d6b0f267f8d21ffc9b3f7d9d1c3;p=emacs.git Support namespaces in c++-ts-mode (bug#60397) 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. --- diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index a6ab454012d..43d714dbb20 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -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)