From 3d42b9689949b927cd5e8e5d42ad96149abf5c45 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sat, 2 Nov 2013 09:18:11 +0400 Subject: [PATCH] * lisp/progmodes/ruby-mode.el (ruby-smie--rule-parent-skip-assign): New function, replacement for `smie-rule-parent' for when we want to skip over our direct parent if it's an assignment token.. (ruby-smie-rules): Use it. --- lisp/ChangeLog | 7 +++++++ lisp/progmodes/ruby-mode.el | 14 ++++++++++++-- test/indent/ruby.rb | 8 ++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3de7afba477..c334d2e8c3c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2013-11-02 Dmitry Gutov + + * progmodes/ruby-mode.el (ruby-smie--rule-parent-skip-assign): New + function, replacement for `smie-rule-parent' for when we want to + skip over our direct parent if it's an assignment token.. + (ruby-smie-rules): Use it. + 2013-11-02 Dmitry Gutov * progmodes/ruby-mode.el Use `syntax-propertize-function' diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 75c59ebe1fd..36aa8eeae96 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -467,6 +467,16 @@ explicitly declared in magic comment." (t ";"))) (t tok))))))) +(defun ruby-smie--rule-parent-skip-assign () + (let* ((parent (smie-indent--parent)) + (tok (caddr parent))) + (if (and (stringp tok) (string-match-p "[+-*&|^]?=\\'" tok)) + (progn + (goto-char (cadr parent)) + (let (smie--parent) + (smie-rule-parent))) + (smie-rule-parent)))) + (defun ruby-smie-rules (kind token) (pcase (cons kind token) (`(:elem . basic) ruby-indent-level) @@ -489,7 +499,7 @@ explicitly declared in magic comment." ((and (equal token "{") (not (smie-rule-prev-p "(" "{" "[" "," "=>" "=" "return" ";"))) ;; Curly block opener. - (smie-rule-parent)) + (ruby-smie--rule-parent-skip-assign)) ((smie-rule-hanging-p) ;; Treat purely syntactic block-constructs as being part of their parent, ;; when the opening statement is hanging. @@ -498,7 +508,7 @@ explicitly declared in magic comment." (cons 'column (smie-indent-virtual))))) (`(:after . ,(or "=" "iuwu-mod")) 2) (`(:after . " @ ") (smie-rule-parent)) - (`(:before . "do") (smie-rule-parent)) + (`(:before . "do") (ruby-smie--rule-parent-skip-assign)) (`(,(or :before :after) . ".") (unless (smie-rule-parent-p ".") (smie-rule-parent ruby-indent-level))) diff --git a/test/indent/ruby.rb b/test/indent/ruby.rb index 633b2991d5e..65c33bb3ecf 100644 --- a/test/indent/ruby.rb +++ b/test/indent/ruby.rb @@ -225,6 +225,14 @@ tee = if foo bar end +a = b { + c +} + +aa = bb do + cc +end + # Examples below still fail with `ruby-use-smie' on: foo = [1, 2, 3].map do |i| -- 2.39.2