mirror of
https://github.com/golang/go
synced 2024-11-13 15:20:22 -07:00
Correct indentation for go-mode where a close brace following a semi-
colon-less statement would be indented one stop too many. R=rsc, aclements CC=aclements https://golang.org/cl/154096
This commit is contained in:
parent
a01839fb82
commit
95be81da4d
@ -352,7 +352,8 @@ indented one level."
|
|||||||
(t
|
(t
|
||||||
;; Neither top-level nor in a multi-line string or comment
|
;; Neither top-level nor in a multi-line string or comment
|
||||||
(let ((indent 0)
|
(let ((indent 0)
|
||||||
(inside-indenting-paren nil))
|
(inside-indenting-paren nil)
|
||||||
|
(current-line-closes-scope nil))
|
||||||
;; Count every enclosing brace, plus parens that follow
|
;; Count every enclosing brace, plus parens that follow
|
||||||
;; import, const, var, or type and indent according to
|
;; import, const, var, or type and indent according to
|
||||||
;; depth. This simple rule does quite well, but also has a
|
;; depth. This simple rule does quite well, but also has a
|
||||||
@ -376,9 +377,18 @@ indented one level."
|
|||||||
(setq inside-indenting-paren t)))))
|
(setq inside-indenting-paren t)))))
|
||||||
(setq first nil))))
|
(setq first nil))))
|
||||||
|
|
||||||
|
(setq current-line-closes-scope
|
||||||
|
(case (char-after)
|
||||||
|
((?\} ?\)) t)
|
||||||
|
(t nil)))
|
||||||
|
|
||||||
;; case, default, and labels are outdented 1 level
|
;; case, default, and labels are outdented 1 level
|
||||||
(when (looking-at "\\<case\\>\\|\\<default\\>\\|\\w+\\s *:\\(\\S.\\|$\\)")
|
(when (looking-at "\\<case\\>\\|\\<default\\>\\|\\w+\\s *:\\(\\S.\\|$\\)")
|
||||||
(decf indent tab-width))
|
(decf indent tab-width)
|
||||||
|
;; Lines with case, default, etc. also "close" the previous line's
|
||||||
|
;; scope, even when there is no semicolon. Don't treat them as
|
||||||
|
;; continuation lines.
|
||||||
|
(setq current-line-closes-scope t))
|
||||||
|
|
||||||
;; Continuation lines are indented 1 level
|
;; Continuation lines are indented 1 level
|
||||||
(forward-comment (- (buffer-size)))
|
(forward-comment (- (buffer-size)))
|
||||||
@ -401,8 +411,9 @@ indented one level."
|
|||||||
(and depth
|
(and depth
|
||||||
(not (eq (char-after (caar depth)) ?\{)))))
|
(not (eq (char-after (caar depth)) ?\{)))))
|
||||||
(t
|
(t
|
||||||
;; Anything else is always a continuation line
|
;; Except when the current line closes the previous line's
|
||||||
t))
|
;; scope, anything else is a continuation line.
|
||||||
|
(not current-line-closes-scope)))
|
||||||
(incf indent tab-width))
|
(incf indent tab-width))
|
||||||
(max indent 0)))))))
|
(max indent 0)))))))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user