From ba9fc0542351506e2271a5edd47f00feb2163245 Mon Sep 17 00:00:00 2001 From: Theodor Thornhill Date: Fri, 17 Feb 2023 20:46:19 +0100 Subject: [PATCH] Cleanup preproc indent for c-ts-mode * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Make sure we indent to grand-parent if inside an #ifdef...#endif block. If grandparent is root node, then don't indent one step. --- lisp/progmodes/c-ts-mode.el | 11 ++++++----- lisp/treesit.el | 5 +++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 05875e9267..9c28fc4ad4 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -265,13 +265,14 @@ c-ts-mode--indent-styles ((match nil "do_statement" "body") parent-bol c-ts-mode-indent-offset) ((match nil "for_statement" "body") parent-bol c-ts-mode-indent-offset) - ((match "preproc_ifdef" "compound_statement") point-min 0) - ((match "#endif" "preproc_ifdef") point-min 0) - ((match "preproc_if" "compound_statement") point-min 0) - ((match "#endif" "preproc_if") point-min 0) - ((match "preproc_function_def" "compound_statement") point-min 0) + ((node-is "preproc") point-min 0) + ((node-is "#endif") point-min 0) ((match "preproc_call" "compound_statement") point-min 0) + ((n-p-gp nil "preproc" "translation_unit") point-min 0) + ((n-p-gp nil "\n" "preproc") great-grand-parent c-ts-mode-indent-offset) + ((parent-is "preproc") grand-parent c-ts-mode-indent-offset) + ((parent-is "function_definition") parent-bol 0) ((parent-is "conditional_expression") first-sibling 0) ((parent-is "assignment_expression") parent-bol c-ts-mode-indent-offset) diff --git a/lisp/treesit.el b/lisp/treesit.el index 09531b838a..be864d8f1f 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -1204,6 +1204,11 @@ treesit-simple-indent-presets (cons 'grand-parent (lambda (_n parent &rest _) (treesit-node-start (treesit-node-parent parent)))) + (cons 'great-grand-parent + (lambda (_n parent &rest _) + (treesit-node-start + (treesit-node-parent + (treesit-node-parent parent))))) (cons 'parent-bol (lambda (_n parent &rest _) (save-excursion (goto-char (treesit-node-start parent)) -- 2.34.1