From: Theodor Thornhill Date: Sun, 22 Jan 2023 10:14:00 +0000 (+0100) Subject: Tweak BSD style indentation (bug#60984) X-Git-Tag: emacs-29.0.90~626 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=808e101fabec64a2f7a42dd9d9207ebd402ead4f;p=emacs.git Tweak BSD style indentation (bug#60984) * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Simplify rules. * test/lisp/progmodes/c-ts-mode-resources/indent-bsd.erts: New testfile with bsd style indentation examples. * test/lisp/progmodes/c-ts-mode-tests.el (c-ts-mode-test-indentation-bsd): Add a test for the new style. --- diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 27737a2ee1d..95f9001e0d7 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -237,6 +237,10 @@ MODE is either `c' or `cpp'." ((node-is "labeled_statement") point-min 0) ,@common) (bsd + ((node-is "}") parent-bol 0) + ((node-is "labeled_statement") parent-bol c-ts-mode-indent-offset) + ((parent-is "labeled_statement") parent-bol c-ts-mode-indent-offset) + ((parent-is "compound_statement") parent-bol c-ts-mode-indent-offset) ((parent-is "if_statement") parent-bol 0) ((parent-is "for_statement") parent-bol 0) ((parent-is "while_statement") parent-bol 0) diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent-bsd.erts b/test/lisp/progmodes/c-ts-mode-resources/indent-bsd.erts new file mode 100644 index 00000000000..07698077ffc --- /dev/null +++ b/test/lisp/progmodes/c-ts-mode-resources/indent-bsd.erts @@ -0,0 +1,93 @@ +Code: + (lambda () + (setq indent-tabs-mode nil) + (setq c-ts-mode-indent-offset 2) + (setq c-ts-mode-indent-style 'bsd) + (c-ts-mode) + (indent-region (point-min) (point-max))) + +Point-Char: | + +Name: Basic + +=-= +int +main (void) +{ + return 0; +} +=-=-= + +Name: Hanging Braces + +=-= +int +main (void) +{ + if (true) + { + | + } +} +=-=-= + +Name: Labels + +=-= +int +main (void) +{ + label: + return 0; + if (true) + { + label: + return 0; + } + else + { + if (true) + { + label: + return 0; + } + } +} +=-=-= + +Name: If-Else + +=-= +int main() +{ + if (true) + { + return 0; + } + else + { + return 1; + } +} +=-=-= + +Name: Empty Line +=-= +int main() +{ + | +} +=-=-= + +Name: Consecutive blocks (bug#60873) + +=-= +int +main (int argc, + char *argv[]) +{ + { + int i = 0; + } +} +=-=-= diff --git a/test/lisp/progmodes/c-ts-mode-tests.el b/test/lisp/progmodes/c-ts-mode-tests.el index 3d0902fe501..ddf64b40736 100644 --- a/test/lisp/progmodes/c-ts-mode-tests.el +++ b/test/lisp/progmodes/c-ts-mode-tests.el @@ -27,6 +27,10 @@ (skip-unless (treesit-ready-p 'c)) (ert-test-erts-file (ert-resource-file "indent.erts"))) +(ert-deftest c-ts-mode-test-indentation-bsd () + (skip-unless (treesit-ready-p 'c)) + (ert-test-erts-file (ert-resource-file "indent-bsd.erts"))) + (ert-deftest c-ts-mode-test-filling () (skip-unless (treesit-ready-p 'c)) (ert-test-erts-file (ert-resource-file "filling.erts")))