aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2013-10-09 06:18:01 +0300
committerDmitry Gutov2013-10-09 06:18:01 +0300
commit238150c8ff55ab6d74f0fdcc7f163c8ee98c3749 (patch)
treec349bb1dd0dca3f33983368d1aeb93b539d67532
parentb0949cc4c9edcfea541ad72ee5e7579fac7466e1 (diff)
downloademacs-238150c8ff55ab6d74f0fdcc7f163c8ee98c3749.tar.gz
emacs-238150c8ff55ab6d74f0fdcc7f163c8ee98c3749.zip
* lisp/progmodes/ruby-mode.el (ruby-smie-rules): Indent after hanging
iuwu-mod token. (ruby-smie--implicit-semi-p): Prohibit implicit semicolon after hanging iuwu-mod token. (ruby-smie--forward-token): Do not include a dot after a token in that token. (ruby-smie--backward-token): Likewise.
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/progmodes/ruby-mode.el13
-rw-r--r--test/automated/ruby-mode-tests.el7
-rw-r--r--test/indent/ruby.rb8
4 files changed, 29 insertions, 9 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 14d7b4f344c..73bf12dfb4b 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
12013-10-09 Dmitry Gutov <dgutov@yandex.ru>
2
3 * progmodes/ruby-mode.el (ruby-smie-rules): Indent after hanging
4 iuwu-mod token.
5 (ruby-smie--implicit-semi-p): Prohibit implicit semicolon after
6 hanging iuwu-mod token.
7 (ruby-smie--forward-token): Do not include a dot after a token in
8 that token.
9 (ruby-smie--backward-token): Likewise.
10
12013-10-08 Juri Linkov <juri@jurta.org> 112013-10-08 Juri Linkov <juri@jurta.org>
2 12
3 * isearch.el (isearch-help-map, isearch-mode-map): Don't bind [t] 13 * isearch.el (isearch-help-map, isearch-mode-map): Don't bind [t]
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index b34143dea17..f734dc50e47 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -296,6 +296,9 @@ Also ignores spaces after parenthesis when 'space."
296 (let ((tok (save-excursion (ruby-smie--backward-token)))) 296 (let ((tok (save-excursion (ruby-smie--backward-token))))
297 (or (equal tok "?") 297 (or (equal tok "?")
298 (string-match "\\`\\s." tok)))) 298 (string-match "\\`\\s." tok))))
299 (and (eq (car (syntax-after (1- (point)))) 2)
300 (equal (save-excursion (ruby-smie--backward-token))
301 "iuwu-mod"))
299 (save-excursion 302 (save-excursion
300 (forward-comment 1) 303 (forward-comment 1)
301 (eq (char-after) ?.)))))) 304 (eq (char-after) ?.))))))
@@ -334,9 +337,6 @@ Also ignores spaces after parenthesis when 'space."
334 (if (looking-at ":\\s.+") 337 (if (looking-at ":\\s.+")
335 (progn (goto-char (match-end 0)) (match-string 0)) ;; bug#15208. 338 (progn (goto-char (match-end 0)) (match-string 0)) ;; bug#15208.
336 (let ((tok (smie-default-forward-token))) 339 (let ((tok (smie-default-forward-token)))
337 (when (eq ?. (char-after))
338 (forward-char 1)
339 (setq tok (concat tok "." (ruby-smie--forward-id))))
340 (cond 340 (cond
341 ((member tok '("unless" "if" "while" "until")) 341 ((member tok '("unless" "if" "while" "until"))
342 (if (save-excursion (forward-word -1) (ruby-smie--bosp)) 342 (if (save-excursion (forward-word -1) (ruby-smie--bosp))
@@ -375,7 +375,7 @@ Also ignores spaces after parenthesis when 'space."
375 (let ((tok (smie-default-backward-token))) 375 (let ((tok (smie-default-backward-token)))
376 (when (eq ?. (char-before)) 376 (when (eq ?. (char-before))
377 (forward-char -1) 377 (forward-char -1)
378 (setq tok (concat (ruby-smie--backward-id) "." tok))) 378 (setq tok (concat "." tok)))
379 (when (and (eq ?: (char-before)) (string-match "\\`\\s." tok)) 379 (when (and (eq ?: (char-before)) (string-match "\\`\\s." tok))
380 (forward-char -1) (setq tok (concat ":" tok))) ;; bug#15208. 380 (forward-char -1) (setq tok (concat ":" tok))) ;; bug#15208.
381 (cond 381 (cond
@@ -394,6 +394,9 @@ Also ignores spaces after parenthesis when 'space."
394 (line-end-position)) 394 (line-end-position))
395 (ruby-smie--backward-token)) ;Fully redundant. 395 (ruby-smie--backward-token)) ;Fully redundant.
396 (t ";"))) 396 (t ";")))
397 ;; FIXME: We shouldn't merge the dot with preceding token here
398 ;; either, but not doing that breaks indentation of hanging
399 ;; method calls with dot on the first line.
397 ((equal tok ".") 400 ((equal tok ".")
398 (concat (ruby-smie--backward-id) tok)) 401 (concat (ruby-smie--backward-id) tok))
399 (t tok))))))) 402 (t tok)))))))
@@ -419,7 +422,7 @@ Also ignores spaces after parenthesis when 'space."
419 ;; when the opening statement is hanging. 422 ;; when the opening statement is hanging.
420 (when (smie-rule-hanging-p) 423 (when (smie-rule-hanging-p)
421 (smie-backward-sexp 'halfsexp) (smie-indent-virtual))) 424 (smie-backward-sexp 'halfsexp) (smie-indent-virtual)))
422 (`(:after . "=") 2) 425 (`(:after . ,(or "=" "iuwu-mod")) 2)
423 (`(:before . "do") 426 (`(:before . "do")
424 (when (or (smie-rule-hanging-p) 427 (when (or (smie-rule-hanging-p)
425 (save-excursion 428 (save-excursion
diff --git a/test/automated/ruby-mode-tests.el b/test/automated/ruby-mode-tests.el
index 861ab9b6125..86b123f9b14 100644
--- a/test/automated/ruby-mode-tests.el
+++ b/test/automated/ruby-mode-tests.el
@@ -594,6 +594,9 @@ VALUES-PLIST is a list with alternating index and value elements."
594 | def foo 594 | def foo
595 | self.end 595 | self.end
596 | D.new.class 596 | D.new.class
597 | [1, 2, 3].map do |i|
598 | i + 1
599 | end.sum
597 | end 600 | end
598 |end")) 601 |end"))
599 602
@@ -601,11 +604,11 @@ VALUES-PLIST is a list with alternating index and value elements."
601 (ruby-with-temp-buffer ruby-sexp-test-example 604 (ruby-with-temp-buffer ruby-sexp-test-example
602 (goto-line 2) 605 (goto-line 2)
603 (ruby-forward-sexp) 606 (ruby-forward-sexp)
604 (should (= 5 (line-number-at-pos))))) 607 (should (= 8 (line-number-at-pos)))))
605 608
606(ert-deftest ruby-backward-sexp-skips-method-calls-with-keyword-names () 609(ert-deftest ruby-backward-sexp-skips-method-calls-with-keyword-names ()
607 (ruby-with-temp-buffer ruby-sexp-test-example 610 (ruby-with-temp-buffer ruby-sexp-test-example
608 (goto-line 5) 611 (goto-line 8)
609 (end-of-line) 612 (end-of-line)
610 (ruby-backward-sexp) 613 (ruby-backward-sexp)
611 (should (= 2 (line-number-at-pos))))) 614 (should (= 2 (line-number-at-pos)))))
diff --git a/test/indent/ruby.rb b/test/indent/ruby.rb
index 2b2b95bf47b..48275ee3e31 100644
--- a/test/indent/ruby.rb
+++ b/test/indent/ruby.rb
@@ -148,10 +148,14 @@ z = {
148 } 148 }
149} 149}
150 150
151foo if
152 bar
153
151# Examples below still fail with `ruby-use-smie' on: 154# Examples below still fail with `ruby-use-smie' on:
152 155
153foo + 156foo +
154 bar 157 bar
155 158
156foo if 159foo = [1, 2, 3].map do |i|
157 bar 160 i + 1
161end