From f55bbc6898898c4b5457e6952b0ae9b5c8c42423 Mon Sep 17 00:00:00 2001 From: Theodor Thornhill Date: Sat, 21 Jan 2023 13:35:10 +0100 Subject: [PATCH] Add sentence and sexp movement to c-ts-mode * lisp/progmodes/c-ts-mode.el (c-ts-base-mode): Add 'treesit-sentence-type-regexp' and 'treesit-sexp-type-regexp' node types. --- lisp/progmodes/c-ts-mode.el | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 348d027af19..14bbb099a0a 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -896,6 +896,37 @@ Set up: (setq-local treesit-defun-skipper #'c-ts-mode--defun-skipper) (setq-local treesit-defun-name-function #'c-ts-mode--defun-name) + (setq-local treesit-sentence-type-regexp + ;; compound_statement makes us jump over too big units + ;; of code, so skip that one, and include the other + ;; statements. + (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"))) + + (setq-local treesit-sexp-type-regexp + (regexp-opt '("preproc" + "declarator" + "qualifier" + "type" + "parameter" + "expression" + "literal" + "string"))) + ;; Nodes like struct/enum/union_specifier can appear in ;; function_definitions, so we need to find the top-level node. (setq-local treesit-defun-prefer-top-level t) -- 2.39.5