diff options
| author | Theodor Thornhill | 2023-01-22 11:14:00 +0100 |
|---|---|---|
| committer | Theodor Thornhill | 2023-01-22 11:14:00 +0100 |
| commit | 808e101fabec64a2f7a42dd9d9207ebd402ead4f (patch) | |
| tree | f86d17daf33d339cb0f778d60f1311d27a421001 | |
| parent | 204519a2e73b5907b2c6f6a670ea6068bc09f6bc (diff) | |
| download | emacs-808e101fabec64a2f7a42dd9d9207ebd402ead4f.tar.gz emacs-808e101fabec64a2f7a42dd9d9207ebd402ead4f.zip | |
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.
| -rw-r--r-- | lisp/progmodes/c-ts-mode.el | 4 | ||||
| -rw-r--r-- | test/lisp/progmodes/c-ts-mode-resources/indent-bsd.erts | 93 | ||||
| -rw-r--r-- | test/lisp/progmodes/c-ts-mode-tests.el | 4 |
3 files changed, 101 insertions, 0 deletions
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'." | |||
| 237 | ((node-is "labeled_statement") point-min 0) | 237 | ((node-is "labeled_statement") point-min 0) |
| 238 | ,@common) | 238 | ,@common) |
| 239 | (bsd | 239 | (bsd |
| 240 | ((node-is "}") parent-bol 0) | ||
| 241 | ((node-is "labeled_statement") parent-bol c-ts-mode-indent-offset) | ||
| 242 | ((parent-is "labeled_statement") parent-bol c-ts-mode-indent-offset) | ||
| 243 | ((parent-is "compound_statement") parent-bol c-ts-mode-indent-offset) | ||
| 240 | ((parent-is "if_statement") parent-bol 0) | 244 | ((parent-is "if_statement") parent-bol 0) |
| 241 | ((parent-is "for_statement") parent-bol 0) | 245 | ((parent-is "for_statement") parent-bol 0) |
| 242 | ((parent-is "while_statement") parent-bol 0) | 246 | ((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 @@ | |||
| 1 | Code: | ||
| 2 | (lambda () | ||
| 3 | (setq indent-tabs-mode nil) | ||
| 4 | (setq c-ts-mode-indent-offset 2) | ||
| 5 | (setq c-ts-mode-indent-style 'bsd) | ||
| 6 | (c-ts-mode) | ||
| 7 | (indent-region (point-min) (point-max))) | ||
| 8 | |||
| 9 | Point-Char: | | ||
| 10 | |||
| 11 | Name: Basic | ||
| 12 | |||
| 13 | =-= | ||
| 14 | int | ||
| 15 | main (void) | ||
| 16 | { | ||
| 17 | return 0; | ||
| 18 | } | ||
| 19 | =-=-= | ||
| 20 | |||
| 21 | Name: Hanging Braces | ||
| 22 | |||
| 23 | =-= | ||
| 24 | int | ||
| 25 | main (void) | ||
| 26 | { | ||
| 27 | if (true) | ||
| 28 | { | ||
| 29 | | | ||
| 30 | } | ||
| 31 | } | ||
| 32 | =-=-= | ||
| 33 | |||
| 34 | Name: Labels | ||
| 35 | |||
| 36 | =-= | ||
| 37 | int | ||
| 38 | main (void) | ||
| 39 | { | ||
| 40 | label: | ||
| 41 | return 0; | ||
| 42 | if (true) | ||
| 43 | { | ||
| 44 | label: | ||
| 45 | return 0; | ||
| 46 | } | ||
| 47 | else | ||
| 48 | { | ||
| 49 | if (true) | ||
| 50 | { | ||
| 51 | label: | ||
| 52 | return 0; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | } | ||
| 56 | =-=-= | ||
| 57 | |||
| 58 | Name: If-Else | ||
| 59 | |||
| 60 | =-= | ||
| 61 | int main() | ||
| 62 | { | ||
| 63 | if (true) | ||
| 64 | { | ||
| 65 | return 0; | ||
| 66 | } | ||
| 67 | else | ||
| 68 | { | ||
| 69 | return 1; | ||
| 70 | } | ||
| 71 | } | ||
| 72 | =-=-= | ||
| 73 | |||
| 74 | Name: Empty Line | ||
| 75 | =-= | ||
| 76 | int main() | ||
| 77 | { | ||
| 78 | | | ||
| 79 | } | ||
| 80 | =-=-= | ||
| 81 | |||
| 82 | Name: Consecutive blocks (bug#60873) | ||
| 83 | |||
| 84 | =-= | ||
| 85 | int | ||
| 86 | main (int argc, | ||
| 87 | char *argv[]) | ||
| 88 | { | ||
| 89 | { | ||
| 90 | int i = 0; | ||
| 91 | } | ||
| 92 | } | ||
| 93 | =-=-= | ||
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 @@ | |||
| 27 | (skip-unless (treesit-ready-p 'c)) | 27 | (skip-unless (treesit-ready-p 'c)) |
| 28 | (ert-test-erts-file (ert-resource-file "indent.erts"))) | 28 | (ert-test-erts-file (ert-resource-file "indent.erts"))) |
| 29 | 29 | ||
| 30 | (ert-deftest c-ts-mode-test-indentation-bsd () | ||
| 31 | (skip-unless (treesit-ready-p 'c)) | ||
| 32 | (ert-test-erts-file (ert-resource-file "indent-bsd.erts"))) | ||
| 33 | |||
| 30 | (ert-deftest c-ts-mode-test-filling () | 34 | (ert-deftest c-ts-mode-test-filling () |
| 31 | (skip-unless (treesit-ready-p 'c)) | 35 | (skip-unless (treesit-ready-p 'c)) |
| 32 | (ert-test-erts-file (ert-resource-file "filling.erts"))) | 36 | (ert-test-erts-file (ert-resource-file "filling.erts"))) |