|
5 | 5 | ;; Url: https://github.com/mozilla/rust |
6 | 6 |
|
7 | 7 | (eval-when-compile (require 'cl)) |
| 8 | +(eval-when-compile (require 'misc)) |
8 | 9 |
|
9 | 10 | ;; Syntax definitions and helpers |
10 | 11 | (defvar rust-mode-syntax-table |
|
67 | 68 | ;; or one further indent from that if either current line |
68 | 69 | ;; begins with 'else', or previous line didn't end in |
69 | 70 | ;; 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. |
71 | 74 | ((> level 0) |
72 | 75 | (let ((pt (point))) |
73 | 76 | (rust-rewind-irrelevant) |
74 | 77 | (backward-up-list) |
75 | | - (if (and |
| 78 | + (cond |
| 79 | + ((and |
76 | 80 | (looking-at "[[(]") |
77 | 81 | ; We don't want to indent out to the open bracket if the |
78 | 82 | ; open bracket ends the line |
79 | 83 | (save-excursion |
80 | 84 | (forward-char) |
81 | 85 | (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:]]*$") |
83 | 89 | (progn |
| 90 | + (forward-char) |
| 91 | + (forward-to-word 1) |
| 92 | + (current-column))) |
| 93 | + (t (progn |
84 | 94 | (goto-char pt) |
85 | 95 | (back-to-indentation) |
86 | 96 | (if (looking-at "\\<else\\>") |
|
95 | 105 | (back-to-indentation) |
96 | 106 | (if (looking-at "#") |
97 | 107 | (* rust-indent-offset level) |
98 | | - (* rust-indent-offset (+ 1 level)))))))))) |
| 108 | + (* rust-indent-offset (+ 1 level))))))))))) |
99 | 109 |
|
100 | 110 | ;; Otherwise we're in a column-zero definition |
101 | 111 | (t 0)))))) |
|
0 commit comments