From bae91342a41c1aef864c64c2354dfbfc58335bfa Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sat, 26 Oct 2013 05:16:37 +0400 Subject: [PATCH] * lisp/progmodes/ruby-mode.el (ruby-smie--args-separator-p): Be more specific in what the first arg can be: a non-keyword word, string/regexp/percent literal opener, opening paren, or unary operator followed directly by word. * test/automated/ruby-mode-tests.el (ruby-toggle-block-to-brace): Fix the test, in respect to adding the space after the curly. --- lisp/ChangeLog | 7 +++++++ lisp/progmodes/ruby-mode.el | 11 ++++++++++- test/ChangeLog | 5 +++++ test/automated/ruby-mode-tests.el | 4 ++-- test/indent/ruby.rb | 25 +++++++++++++------------ 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 82e03a48da4..e25d5bab1e1 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2013-10-26 Dmitry Gutov + + * progmodes/ruby-mode.el (ruby-smie--args-separator-p): Be more + specific in what the first arg can be: a non-keyword word, + string/regexp/percent literal opener, opening paren, or unary + operator followed directly by word. + 2013-10-25 Stefan Monnier * progmodes/prolog.el: Remove old indent; use post-self-insert-hook. diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index dbca0d4dd26..b85385a7428 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -372,9 +372,18 @@ explicitly declared in magic comment." (and (< pos (line-end-position)) (or (eq (char-syntax (preceding-char)) '?w) + ;; FIXME: Check that the preceding token is not a keyword. + ;; This isn't very important most of the time, though. (and (memq (preceding-char) '(?! ??)) (eq (char-syntax (char-before (1- (point)))) '?w))) - (memq (char-syntax (char-after pos)) '(?w ?\")))) + (or (and (eq (char-syntax (char-after pos)) ?w) + (not (looking-at (regexp-opt '("unless" "if" "while" "until" + "else" "elsif" "do" "end") + 'symbols)))) + (memq (syntax-after pos) '(7 15)) + (save-excursion + (goto-char pos) + (looking-at "\\s(\\|[-+!~:]\\sw"))))) (defun ruby-smie--at-dot-call () (and (eq ?w (char-syntax (following-char))) diff --git a/test/ChangeLog b/test/ChangeLog index 10acf187967..6572b9c46e4 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2013-10-26 Dmitry Gutov + + * automated/ruby-mode-tests.el (ruby-toggle-block-to-brace): Fix + the test, in respect to adding the space after the curly. + 2013-10-24 Michael Albinus * automated/ert-tests.el (ert-test-skip-unless): New test case. diff --git a/test/automated/ruby-mode-tests.el b/test/automated/ruby-mode-tests.el index dafe393377b..dc86b4a2914 100644 --- a/test/automated/ruby-mode-tests.el +++ b/test/automated/ruby-mode-tests.el @@ -292,8 +292,8 @@ VALUES-PLIST is a list with alternating index and value elements." (should (string= "foo do |b|\nend" (buffer-string))))) (ert-deftest ruby-toggle-block-to-brace () - (let ((pairs '((16 . "foo {|b| b + 2 }") - (15 . "foo {|b|\n b + 2\n}")))) + (let ((pairs '((17 . "foo { |b| b + 2 }") + (16 . "foo { |b|\n b + 2\n}")))) (dolist (pair pairs) (with-temp-buffer (let ((fill-column (car pair))) diff --git a/test/indent/ruby.rb b/test/indent/ruby.rb index 1fd19cf34d4..9532a4b4245 100644 --- a/test/indent/ruby.rb +++ b/test/indent/ruby.rb @@ -174,6 +174,19 @@ method? arg1, method! arg1, arg2 +method !arg1, + arg2 + +method [], + arg2 + +method :foo, + :bar + +method (a + b), + c, :d => :e, + f: g + it "is a method call with block" do |asd| foo end @@ -213,18 +226,6 @@ foo = [1, 2, 3].map do |i| i + 1 end -method !arg1, - arg2 - -method [], - arg2 - -method :foo, - :bar - -method (a + b), - c - bar.foo do # "." is parent to "do"; it shouldn't be. bar end -- 2.39.5