diff options
| author | Jacob Leeming | 2024-04-22 09:49:15 +0100 |
|---|---|---|
| committer | Eli Zaretskii | 2024-04-25 18:53:06 +0300 |
| commit | 494dfd9cf2becdb33eefb1c0e6d8bc383cb8a2f0 (patch) | |
| tree | 0578fdebcf153c7c72b121ddaf44fedbba8698d0 | |
| parent | 1cc6322e61275ad8b5056eb7dd43af6fe459aa0b (diff) | |
| download | emacs-494dfd9cf2becdb33eefb1c0e6d8bc383cb8a2f0.tar.gz emacs-494dfd9cf2becdb33eefb1c0e6d8bc383cb8a2f0.zip | |
Fix indentation of if/else in 'csharp-ts-mode' (bug#70345)
* lisp/progmodes/csharp-mode.el (csharp-ts-mode--indent-rules):
Fix indentation rules for 'if' and 'else'.
* test/lisp/progmodes/csharp-ts-mode-tests.el:
* test/lisp/progmodes/csharp-ts-mode-resources/indent.erts: New
test files.
Copyright-paperwork-exempt: yes
| -rw-r--r-- | lisp/progmodes/csharp-mode.el | 4 | ||||
| -rw-r--r-- | test/lisp/progmodes/csharp-ts-mode-resources/indent.erts | 51 | ||||
| -rw-r--r-- | test/lisp/progmodes/csharp-ts-mode-tests.el | 30 |
3 files changed, 84 insertions, 1 deletions
diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el index 607360f737a..62bbbfe02ff 100644 --- a/lisp/progmodes/csharp-mode.el +++ b/lisp/progmodes/csharp-mode.el | |||
| @@ -689,7 +689,9 @@ compilation and evaluation time conflicts." | |||
| 689 | ((parent-is "binary_expression") parent 0) | 689 | ((parent-is "binary_expression") parent 0) |
| 690 | ((parent-is "block") parent-bol csharp-ts-mode-indent-offset) | 690 | ((parent-is "block") parent-bol csharp-ts-mode-indent-offset) |
| 691 | ((parent-is "local_function_statement") parent-bol 0) | 691 | ((parent-is "local_function_statement") parent-bol 0) |
| 692 | ((parent-is "if_statement") parent-bol 0) | 692 | ((match "block" "if_statement") parent-bol 0) |
| 693 | ((match "else" "if_statement") parent-bol 0) | ||
| 694 | ((parent-is "if_statement") parent-bol csharp-ts-mode-indent-offset) | ||
| 693 | ((parent-is "for_statement") parent-bol 0) | 695 | ((parent-is "for_statement") parent-bol 0) |
| 694 | ((parent-is "for_each_statement") parent-bol 0) | 696 | ((parent-is "for_each_statement") parent-bol 0) |
| 695 | ((parent-is "while_statement") parent-bol 0) | 697 | ((parent-is "while_statement") parent-bol 0) |
diff --git a/test/lisp/progmodes/csharp-ts-mode-resources/indent.erts b/test/lisp/progmodes/csharp-ts-mode-resources/indent.erts new file mode 100644 index 00000000000..3cb23608270 --- /dev/null +++ b/test/lisp/progmodes/csharp-ts-mode-resources/indent.erts | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | Code: | ||
| 2 | (lambda () | ||
| 3 | (csharp-ts-mode) | ||
| 4 | (indent-region (point-min) (point-max))) | ||
| 5 | |||
| 6 | Point-Char: | | ||
| 7 | |||
| 8 | Name: Indent single statement body for if/else. (bug#70345) | ||
| 9 | |||
| 10 | =-= | ||
| 11 | |||
| 12 | int x; | ||
| 13 | int y; | ||
| 14 | |||
| 15 | if (true) | ||
| 16 | x = 2; | ||
| 17 | |||
| 18 | if (true) | ||
| 19 | { | ||
| 20 | x = 2; | ||
| 21 | } | ||
| 22 | |||
| 23 | if (true) | ||
| 24 | x = 2; | ||
| 25 | else | ||
| 26 | y = 2; | ||
| 27 | |||
| 28 | if (true) | ||
| 29 | { | ||
| 30 | x = 2; | ||
| 31 | } | ||
| 32 | else | ||
| 33 | { | ||
| 34 | y = 2; | ||
| 35 | } | ||
| 36 | |||
| 37 | if (true) | ||
| 38 | x = 2; | ||
| 39 | else | ||
| 40 | { | ||
| 41 | y = 2; | ||
| 42 | } | ||
| 43 | |||
| 44 | if (true) | ||
| 45 | { | ||
| 46 | x = 2; | ||
| 47 | } | ||
| 48 | else | ||
| 49 | y = 2; | ||
| 50 | |||
| 51 | =-=-= | ||
diff --git a/test/lisp/progmodes/csharp-ts-mode-tests.el b/test/lisp/progmodes/csharp-ts-mode-tests.el new file mode 100644 index 00000000000..0df0211d86b --- /dev/null +++ b/test/lisp/progmodes/csharp-ts-mode-tests.el | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | ;;; csharp-ts-mode-tests.el --- Tests for Tree-sitter-based C# mode -*- lexical-binding: t; -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2024 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 8 | ;; it under the terms of the GNU General Public License as published by | ||
| 9 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 10 | ;; (at your option) any later version. | ||
| 11 | |||
| 12 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | ;; GNU General Public License for more details. | ||
| 16 | |||
| 17 | ;; You should have received a copy of the GNU General Public License | ||
| 18 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | ;;; Code: | ||
| 21 | |||
| 22 | (require 'ert) | ||
| 23 | (require 'ert-x) | ||
| 24 | (require 'csharp-mode) | ||
| 25 | |||
| 26 | (ert-deftest csharp-ts-mode-test-indentation () | ||
| 27 | (ert-test-erts-file (ert-resource-file "indent.erts"))) | ||
| 28 | |||
| 29 | (provide 'csharp-ts-mode-tests) | ||
| 30 | ;;; csharp-ts-mode-tests.el ends here | ||