Skip to content

Commit 7a42dd8

Browse files
committed
Align field names in struct expressions with fields on same line as the opening curly brace
1 parent 70bc163 commit 7a42dd8

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/etc/emacs/rust-mode.el

+14-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
;; Url: https://github.com/mozilla/rust
66

77
(eval-when-compile (require 'cl))
8+
(eval-when-compile (require 'misc))
89

910
;; Syntax definitions and helpers
1011
(defvar rust-mode-syntax-table
@@ -67,20 +68,29 @@
6768
;; or one further indent from that if either current line
6869
;; begins with 'else', or previous line didn't end in
6970
;; semi, comma or brace (other than whitespace and line
70-
;; comments) , and wasn't an attribute. PHEW.
71+
;; comments) , and wasn't an attribute. But if we have
72+
;; something after the open brace and ending with a comma,
73+
;; treat it as fields and align them. PHEW.
7174
((> level 0)
7275
(let ((pt (point)))
7376
(rust-rewind-irrelevant)
7477
(backward-up-list)
75-
(if (and
78+
(cond
79+
((and
7680
(looking-at "[[(]")
7781
; We don't want to indent out to the open bracket if the
7882
; open bracket ends the line
7983
(save-excursion
8084
(forward-char)
8185
(not (looking-at "[[:space:]]*\\(?://.*\\)?$"))))
82-
(+ 1 (current-column))
86+
(+ 1 (current-column)))
87+
;; Check for fields on the same line as the open curly brace:
88+
((looking-at "{[[:blank:]]*[^}\n]*,[[:space:]]*$")
8389
(progn
90+
(forward-char)
91+
(forward-to-word 1)
92+
(current-column)))
93+
(t (progn
8494
(goto-char pt)
8595
(back-to-indentation)
8696
(if (looking-at "\\<else\\>")
@@ -95,7 +105,7 @@
95105
(back-to-indentation)
96106
(if (looking-at "#")
97107
(* rust-indent-offset level)
98-
(* rust-indent-offset (+ 1 level))))))))))
108+
(* rust-indent-offset (+ 1 level)))))))))))
99109

100110
;; Otherwise we're in a column-zero definition
101111
(t 0))))))

0 commit comments

Comments
 (0)