From 20def317685b39a35416397b35940a4d040bf72f Mon Sep 17 00:00:00 2001 From: Micah Chalmer Date: Thu, 29 Aug 2013 22:59:38 -0400 Subject: [PATCH 1/4] Correct indent with trailing spaces/comments on previous line --- src/etc/emacs/rust-mode.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/etc/emacs/rust-mode.el b/src/etc/emacs/rust-mode.el index e0f25165ddda9..b79d09395b0fb 100644 --- a/src/etc/emacs/rust-mode.el +++ b/src/etc/emacs/rust-mode.el @@ -62,7 +62,8 @@ ;; - { means indent to either nesting-level * rust-indent-offset, ;; or one further indent from that if either current line ;; begins with 'else', or previous line didn't end in - ;; semi, comma or brace, and wasn't an attribute. PHEW. + ;; semi, comma or brace (other than whitespace and line + ;; comments) , and wasn't an attribute. PHEW. ((> level 0) (let ((pt (point))) (rust-rewind-irrelevant) @@ -79,7 +80,7 @@ (beginning-of-line) (rust-rewind-irrelevant) (end-of-line) - (if (looking-back "[{};,]") + (if (looking-back "[,;{}][[:space:]]*\\(?://.*\\)?") (* rust-indent-offset level) (back-to-indentation) (if (looking-at "#") From 0b9dc80d493cb911a2d9d4152433b5998a40d556 Mon Sep 17 00:00:00 2001 From: Micah Chalmer Date: Thu, 29 Aug 2013 23:28:36 -0400 Subject: [PATCH 2/4] One indent after open paren with no argument --- src/etc/emacs/rust-mode.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/etc/emacs/rust-mode.el b/src/etc/emacs/rust-mode.el index b79d09395b0fb..8cf6c45597946 100644 --- a/src/etc/emacs/rust-mode.el +++ b/src/etc/emacs/rust-mode.el @@ -68,7 +68,13 @@ (let ((pt (point))) (rust-rewind-irrelevant) (backward-up-list) - (if (looking-at "[[(]") + (if (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)) (progn (goto-char pt) @@ -80,7 +86,7 @@ (beginning-of-line) (rust-rewind-irrelevant) (end-of-line) - (if (looking-back "[,;{}][[:space:]]*\\(?://.*\\)?") + (if (looking-back "[,;{}(][[:space:]]*\\(?://.*\\)?") (* rust-indent-offset level) (back-to-indentation) (if (looking-at "#") From 70bc1637b877f52f824b34bbfbf73936d52a628e Mon Sep 17 00:00:00 2001 From: Micah Chalmer Date: Fri, 30 Aug 2013 01:15:32 -0400 Subject: [PATCH 3/4] Multiline comments with leading *s line up the *s --- src/etc/emacs/rust-mode.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/etc/emacs/rust-mode.el b/src/etc/emacs/rust-mode.el index 8cf6c45597946..5c94f6f4c84cd 100644 --- a/src/etc/emacs/rust-mode.el +++ b/src/etc/emacs/rust-mode.el @@ -57,6 +57,10 @@ ;; 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 + ((and (nth 4 (syntax-ppss)) (looking-at "*")) + (+ 1 (* rust-indent-offset level))) + ;; If we're in any other token-tree / sexp, then: ;; - [ or ( means line up with the opening token ;; - { means indent to either nesting-level * rust-indent-offset, From 7a42dd807430f11678e004bbbad9eda3a550dea9 Mon Sep 17 00:00:00 2001 From: Micah Chalmer Date: Fri, 30 Aug 2013 01:48:02 -0400 Subject: [PATCH 4/4] Align field names in struct expressions with fields on same line as the opening curly brace --- src/etc/emacs/rust-mode.el | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/etc/emacs/rust-mode.el b/src/etc/emacs/rust-mode.el index 5c94f6f4c84cd..92b85247e4891 100644 --- a/src/etc/emacs/rust-mode.el +++ b/src/etc/emacs/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 "\\") @@ -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))))))