[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode b990645 425/495: Fix call expr indenting after dan
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode b990645 425/495: Fix call expr indenting after dangling operator. |
Date: |
Sat, 7 Aug 2021 09:06:01 -0400 (EDT) |
branch: elpa/go-mode
commit b990645d59dd6c54ac7f54608510a218f605848e
Author: Muir Manders <muir@retailnext.net>
Commit: Peter Sanford <psanford@sanford.io>
Fix call expr indenting after dangling operator.
We were indenting like
f :=
print(1,
2,
)
because the "(" follows a line with a dangling operator, so we weren't
adding an extra indent. I think this logic was to avoid giving an
extra indent when a block opening "{" follows a line with a dangling
operator. I added some extra logic to always indent the line after an
opening "(".
Similarly we were indenting like
f :=
int64(4 *
3 *
1)
because "3"'s previous line was already indented due to a dangling
operator. I added more logic to always indent in this case when the
previous line opens a "(".
Note that there are still other broken cases involving "{" because we
can't currently differentiate between a block opening curly and a
composite literal curly:
f :=
map[int]bool{
1: 3,
}
Fixes #13
---
go-mode.el | 26 ++++++++++++++++++----
test/go-indentation-test.el | 17 ++++++++++++++
.../indentation_tests/dangling_operator.go | 10 +++++++++
3 files changed, 49 insertions(+), 4 deletions(-)
diff --git a/go-mode.el b/go-mode.el
index d515174..361c862 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -586,6 +586,17 @@ current line will be returned."
(current-indentation))
(current-indentation))))
+(defun go--line-opens-paren-p ()
+ "Returns whether current line opens a paren that contains point."
+ (save-excursion
+ (let ((start-paren-level (go-paren-level))
+ (line-beginning (line-beginning-position)))
+ (go-goto-opening-parenthesis)
+ (and
+ (eq (char-after) ?\() ; opening paren-like character is actually a paren
+ (< (go-paren-level) start-paren-level) ; point is before the closing
paren
+ (>= (point) line-beginning))))) ; still on starting line
+
(defun go-indentation-at-point ()
(save-excursion
(let (start-nesting)
@@ -597,20 +608,27 @@ current line will be returned."
(current-indentation))
((looking-at "[])}]")
(go-goto-opening-parenthesis)
- (if (go-previous-line-has-dangling-op-p)
+ (if (and
+ (not (eq (char-after) ?\()) ; opening parens always indent
+ (go-previous-line-has-dangling-op-p))
(- (current-indentation) tab-width)
(go--indentation-for-opening-parenthesis)))
((progn (go--backward-irrelevant t)
(looking-back go-dangling-operators-regexp
(- (point) go--max-dangling-operator-length)))
;; only one nesting for all dangling operators in one operation
- (if (go-previous-line-has-dangling-op-p)
- (current-indentation)
+ (if (and
+ (not (go--line-opens-paren-p))
+ (go-previous-line-has-dangling-op-p))
+ (progn
+ (current-indentation))
(+ (current-indentation) tab-width)))
((zerop (go-paren-level))
0)
((progn (go-goto-opening-parenthesis) (< (go-paren-level)
start-nesting))
- (if (go-previous-line-has-dangling-op-p)
+ (if (and
+ (not (eq (char-after) ?\()) ; opening parens always indent
+ (go-previous-line-has-dangling-op-p))
(current-indentation)
(+ (go--indentation-for-opening-parenthesis) tab-width)))
(t
diff --git a/test/go-indentation-test.el b/test/go-indentation-test.el
new file mode 100644
index 0000000..a1be805
--- /dev/null
+++ b/test/go-indentation-test.el
@@ -0,0 +1,17 @@
+;;; go-indentation-test.el
+
+;; Copyright 2019 The go-mode Authors. All rights reserved.
+;; Use of this source code is governed by a BSD-style
+;; license that can be found in the LICENSE file.
+
+(require 'ert)
+(require 'go-mode)
+
+(ert-deftest go--indent-line ()
+ (dolist (file (directory-files (expand-file-name
"testdata/indentation_tests/") t ".*\\.go$"))
+ (with-temp-buffer
+ (go-mode)
+ (insert-file-contents file)
+ (let ((contents-before-indent (buffer-string)))
+ (indent-region (point-min) (point-max) nil)
+ (should (string= contents-before-indent (buffer-string)))))))
diff --git a/test/testdata/indentation_tests/dangling_operator.go
b/test/testdata/indentation_tests/dangling_operator.go
index 9753358..6eff406 100644
--- a/test/testdata/indentation_tests/dangling_operator.go
+++ b/test/testdata/indentation_tests/dangling_operator.go
@@ -25,5 +25,15 @@ func init() {
456,
)
+ f :=
+ print(1,
+ 2,
+ )
+
+ g :=
+ int64(4 *
+ 3 *
+ 1)
+
return
}
- [nongnu] elpa/go-mode 1b85887 389/495: refactor/rename: require cl-lib, use cl- namespace, (continued)
- [nongnu] elpa/go-mode 1b85887 389/495: refactor/rename: require cl-lib, use cl- namespace, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8144ae8 392/495: Merge commit '12ef34c', ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 269eb01 398/495: Remove support for Emacs 23, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 5056b85 403/495: Use xref functions if available, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 3f02a16 406/495: Add go-guru-definition-other-window, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7eb5b3d 409/495: Delete go-mode-autoloads.el, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 2d1d33a 407/495: Fix off-by-one in point calculations, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7f87c32 416/495: Permit empty guru scope, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode be9186c 417/495: Support remote files in `gofmt', ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 287595a 420/495: Don't traverse symlinks when recursing directories, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode b990645 425/495: Fix call expr indenting after dangling operator.,
ELPA Syncer <=
- [nongnu] elpa/go-mode ac6dd8c 430/495: Fix go-remove-unused-imports, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e8674fe 437/495: Expand electric indent config a bit, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 6a64cbf 439/495: Fix indentation for composite literal keys., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode fb1272c 441/495: indent: fix performance in giant comments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode c020e2c 456/495: Fontify type names in more places., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 2a1584f 454/495: Readme: add note recommending goimports, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 57becfb 460/495: Fontify type names in interface declarations, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode cf53daa 459/495: Fix indentation in naked blocks., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode f872781 466/495: Fontify variable names., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode acec0aa 471/495: Fix Content-Type for https://play.golang.org/share, ELPA Syncer, 2021/08/07