|
45 | 45 | (if (/= starting (point))
|
46 | 46 | (rust-rewind-irrelevant))))
|
47 | 47 |
|
| 48 | +(defun rust-first-indent-after-brace () |
| 49 | + (save-excursion |
| 50 | + (forward-char) |
| 51 | + (if (looking-at "[[:blank:]]*\\(?://.*\\)?$") |
| 52 | + ;; We don't want to indent out to the open bracket if the |
| 53 | + ;; open bracket ends the line |
| 54 | + (* rust-indent-offset (rust-paren-level)) |
| 55 | + (when (looking-at "[[:space:]]") (forward-to-word 1)) |
| 56 | + (current-column)))) |
| 57 | + |
48 | 58 | (defun rust-mode-indent-line ()
|
49 | 59 | (interactive)
|
50 | 60 | (let ((indent
|
|
58 | 68 | ;; A closing brace is 1 level unindended
|
59 | 69 | ((looking-at "}") (* rust-indent-offset (- level 1)))
|
60 | 70 |
|
61 |
| - ; Doc comments in /** style with leading * indent to line up the *s |
| 71 | + ;; Doc comments in /** style with leading * indent to line up the *s |
62 | 72 | ((and (nth 4 (syntax-ppss)) (looking-at "*"))
|
63 | 73 | (+ 1 (* rust-indent-offset level)))
|
64 | 74 |
|
|
75 | 85 | (let ((pt (point)))
|
76 | 86 | (rust-rewind-irrelevant)
|
77 | 87 | (backward-up-list)
|
78 |
| - (cond |
79 |
| - ((and |
80 |
| - (looking-at "[[(]") |
81 |
| - ; We don't want to indent out to the open bracket if the |
82 |
| - ; open bracket ends the line |
83 |
| - (save-excursion |
84 |
| - (forward-char) |
85 |
| - (not (looking-at "[[:space:]]*\\(?://.*\\)?$")))) |
86 |
| - (+ 1 (current-column))) |
87 |
| - ;; Check for fields on the same line as the open curly brace: |
88 |
| - ((looking-at "{[[:space:]]*[^\n]*,[[:space:]]*$") |
| 88 | + (if (looking-at "[[({]") |
| 89 | + (rust-first-indent-after-brace) |
89 | 90 | (progn
|
90 |
| - (forward-char) |
91 |
| - (when (looking-at "[[:space:]]") (forward-to-word 1)) |
92 |
| - (current-column))) |
93 |
| - (t (progn |
94 | 91 | (goto-char pt)
|
95 | 92 | (back-to-indentation)
|
96 | 93 | (if (looking-at "\\<else\\>")
|
|
105 | 102 | (back-to-indentation)
|
106 | 103 | (if (looking-at "#")
|
107 | 104 | (* rust-indent-offset level)
|
108 |
| - (* rust-indent-offset (+ 1 level))))))))))) |
| 105 | + (* rust-indent-offset (+ 1 level)))))))))) |
109 | 106 |
|
110 | 107 | ;; Otherwise we're in a column-zero definition
|
111 | 108 | (t 0))))))
|
|
0 commit comments