diff options
| author | Daniel Raloff <draloff@side2.com> | 2014-12-16 00:43:57 -0800 |
|---|---|---|
| committer | Daniel Raloff <draloff@side2.com> | 2014-12-16 00:43:57 -0800 |
| commit | 2a81393b29fc0b133056d8a8c3cd8d0221fa7def (patch) | |
| tree | 1f0356ef806431fae1ba5cb8b10bd7466c0a4d61 /rust-mode.el | |
| parent | 079f0c2e36a6f7b25b3c2a0d9d64a0ef6e1816c4 (diff) | |
| download | rust-mode-2a81393b29fc0b133056d8a8c3cd8d0221fa7def.tar.gz | |
added optional method chain indentations for emacs major mode
Diffstat (limited to 'rust-mode.el')
| -rw-r--r-- | rust-mode.el | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/rust-mode.el b/rust-mode.el index 6917e9e..f66df6c 100644 --- a/rust-mode.el +++ b/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)) |
