summaryrefslogtreecommitdiff
path: root/rust-mode.el
diff options
context:
space:
mode:
authorMicah Chalmer <micah@micahchalmer.net>2013-09-05 22:26:30 -0400
committerMicah Chalmer <micah@micahchalmer.net>2013-09-06 01:02:19 -0400
commit2765de71a30bcd24a9e433add88953148c602444 (patch)
treef1ee8e1f33b5673639f71befa4d08be5a78f8cae /rust-mode.el
parentaf2aba904eeb689b72f5c074030b1d527b6777dc (diff)
downloadrust-mode-2765de71a30bcd24a9e433add88953148c602444.tar.gz
Allow indenting to align struct fields after curly brace
Diffstat (limited to 'rust-mode.el')
-rw-r--r--rust-mode.el31
1 files changed, 14 insertions, 17 deletions
diff --git a/rust-mode.el b/rust-mode.el
index e45cec9..ff91192 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -45,6 +45,16 @@
(if (/= starting (point))
(rust-rewind-irrelevant))))
+(defun rust-first-indent-after-brace ()
+ (save-excursion
+ (forward-char)
+ (if (looking-at "[[:blank:]]*\\(?://.*\\)?$")
+ ;; We don't want to indent out to the open bracket if the
+ ;; open bracket ends the line
+ (* rust-indent-offset (rust-paren-level))
+ (when (looking-at "[[:space:]]") (forward-to-word 1))
+ (current-column))))
+
(defun rust-mode-indent-line ()
(interactive)
(let ((indent
@@ -58,7 +68,7 @@
;; A closing brace is 1 level unindended
((looking-at "}") (* rust-indent-offset (- level 1)))
- ; Doc comments in /** style with leading * indent to line up the *s
+ ;; Doc comments in /** style with leading * indent to line up the *s
((and (nth 4 (syntax-ppss)) (looking-at "*"))
(+ 1 (* rust-indent-offset level)))
@@ -75,22 +85,9 @@
(let ((pt (point)))
(rust-rewind-irrelevant)
(backward-up-list)
- (cond
- ((and
- (looking-at "[[(]")
- ; We don't want to indent out to the open bracket if the
- ; open bracket ends the line
- (save-excursion
- (forward-char)
- (not (looking-at "[[:space:]]*\\(?://.*\\)?$"))))
- (+ 1 (current-column)))
- ;; Check for fields on the same line as the open curly brace:
- ((looking-at "{[[:space:]]*[^\n]*,[[:space:]]*$")
+ (if (looking-at "[[({]")
+ (rust-first-indent-after-brace)
(progn
- (forward-char)
- (when (looking-at "[[:space:]]") (forward-to-word 1))
- (current-column)))
- (t (progn
(goto-char pt)
(back-to-indentation)
(if (looking-at "\\<else\\>")
@@ -105,7 +102,7 @@
(back-to-indentation)
(if (looking-at "#")
(* rust-indent-offset level)
- (* rust-indent-offset (+ 1 level)))))))))))
+ (* rust-indent-offset (+ 1 level))))))))))
;; Otherwise we're in a column-zero definition
(t 0))))))