8000 Fix indentation hang on first-line dangling operators by dajiaohuang · Pull Request #449 · dominikh/go-mode.el · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions go-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,12 @@ The return value is cached based on the current `line-beginning-position'."
(val (gethash line-begin go-dangling-cache 'nope)))
(when (or (go--buffer-narrowed-p) (equal val 'nope))
(save-excursion
(go--forward-line -1)
(if (go--current-line-has-dangling-op-p)
;; `forward-line' from a non-BOL position on the first line can
;; succeed by moving to the start of that same line. Ignore that
;; result unless it reached an earlier line.
(if (and (go--forward-line -1)
(< (line-beginning-position) line-begin)
(go--current-line-has-dangling-op-p))
(setq val (line-end-position))
(setq val nil))

Expand Down
11 changes: 11 additions & 0 deletions test/go-indentation-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ var foo = 123 +
"
))

(ert-deftest go--indent-first-line-ending-in-dangling-operator ()
;; The first line of an Org source block may be an expression without
;; the package declaration that normally precedes Go source.
(with-temp-buffer
(go-mode)
(insert "s := \"a\" +")
(goto-char (point-max))
(let ((inhibit-message t))
(go-mode-indent-line))
(should (equal (buffer-string) "s := \"a\" +"))))

(ert-deftest go--indent-multiline-comment ()
(go--should-indent
"
Expand Down
0