|
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
|
|
57 | 58 | ;; A closing brace is 1 level unindended
|
58 | 59 | ((looking-at "}") (* rust-indent-offset (- level 1)))
|
59 | 60 |
|
| 61 | + ; Doc comments in /** style with leading * indent to line up the *s |
| 62 | + ((and (nth 4 (syntax-ppss)) (looking-at "*")) |
| 63 | + (+ 1 (* rust-indent-offset level))) |
| 64 | + |
60 | 65 | ;; If we're in any other token-tree / sexp, then:
|
61 | 66 | ;; - [ or ( means line up with the opening token
|
62 | 67 | ;; - { means indent to either nesting-level * rust-indent-offset,
|
63 | 68 | ;; or one further indent from that if either current line
|
64 | 69 | ;; begins with 'else', or previous line didn't end in
|
65 |
| - ;; semi, comma or brace, and wasn't an attribute. PHEW. |
| 70 | + ;; semi, comma or brace (other than whitespace and line |
| 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. |
66 | 74 | ((> level 0)
|
67 | 75 | (let ((pt (point)))
|
68 | 76 | (rust-rewind-irrelevant)
|
69 | 77 | (backward-up-list)
|
70 |
| - (if (looking-at "[[(]") |
71 |
| - (+ 1 (current-column)) |
| 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 "{[[:blank:]]*[^}\n]*,[[:space:]]*$") |
72 | 89 | (progn
|
| 90 | + (forward-char) |
| 91 | + (forward-to-word 1) |
| 92 | + (current-column))) |
| 93 | + (t (progn |
73 | 94 | (goto-char pt)
|
74 | 95 | (back-to-indentation)
|
75 | 96 | (if (looking-at "\\<else\\>")
|
|
79 | 100 | (beginning-of-line)
|
80 | 101 | (rust-rewind-irrelevant)
|
81 | 102 | (end-of-line)
|
82 |
| - (if (looking-back "[{};,]") |
| 103 | + (if (looking-back "[,;{}(][[:space:]]*\\(?://.*\\)?") |
83 | 104 | (* rust-indent-offset level)
|
84 | 105 | (back-to-indentation)
|
85 | 106 | (if (looking-at "#")
|
86 | 107 | (* rust-indent-offset level)
|
87 |
| - (* rust-indent-offset (+ 1 level)))))))))) |
| 108 | + (* rust-indent-offset (+ 1 level))))))))))) |
88 | 109 |
|
89 | 110 | ;; Otherwise we're in a column-zero definition
|
90 | 111 | (t 0))))))
|
|
0 commit comments