Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Align field names in struct expressions with fields on same line as t…
…he opening curly brace
  • Loading branch information
MicahChalmer committed Aug 30, 2013
1 parent 70bc163 commit 7a42dd8
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/etc/emacs/rust-mode.el
Expand Up @@ -5,6 +5,7 @@
;; Url: https://github.com/mozilla/rust

(eval-when-compile (require 'cl))
(eval-when-compile (require 'misc))

;; Syntax definitions and helpers
(defvar rust-mode-syntax-table
Expand Down Expand Up @@ -67,20 +68,29 @@
;; or one further indent from that if either current line
;; begins with 'else', or previous line didn't end in
;; semi, comma or brace (other than whitespace and line
;; comments) , and wasn't an attribute. PHEW.
;; comments) , and wasn't an attribute. But if we have
;; something after the open brace and ending with a comma,
;; treat it as fields and align them. PHEW.
((> level 0)
(let ((pt (point)))
(rust-rewind-irrelevant)
(backward-up-list)
(if (and
(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))
(+ 1 (current-column)))
;; Check for fields on the same line as the open curly brace:
((looking-at "{[[:blank:]]*[^}\n]*,[[:space:]]*$")
(progn
(forward-char)
(forward-to-word 1)
(current-column)))
(t (progn
(goto-char pt)
(back-to-indentation)
(if (looking-at "\\<else\\>")
Expand All @@ -95,7 +105,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))))))
Expand Down

5 comments on commit 7a42dd8

@bors
Copy link
Contributor

@bors bors commented on 7a42dd8 Aug 30, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pnkfelix
at MicahChalmer@7a42dd8

@bors
Copy link
Contributor

@bors bors commented on 7a42dd8 Aug 30, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging MicahChalmer/rust/emacs-indent-fix = 7a42dd8 into auto

@bors
Copy link
Contributor

@bors bors commented on 7a42dd8 Aug 30, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MicahChalmer/rust/emacs-indent-fix = 7a42dd8 merged ok, testing candidate = 8e3efc1

@bors
Copy link
Contributor

@bors bors commented on 7a42dd8 Aug 30, 2013

@bors
Copy link
Contributor

@bors bors commented on 7a42dd8 Aug 30, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 8e3efc1

Please sign in to comment.