[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode e7e0157 447/495: indent: fix indent at top level o
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode e7e0157 447/495: indent: fix indent at top level of file |
Date: |
Sat, 7 Aug 2021 09:06:06 -0400 (EDT) |
branch: elpa/go-mode
commit e7e0157401de9ca89b1847474962ea56780d9b32
Author: Muir Manders <muir@mnd.rs>
Commit: Peter Sanford <psanford@sanford.io>
indent: fix indent at top level of file
We were always adding the (current-indentation) to the computed
indent, but that is not correct for statements at the top
level (i.e. outside any function). It was causing those statements to
maintain their current indent instead of indenting to the beginning of
the line.
I added a new type of indent test so we can differentiate between the
"maintains current indent" and "indent gets corrected" cases.
Closes: #296 [via git-merge-pr]
---
go-mode.el | 9 +++++++--
test/go-indentation-test.el | 25 +++++++++++++++++++++++++
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/go-mode.el b/go-mode.el
index 91f4245..853de70 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -895,8 +895,13 @@ is done."
(not (go--continuation-line-indents-p)))
(cl-decf indent tab-width))
- ;; Apply our computed indent relative to the indent of the ending line.
- (+ indent (current-indentation)))))
+ ;; Apply our computed indent relative to the indent of the
+ ;; ending line, or 0 if we are at the top level.
+ (if (and
+ (= 0 (go-paren-level))
+ (not (go-previous-line-has-dangling-op-p)))
+ indent
+ (+ indent (current-indentation))))))
(defconst go--operator-chars "*/%<>&\\^+\\-|=!,"
"Individual characters that appear in operators.
diff --git a/test/go-indentation-test.el b/test/go-indentation-test.el
index a1be805..03b0f9c 100644
--- a/test/go-indentation-test.el
+++ b/test/go-indentation-test.el
@@ -15,3 +15,28 @@
(let ((contents-before-indent (buffer-string)))
(indent-region (point-min) (point-max) nil)
(should (string= contents-before-indent (buffer-string)))))))
+
+(defun go--should-indent (input expected)
+ "Run `indent-region' against INPUT and make sure it matches EXPECTED."
+ (with-temp-buffer
+ (go-mode)
+ (insert input)
+ (indent-region (point-min) (point-max))
+ (should (string= (buffer-string) expected))))
+
+(ert-deftest go--indent-top-level ()
+ (go--should-indent
+ "
+package foo
+ var foo = 123 +
+ 456 +
+ 789
+"
+
+ "
+package foo
+var foo = 123 +
+ 456 +
+ 789
+"
+ ))
- [nongnu] elpa/go-mode 77c6aae 422/495: Fix quotation marks in the gofmt doc string, (continued)
- [nongnu] elpa/go-mode 77c6aae 422/495: Fix quotation marks in the gofmt doc string, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 3f60838 424/495: Move testdata under test/ directory., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 3ba1982 427/495: Handle indentation for nested dangling operators, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode f6b1398 429/495: Fix filename handling in godoc-gogetdoc, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 00e72cd 431/495: Update default for godoc-and-godef-command, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 6b67088 432/495: Support trailing commas as dangling operators., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8ddf0b3 433/495: Speed up go-goto-opening-parenthesis, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode fdc1545 436/495: Fix indent for case statement comments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode d387378 438/495: indent: handle comments after multiline case lists, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode fbf2544 444/495: Improve fill-paragraph for comment blocks., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e7e0157 447/495: indent: fix indent at top level of file,
ELPA Syncer <=
- [nongnu] elpa/go-mode 3bc7479 450/495: Fix infinite loop in fill-region, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 88ffc9e 452/495: Add github action yaml file to run ert tests, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 4f15abf 449/495: Fix fill-paragraph for certain block comments., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode a13b814 448/495: Add option to reuse a single buffer for godoc, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode a82369b 453/495: Readme: add basic information about gopls., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 839190b 455/495: Run all tests in GH CI, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7248358 462/495: Fontify type names in type switch statements, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 4fabba6 464/495: Small fix for fontification of array types, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 656590a 463/495: Fontify qualified composite literal types., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode d304565 474/495: Fix signature fontification after comments., ELPA Syncer, 2021/08/07