Skip to content

Commit 0dd70cf

Browse files
committed
Fix indentation of closing braces
The ‘nginx-indent-block’ function would get confused by braces in comments. Here is an example of how indentation could go wrong: server { # some comment with { # ... } After this change the example is correctly indented: server { # some comment with { # ... }
1 parent 6e9d96f commit 0dd70cf

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

nginx-mode.el

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,8 @@
7676
"If point is in a block, return the indentation of the first line of that
7777
block (the line containing the opening brace). Used to set the indentation
7878
of the closing brace of a block."
79-
(save-excursion
80-
(save-match-data
81-
(let ((opoint (point))
82-
(apoint (search-backward "{" nil t)))
83-
(when apoint
84-
;; This is a bit of a hack and doesn't allow for strings. We really
85-
;; want to parse by sexps at some point.
86-
(let ((close-braces (count-matches "}" apoint opoint))
87-
(open-braces 0))
88-
(while (and apoint (> close-braces open-braces))
89-
(setq apoint (search-backward "{" nil t))
90-
(when apoint
91-
(setq close-braces (count-matches "}" apoint opoint))
92-
(setq open-braces (1+ open-braces)))))
93-
(if apoint
94-
(current-indentation)
95-
nil))))))
96-
79+
(* (syntax-ppss-depth (syntax-ppss))
80+
nginx-indent-level))
9781

9882
(defun nginx-comment-line-p ()
9983
"Return non-nil iff this line is a comment."
@@ -116,7 +100,7 @@ of the closing brace of a block."
116100
;; This line contains a closing brace and we're at the inner
117101
;; block, so we should indent it matching the indentation of
118102
;; the opening brace of the block.
119-
(setq cur-indent block-indent))
103+
(setq cur-indent (- block-indent nginx-indent-level)))
120104
(t
121105
;; Otherwise, we did not start on a block-ending-only line.
122106
(save-excursion

0 commit comments

Comments
 (0)