|
29 | 29 |
|
30 | 30 | table))
|
31 | 31 |
|
| 32 | +(defcustom rust-indent-offset default-tab-width |
| 33 | + "*Indent Rust code by this number of spaces. |
| 34 | +
|
| 35 | +The initializer is `DEFAULT-TAB-WIDTH'.") |
| 36 | + |
32 | 37 | (defun rust-paren-level () (nth 0 (syntax-ppss)))
|
33 | 38 | (defun rust-in-str-or-cmnt () (nth 8 (syntax-ppss)))
|
34 | 39 | (defun rust-rewind-past-str-cmnt () (goto-char (nth 8 (syntax-ppss))))
|
|
49 | 54 | (let ((level (rust-paren-level)))
|
50 | 55 | (cond
|
51 | 56 | ;; A function return type is 1 level indented
|
52 |
| - ((looking-at "->") (* default-tab-width (+ level 1))) |
| 57 | + ((looking-at "->") (* rust-indent-offset (+ level 1))) |
53 | 58 |
|
54 | 59 | ;; A closing brace is 1 level unindended
|
55 |
| - ((looking-at "}") (* default-tab-width (- level 1))) |
| 60 | + ((looking-at "}") (* rust-indent-offset (- level 1))) |
56 | 61 |
|
57 | 62 | ;; If we're in any other token-tree / sexp, then:
|
58 | 63 | ;; - [ or ( means line up with the opening token
|
|
70 | 75 | (goto-char pt)
|
71 | 76 | (back-to-indentation)
|
72 | 77 | (if (looking-at "\\<else\\>")
|
73 |
| - (* default-tab-width (+ 1 level)) |
| 78 | + (* rust-indent-offset (+ 1 level)) |
74 | 79 | (progn
|
75 | 80 | (goto-char pt)
|
76 | 81 | (beginning-of-line)
|
77 | 82 | (rust-rewind-irrelevant)
|
78 | 83 | (end-of-line)
|
79 | 84 | (if (looking-back "[{};,]")
|
80 |
| - (* default-tab-width level) |
| 85 | + (* rust-indent-offset level) |
81 | 86 | (back-to-indentation)
|
82 | 87 | (if (looking-at "#")
|
83 |
| - (* default-tab-width level) |
84 |
| - (* default-tab-width (+ 1 level)))))))))) |
| 88 | + (* rust-indent-offset level) |
| 89 | + (* rust-indent-offset (+ 1 level)))))))))) |
85 | 90 |
|
86 | 91 | ;; Otherwise we're in a column-zero definition
|
87 | 92 | (t 0))))))
|
|
0 commit comments