about summary refs log tree commit diff
path: root/tools/emacs-pkgs/treecrumbs/treecrumbs.el
diff options
context:
space:
mode:
Diffstat (limited to 'tools/emacs-pkgs/treecrumbs/treecrumbs.el')
-rw-r--r--tools/emacs-pkgs/treecrumbs/treecrumbs.el42
1 files changed, 34 insertions, 8 deletions
diff --git a/tools/emacs-pkgs/treecrumbs/treecrumbs.el b/tools/emacs-pkgs/treecrumbs/treecrumbs.el
index 81538de770f2..a01e5490fa7f 100644
--- a/tools/emacs-pkgs/treecrumbs/treecrumbs.el
+++ b/tools/emacs-pkgs/treecrumbs/treecrumbs.el
@@ -90,6 +90,32 @@ The defined languages are stored in `treecrumbs-languages'."
   ("flow_pair" . ((_) key: (_) @key))
   ("flow_sequence" . "[]"))
 
+(define-treecrumbs-language cpp
+  ;; In C++ files, crumbs are generated from namespaces and
+  ;; identifier declarations.
+  ("namespace_definition" . ([(namespace_definition
+                               name: (namespace_identifier) @key)
+                              (namespace_definition
+                               "namespace" @key
+                               !name)]))
+
+  ("function_definition" . ((function_definition
+                             declarator:
+                             (function_declarator
+                              declarator: (_) @key))))
+
+  ("class_specifier" . ((class_specifier
+                         name: (type_identifier) @key)))
+
+  ("struct_specifier" . ((struct_specifier
+                          name: (type_identifier) @key)))
+
+  ("field_declaration" . ((field_declaration
+                           declarator: (_) @key)))
+
+  ("init_declarator" . ((init_declarator
+                         declarator: (_) @key))))
+
 (defvar-local treecrumbs--current-crumbs nil
   "Current crumbs to display in the header line. Only updated when
 the node under point changes.")
@@ -110,14 +136,14 @@ is undefined, it directly updates the buffer-local
        (when-let ((query (cdr (assoc (treesit-node-type parent) lang))))
 
          (setq-local treecrumbs--current-crumbs
-               (concat treecrumbs--current-crumbs
-                       (if (string-empty-p treecrumbs--current-crumbs) ""
-                         " < ")
-
-                       (if (stringp query)
-                           query
-                         (substring-no-properties
-                          (treesit-node-text (cdar (treesit-query-capture parent query))))))))
+                     (concat treecrumbs--current-crumbs
+                             (if (string-empty-p treecrumbs--current-crumbs) ""
+                               " < ")
+
+                             (if (stringp query)
+                                 query
+                               (substring-no-properties
+                                (treesit-node-text (cdar (treesit-query-capture parent query))))))))
        t))))