From 650fa7bfb4143c3f6f46939982ae7e8f69e806f7 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sat, 12 Oct 2013 16:40:50 -0400 Subject: [PATCH] * lisp/progmodes/ruby-mode.el (ruby-smie-grammar): Add rule for paren-free method calls (bug#bug#15594). (ruby-smie--args-separator-p): New function. (ruby-smie--forward-token, ruby-smie--backward-token): Use it to recognize paren-free method calls. --- lisp/ChangeLog | 6 +++ lisp/progmodes/ruby-mode.el | 81 +++++++++++++++++++++++-------------- test/indent/ruby.rb | 4 ++ 3 files changed, 61 insertions(+), 30 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 20271be89b0..380b48adafc 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,11 @@ 2013-10-12 Stefan Monnier + * progmodes/ruby-mode.el (ruby-smie-grammar): Add rule for paren-free + method calls (bug#bug#15594). + (ruby-smie--args-separator-p): New function. + (ruby-smie--forward-token, ruby-smie--backward-token): Use it to + recognize paren-free method calls. + * isearch.el (isearch-pre-command-hook): Don't build in knowledge about internals of universal-argument. diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 2f922162586..dfc93a21b40 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -246,7 +246,8 @@ Also ignores spaces after parenthesis when 'space." '((id) (insts (inst) (insts ";" insts)) (inst (exp) (inst "iuwu-mod" exp)) - (exp (exp1) (exp "," exp) (exp "=" exp) (exp "-" exp) (exp "+" exp)) + (exp (exp1) (exp "," exp) (exp "=" exp) (exp "-" exp) (exp "+" exp) + (id " @ " exp)) (exp1 (exp2) (exp2 "?" exp1 ":" exp1)) (exp2 ("def" insts "end") ("begin" insts-rescue-insts "end") @@ -274,7 +275,8 @@ Also ignores spaces after parenthesis when 'space." (itheni (insts) (exp "then" insts)) (ielsei (itheni) (itheni "else" insts)) (if-body (ielsei) (if-body "elsif" if-body))) - '((nonassoc "in") (assoc ";") (assoc ",") (right "=") (assoc "-" "+")) + '((nonassoc "in") (assoc ";") (right " @ ") + (assoc ",") (right "=") (assoc "-" "+")) '((assoc "when")) '((assoc "elsif")) '((assoc "rescue" "ensure")) @@ -316,6 +318,12 @@ Also ignores spaces after parenthesis when 'space." (or (eq ?\{ (char-before)) (looking-back "\\_ (save-excursion (forward-comment (point-max)) (point)) - (line-end-position)) - (ruby-smie--forward-token)) ;Fully redundant. - (t ";"))) - ((equal tok ".") (concat tok (ruby-smie--forward-id))) - (t tok))))))) + ((member tok '("unless" "if" "while" "until")) + (if (save-excursion (forward-word -1) (ruby-smie--bosp)) + tok "iuwu-mod")) + ((equal tok "|") + (if (ruby-smie--opening-pipe-p) "opening-|" tok)) + ((and (equal tok "") (looking-at "\\\\\n")) + (goto-char (match-end 0)) (ruby-smie--forward-token)) + ((equal tok "do") + (cond + ((not (ruby-smie--redundant-do-p 'skip)) tok) + ((> (save-excursion (forward-comment (point-max)) (point)) + (line-end-position)) + (ruby-smie--forward-token)) ;Fully redundant. + (t ";"))) + ((equal tok ".") (concat tok (ruby-smie--forward-id))) + (t tok))))))))) (defun ruby-smie--backward-id () (when (and (not (bobp)) @@ -372,6 +387,12 @@ Also ignores spaces after parenthesis when 'space." ((and (> pos (line-end-position)) (ruby-smie--implicit-semi-p)) (skip-chars-forward " \t") ";") ((and (bolp) (not (bobp))) "") ;Presumably a heredoc. + ((and (> pos (point)) (not (bolp)) + (ruby-smie--args-separator-p pos)) + ;; We have "ID SPC ID", which is a method call, but it binds less tightly + ;; than commas, since a method call can also be "ID ARG1, ARG2, ARG3". + ;; In some textbooks, "e1 @ e2" is used to mean "call e1 with arg e2". + " @ ") (t (let ((tok (smie-default-backward-token))) (when (eq ?. (char-before)) diff --git a/test/indent/ruby.rb b/test/indent/ruby.rb index 287cbfd0ec4..67584c01c7a 100644 --- a/test/indent/ruby.rb +++ b/test/indent/ruby.rb @@ -170,3 +170,7 @@ foo_bar_tee(1, 2, 3) if foo && bar end + +method1 arg1, # bug#15594 + method2 arg2, + arg3 -- 2.39.2