Skip to content

Commit 3596f66

Browse files
committed
rust-mode: make indentation customizable
Add new variable rust-indent-offset, defaulting to the old value, and use it.
1 parent 9db698a commit 3596f66

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/etc/emacs/rust-mode.el

+11-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929

3030
table))
3131

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+
3237
(defun rust-paren-level () (nth 0 (syntax-ppss)))
3338
(defun rust-in-str-or-cmnt () (nth 8 (syntax-ppss)))
3439
(defun rust-rewind-past-str-cmnt () (goto-char (nth 8 (syntax-ppss))))
@@ -49,10 +54,10 @@
4954
(let ((level (rust-paren-level)))
5055
(cond
5156
;; A function return type is 1 level indented
52-
((looking-at "->") (* default-tab-width (+ level 1)))
57+
((looking-at "->") (* rust-indent-offset (+ level 1)))
5358

5459
;; A closing brace is 1 level unindended
55-
((looking-at "}") (* default-tab-width (- level 1)))
60+
((looking-at "}") (* rust-indent-offset (- level 1)))
5661

5762
;; If we're in any other token-tree / sexp, then:
5863
;; - [ or ( means line up with the opening token
@@ -70,18 +75,18 @@
7075
(goto-char pt)
7176
(back-to-indentation)
7277
(if (looking-at "\\<else\\>")
73-
(* default-tab-width (+ 1 level))
78+
(* rust-indent-offset (+ 1 level))
7479
(progn
7580
(goto-char pt)
7681
(beginning-of-line)
7782
(rust-rewind-irrelevant)
7883
(end-of-line)
7984
(if (looking-back "[{};,]")
80-
(* default-tab-width level)
85+
(* rust-indent-offset level)
8186
(back-to-indentation)
8287
(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))))))))))
8590

8691
;; Otherwise we're in a column-zero definition
8792
(t 0))))))

0 commit comments

Comments
 (0)