branch: elpa/go-mode
commit 1fbe6a8151e770cfc50e7a1bfb956c5312d9141e
Author: Muir Manders <[email protected]>
Commit: Peter Sanford <[email protected]>
Fix comment filling at start of buffer.
In cases like:
// Sweet
// comment.
package foo
We weren't filling the comment properly
because (go--fill-forward-paragraph -1) was ending up on the second
line instead of the first. It goes backwards to the first line with no
comment content and then moves forward one line, but at the beginning
of the buffer there is no line preceeding the comment. Tweak the logic
to not move forward if the current line has comment content.
Fixes #373.
Closes: #374 [via git-merge-pr]
---
go-mode.el | 8 +++++---
test/go-fill-paragraph-test.el | 18 ++++++++++++++++++
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/go-mode.el b/go-mode.el
index 1675280..835dc18 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -845,9 +845,11 @@ thing for comments."
(when mark-active
(setq arg (forward-paragraph arg)))
(setq done t))
- ;; If we are going backwards, back up one more line so
- ;; we are on the line before the comment.
- (when (= single -1)
+ ;; If we are going backwards, move forward one line so we
+ ;; are on the first interesting line of the comment. Note
+ ;; that the current line may already be interesting if we
+ ;; are at the beginning of the buffer.
+ (when (and (= single -1) (not (go--interesting-comment-p)))
(forward-line 1))
(cl-decf arg single))))
arg))
diff --git a/test/go-fill-paragraph-test.el b/test/go-fill-paragraph-test.el
index 0b5412a..9d23aab 100644
--- a/test/go-fill-paragraph-test.el
+++ b/test/go-fill-paragraph-test.el
@@ -218,3 +218,21 @@ func main() {
if something() { somethingElse() }
}"
))
+
+
+(ert-deftest go--fill-paragraph-bob ()
+ (go--should-fill
+ "<>// Lorem
+// ipsum."
+ "// Lorem ipsum."
+ )
+
+ (go--should-fill
+ "<>/*
+ Lorem
+ ipsum.
+*/"
+ "/*
+ Lorem ipsum.
+*/"
+ ))