branch: elpa/go-mode
commit 4f15abf0e8822c24e45590ef3f161e97920568aa
Author: Muir Manders <[email protected]>
Commit: Peter Sanford <[email protected]>
Fix fill-paragraph for certain block comments.
We weren't filling cases like this properly:
/*
Hello I am
an important comment.
*/
Now we properly detect the fill prefix that precedes "Hello".
---
go-mode.el | 21 ++++++++++++++-------
test/go-fill-paragraph-test.el | 22 ++++++++++++++++++++++
2 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/go-mode.el b/go-mode.el
index a5a6890..85d1bf5 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -656,13 +656,20 @@ case keyword. It returns nil for the case line itself."
(or (go--empty-line-p) (go--boring-comment-p))
(zerop (forward-line 1))))
- ;; If we are looking at the start of an interesting comment, our
- ;; prefix is the comment opener and any space following.
- (if (looking-at (concat go--comment-start-regexp "[[:space:]]*"))
- ;; Replace "/*" opener with spaces so following lines don't
- ;; get "/*" prefix.
- (replace-regexp-in-string "/\\*" " "
- (match-string-no-properties 0)))))
+ ;; If we are in a block comment, set prefix based on first line
+ ;; with content.
+ (if (go-in-comment-p)
+ (progn
+ (looking-at "[[:space:]]*")
+ (match-string-no-properties 0))
+
+ ;; Else if we are looking at the start of an interesting comment, our
+ ;; prefix is the comment opener and any space following.
+ (if (looking-at (concat go--comment-start-regexp "[[:space:]]*"))
+ ;; Replace "/*" opener with spaces so following lines don't
+ ;; get "/*" prefix.
+ (replace-regexp-in-string "/\\*" " "
+ (match-string-no-properties 0))))))
(defun go--fill-paragraph (&rest args)
"Wrap fill-paragraph to set custom fill-prefix."
diff --git a/test/go-fill-paragraph-test.el b/test/go-fill-paragraph-test.el
index 7a2c34e..5775018 100644
--- a/test/go-fill-paragraph-test.el
+++ b/test/go-fill-paragraph-test.el
@@ -127,6 +127,28 @@ func main() {
}"
))
+
+(ert-deftest go--fill-paragraph-block-offset ()
+ (go--should-fill
+ "
+func main() {
+<> /*
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit,
+ sed do eiusmod tempor incididunt ut labore
+ et dolore magna aliqua.
+ */
+}"
+
+ "
+func main() {
+ /*
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
+ do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+ */
+}"
+ ))
+
+
(ert-deftest go--fill-paragraph-block-region ()
(go--should-fill
"