From a72bd699cff26175be7156db13758d17bb88813e Mon Sep 17 00:00:00 2001 From: Daniel Raloff Date: Tue, 16 Dec 2014 00:43:57 -0800 Subject: [PATCH 1/2] added optional method chain indentations for emacs major mode --- src/etc/emacs/rust-mode.el | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/etc/emacs/rust-mode.el b/src/etc/emacs/rust-mode.el index 6917e9ee354e..f66df6c05656 100644 --- a/src/etc/emacs/rust-mode.el +++ b/src/etc/emacs/rust-mode.el @@ -49,6 +49,11 @@ :type 'integer :group 'rust-mode) +(defcustom rust-indent-method-chain nil + "Indent Rust method chains, aligned by the '.' operators" + :type 'boolean + :group 'rust-mode) + (defun rust-paren-level () (nth 0 (syntax-ppss))) (defun rust-in-str-or-cmnt () (nth 8 (syntax-ppss))) (defun rust-rewind-past-str-cmnt () (goto-char (nth 8 (syntax-ppss)))) @@ -72,6 +77,15 @@ (backward-word 1)) (current-column)))) +(defun rust-align-to-method-chain () + (save-excursion + (previous-line) + (end-of-line) + (backward-word 1) + (backward-char) + (when (looking-at "\\..+\(.*\)\n") + (- (current-column) rust-indent-offset)))) + (defun rust-rewind-to-beginning-of-current-level-expr () (let ((current-level (rust-paren-level))) (back-to-indentation) @@ -94,10 +108,13 @@ ;; the inside of it correctly relative to the outside. (if (= 0 level) 0 + (or + (when rust-indent-method-chain + (rust-align-to-method-chain)) (save-excursion (backward-up-list) (rust-rewind-to-beginning-of-current-level-expr) - (+ (current-column) rust-indent-offset))))) + (+ (current-column) rust-indent-offset)))))) (cond ;; A function return type is indented to the corresponding function arguments ((looking-at "->") @@ -109,6 +126,16 @@ ;; A closing brace is 1 level unindended ((looking-at "}") (- baseline rust-indent-offset)) + ;;Line up method chains by their .'s + ((when (and rust-indent-method-chain + (looking-at "\..+\(.*\);?\n")) + (or + (let ((method-indent (rust-align-to-method-chain))) + (when method-indent + (+ method-indent rust-indent-offset))) + (+ baseline rust-indent-offset)))) + + ;; Doc comments in /** style with leading * indent to line up the *s ((and (nth 4 (syntax-ppss)) (looking-at "*")) (+ 1 baseline)) From 8051bd06260e4587e183e6055a6794414e7c76f9 Mon Sep 17 00:00:00 2001 From: Daniel Raloff Date: Tue, 20 Jan 2015 14:07:10 -0800 Subject: [PATCH 2/2] Changed rust-mode code for tabs -> spaces --- src/etc/emacs/rust-mode.el | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/etc/emacs/rust-mode.el b/src/etc/emacs/rust-mode.el index f66df6c05656..ed1523d64f9c 100644 --- a/src/etc/emacs/rust-mode.el +++ b/src/etc/emacs/rust-mode.el @@ -73,18 +73,18 @@ ;; open bracket ends the line (when (not (looking-at "[[:blank:]]*\\(?://.*\\)?$")) (when (looking-at "[[:space:]]") - (forward-word 1) - (backward-word 1)) + (forward-word 1) + (backward-word 1)) (current-column)))) (defun rust-align-to-method-chain () (save-excursion - (previous-line) - (end-of-line) - (backward-word 1) - (backward-char) - (when (looking-at "\\..+\(.*\)\n") - (- (current-column) rust-indent-offset)))) + (previous-line) + (end-of-line) + (backward-word 1) + (backward-char) + (when (looking-at "\\..+\(.*\)\n") + (- (current-column) rust-indent-offset)))) (defun rust-rewind-to-beginning-of-current-level-expr () (let ((current-level (rust-paren-level))) @@ -108,9 +108,9 @@ ;; the inside of it correctly relative to the outside. (if (= 0 level) 0 - (or - (when rust-indent-method-chain - (rust-align-to-method-chain)) + (or + (when rust-indent-method-chain + (rust-align-to-method-chain)) (save-excursion (backward-up-list) (rust-rewind-to-beginning-of-current-level-expr) @@ -126,16 +126,16 @@ ;; A closing brace is 1 level unindended ((looking-at "}") (- baseline rust-indent-offset)) - ;;Line up method chains by their .'s - ((when (and rust-indent-method-chain - (looking-at "\..+\(.*\);?\n")) - (or - (let ((method-indent (rust-align-to-method-chain))) - (when method-indent - (+ method-indent rust-indent-offset))) - (+ baseline rust-indent-offset)))) + ;;Line up method chains by their .'s + ((when (and rust-indent-method-chain + (looking-at "\..+\(.*\);?\n")) + (or + (let ((method-indent (rust-align-to-method-chain))) + (when method-indent + (+ method-indent rust-indent-offset))) + (+ baseline rust-indent-offset)))) - + ;; Doc comments in /** style with leading * indent to line up the *s ((and (nth 4 (syntax-ppss)) (looking-at "*")) (+ 1 baseline))