diff options
| author | Micah Chalmer <micah@micahchalmer.net> | 2013-08-30 01:48:02 -0400 |
|---|---|---|
| committer | Micah Chalmer <micah@micahchalmer.net> | 2013-08-30 02:04:08 -0400 |
| commit | 3301c707f32c48a75f970e1e9c21fa5d011cb50d (patch) | |
| tree | ca8a2779df63b7ae6cd0e621da2640ca199c5447 /rust-mode.el | |
| parent | fe55b710f6cadaaab64aa58a5a4c19b2c5a90736 (diff) | |
| download | rust-mode-3301c707f32c48a75f970e1e9c21fa5d011cb50d.tar.gz | |
Align field names in struct expressions with fields on same line as the opening curly brace
Diffstat (limited to 'rust-mode.el')
| -rw-r--r-- | rust-mode.el | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/rust-mode.el b/rust-mode.el index 5c94f6f..92b8524 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -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 @@ -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\\>") @@ -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)))))) |
