[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode 2f2910c 223/495: fix end-of-defun for function wit
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode 2f2910c 223/495: fix end-of-defun for function with inline struct/interface arguments |
Date: |
Sat, 7 Aug 2021 09:05:18 -0400 (EDT) |
branch: elpa/go-mode
commit 2f2910c33de85119c026c53f180f7124f68548a9
Author: Erin Keenan <erinok@gmail.com>
Commit: Dominik Honnef <dominikh@fork-bomb.org>
fix end-of-defun for function with inline struct/interface arguments
Closes gh-34
---
go-mode.el | 13 ++++++++--
movement_tests/functions.go | 59 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+), 2 deletions(-)
diff --git a/go-mode.el b/go-mode.el
index 1604e74..e7e6981 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -548,8 +548,17 @@ current line will be returned."
;; It can happen that we're not placed before a function by emacs
(if (not (looking-at "func"))
(go-beginning-of-defun -1))
- (skip-chars-forward "^{")
- (forward-char)
+ ;; Find the { that starts the function, i.e., the next { that isn't
+ ;; preceded by struct or interface, or a comment or struct tag. BUG:
+ ;; breaks if there's a comment between the struct/interface keyword and
+ ;; bracket, like this:
+ ;;
+ ;; struct /* why? */ {
+ (while (progn
+ (skip-chars-forward "^{")
+ (forward-char)
+ (or (go-in-string-or-comment-p)
+ (looking-back "\\(struct\\|interface\\)\\s-*{"))))
(setq orig-level (go-paren-level))
(while (>= (go-paren-level) orig-level)
(skip-chars-forward "^}")
diff --git a/movement_tests/functions.go b/movement_tests/functions.go
new file mode 100644
index 0000000..40705bc
--- /dev/null
+++ b/movement_tests/functions.go
@@ -0,0 +1,59 @@
+// This file can be used to manually test that go-beginning-of-def and
+// go-end-of-defun are correct by entering into each function and mark-defun
+// (C-M-h).
+package main
+
+type typea int
+
+func easy(a, b, c int) int {
+ c += a
+ c += b
+ return c
+}
+
+func harder(a chan struct{}) {
+ close(a)
+}
+
+func harder(a struct {
+ b struct {
+ c interface {
+ Foo()
+ Bar()
+ Baz()
+ }
+ }
+}) interface {
+ Channer() chan struct{}
+} {
+ return nil
+}
+
+func oneline(a struct{}) (r struct{ a int }) { return r }
+
+type typeb struct {
+ a, b, c int
+}
+
+// comment1 breaks end-of-defun by splitting "struct" from "{". (This also
+// apparently breaks gofmt, is why this is formatted so weird.)
+func comment1(a chan struct /* why? */ {
+
+}) {
+ close(a)
+}
+
+func comment2(a struct {
+ b int // b is sad :{
+ c int
+}) {
+ a.b += a.c
+ a.c += a.b
+ return
+}
+
+func structWithTag(a chan struct {
+ v int `{`
+}) {
+ close(a)
+}
- [nongnu] elpa/go-mode d304565 474/495: Fix signature fontification after comments., (continued)
- [nongnu] elpa/go-mode d304565 474/495: Fix signature fontification after comments., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e9b9c0e 473/495: Add some fontification faces for go-dot-mod-mode., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 4acf733 468/495: Fully fontify type and const decls., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode dac200f 469/495: Fix font locking in nested signatures., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode fa2162b 475/495: Fix "nil" fontification in type switch clause., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7ce031c 481/495: Allow disabling variable font locking., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e10d677 478/495: indent: fix func literals in dangling lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode c9f5e92 483/495: Fix indentation of chained dangling selectors., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode fdf46fe 492/495: Fix go.mod fontification., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e8eea7f 487/495: Fix fontification of multiline type switch clauses., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 2f2910c 223/495: fix end-of-defun for function with inline struct/interface arguments,
ELPA Syncer <=
- [nongnu] elpa/go-mode f1adac0 230/495: switch versioning to semver, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode d9f0bee 232/495: add variable to customize godef command, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 3da268f 285/495: README: improve description of new functions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 9047fcd 238/495: add a menu, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 466e188 239/495: add `go-play-browse-function', ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8c13a82 240/495: match identifiers, not type names, when highlighting struct literal, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 775c77a 241/495: immediately store match data in go-unused-imports-lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode aaea941 242/495: bump version to 1.2.0, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode bf4a097 243/495: add Iwasaki Yudai to AUTHORS, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 498452d 244/495: Don't set old buffer as active after godef--find-file-line-column, ELPA Syncer, 2021/08/07