[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] trunk r114639: * lisp/progmodes/ruby-mode.el (ruby-smie-gr
From: |
Stefan Monnier |
Subject: |
[Emacs-diffs] trunk r114639: * lisp/progmodes/ruby-mode.el (ruby-smie-grammar): Add rule for paren-free |
Date: |
Sat, 12 Oct 2013 20:40:54 +0000 |
User-agent: |
Bazaar (2.6b2) |
------------------------------------------------------------
revno: 114639
revision-id: address@hidden
parent: address@hidden
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Sat 2013-10-12 16:40:50 -0400
message:
* 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.
modified:
lisp/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1432
lisp/progmodes/ruby-mode.el
rubymode.el-20091113204419-o5vbwnq5f7feedwu-8804
test/indent/ruby.rb ruby.rb-20120424165921-h044139hbrd7snvw-1
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog 2013-10-12 01:10:25 +0000
+++ b/lisp/ChangeLog 2013-10-12 20:40:50 +0000
@@ -1,5 +1,11 @@
2013-10-12 Stefan Monnier <address@hidden>
+ * 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.
=== modified file 'lisp/progmodes/ruby-mode.el'
--- a/lisp/progmodes/ruby-mode.el 2013-10-11 02:11:37 +0000
+++ b/lisp/progmodes/ruby-mode.el 2013-10-12 20:40:50 +0000
@@ -246,7 +246,8 @@
'((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 @@
(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 @@
(or (eq ?\{ (char-before))
(looking-back "\\_<do" (- (point) 2)))))
+(defun ruby-smie--args-separator-p (pos)
+ (and
+ (eq ?w (char-syntax (char-before)))
+ (< pos (point-max))
+ (memq (char-syntax (char-after pos)) '(?w ?\"))))
+
(defun ruby-smie--forward-id ()
(when (and (not (eobp))
(eq ?w (char-syntax (char-after))))
@@ -326,35 +334,42 @@
tok)))
(defun ruby-smie--forward-token ()
- (skip-chars-forward " \t")
- (cond
- ((looking-at "\\s\"") "") ;A heredoc or a string.
- ((and (looking-at "[\n#]")
- (ruby-smie--implicit-semi-p)) ;Only add implicit ; when needed.
- (if (eolp) (forward-char 1) (forward-comment 1))
- ";")
- (t
- (forward-comment (point-max))
- (if (looking-at ":\\s.+")
- (progn (goto-char (match-end 0)) (match-string 0)) ;; bug#15208.
- (let ((tok (smie-default-forward-token)))
- (cond
- ((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")
+ (let ((pos (point)))
+ (skip-chars-forward " \t")
+ (cond
+ ((looking-at "\\s\"") "") ;A heredoc or a string.
+ ((and (looking-at "[\n#]")
+ (ruby-smie--implicit-semi-p)) ;Only add implicit ; when needed.
+ (if (eolp) (forward-char 1) (forward-comment 1))
+ ";")
+ (t
+ (forward-comment (point-max))
+ (cond
+ ((looking-at ":\\s.+")
+ (goto-char (match-end 0)) (match-string 0)) ;; bug#15208.
+ ((and (< pos (point))
+ (save-excursion
+ (ruby-smie--args-separator-p (prog1 (point) (goto-char pos)))))
+ " @ ")
+ (t
+ (let ((tok (smie-default-forward-token)))
(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)))))))
+ ((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 @@
((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))
=== modified file 'test/indent/ruby.rb'
--- a/test/indent/ruby.rb 2013-10-11 20:45:14 +0000
+++ b/test/indent/ruby.rb 2013-10-12 20:40:50 +0000
@@ -170,3 +170,7 @@
if foo &&
bar
end
+
+method1 arg1, # bug#15594
+ method2 arg2,
+ arg3
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] trunk r114639: * lisp/progmodes/ruby-mode.el (ruby-smie-grammar): Add rule for paren-free,
Stefan Monnier <=