diff options
| author | Dmitry Gutov | 2013-10-21 07:50:06 +0400 |
|---|---|---|
| committer | Dmitry Gutov | 2013-10-21 07:50:06 +0400 |
| commit | 8c1ae48154e4c6935da3120362ea535f0dddfec5 (patch) | |
| tree | d8c450d065eeb0820bbcd4ddd7f9233b73a1af69 | |
| parent | a9f8deecce02a4acdb5259297878799b69d56a21 (diff) | |
| download | emacs-8c1ae48154e4c6935da3120362ea535f0dddfec5.tar.gz emacs-8c1ae48154e4c6935da3120362ea535f0dddfec5.zip | |
* lisp/progmodes/ruby-mode.el (ruby-mode-map): Add binding for
`smie-down-list'.
(ruby-smie--args-separator-p): Check that there's no newline
between method call and its arguments.
(ruby-smie-rules): Handle new cases: curly block with and without
parameters, hash surrounded with parens, block passed to
paren-less method call.
* test/indent/ruby.rb: New examples for indentation of blocks. Example
of hash inside parens that inflooped before this commit.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/progmodes/ruby-mode.el | 47 | ||||
| -rw-r--r-- | test/ChangeLog | 5 | ||||
| -rw-r--r-- | test/indent/ruby.rb | 25 |
4 files changed, 63 insertions, 21 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ecb5ef0e70e..c57ac41171c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2013-10-21 Dmitry Gutov <dgutov@yandex.ru> | ||
| 2 | |||
| 3 | * progmodes/ruby-mode.el (ruby-mode-map): Add binding for | ||
| 4 | `smie-down-list'. | ||
| 5 | (ruby-smie--args-separator-p): Check that there's no newline | ||
| 6 | between method call and its arguments. | ||
| 7 | |||
| 1 | 2013-10-20 Alan Mackenzie <acm@muc.de> | 8 | 2013-10-20 Alan Mackenzie <acm@muc.de> |
| 2 | 9 | ||
| 3 | Allow comma separated lists after Java "implements". | 10 | Allow comma separated lists after Java "implements". |
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index a29540ad3a3..6abc525f705 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el | |||
| @@ -152,6 +152,8 @@ This should only be called after matching against `ruby-here-doc-beg-re'." | |||
| 152 | (define-key map (kbd "M-C-b") 'ruby-backward-sexp) | 152 | (define-key map (kbd "M-C-b") 'ruby-backward-sexp) |
| 153 | (define-key map (kbd "M-C-f") 'ruby-forward-sexp) | 153 | (define-key map (kbd "M-C-f") 'ruby-forward-sexp) |
| 154 | (define-key map (kbd "M-C-q") 'ruby-indent-exp)) | 154 | (define-key map (kbd "M-C-q") 'ruby-indent-exp)) |
| 155 | (when ruby-use-smie | ||
| 156 | (define-key map (kbd "M-C-d") 'smie-down-list)) | ||
| 155 | (define-key map (kbd "M-C-p") 'ruby-beginning-of-block) | 157 | (define-key map (kbd "M-C-p") 'ruby-beginning-of-block) |
| 156 | (define-key map (kbd "M-C-n") 'ruby-end-of-block) | 158 | (define-key map (kbd "M-C-n") 'ruby-end-of-block) |
| 157 | (define-key map (kbd "C-c {") 'ruby-toggle-block) | 159 | (define-key map (kbd "C-c {") 'ruby-toggle-block) |
| @@ -327,10 +329,10 @@ explicitly declared in magic comment." | |||
| 327 | 329 | ||
| 328 | (defun ruby-smie--args-separator-p (pos) | 330 | (defun ruby-smie--args-separator-p (pos) |
| 329 | (and | 331 | (and |
| 332 | (< pos (line-end-position)) | ||
| 330 | (or (eq (char-syntax (preceding-char)) '?w) | 333 | (or (eq (char-syntax (preceding-char)) '?w) |
| 331 | (and (memq (preceding-char) '(?! ??)) | 334 | (and (memq (preceding-char) '(?! ??)) |
| 332 | (eq (char-syntax (char-before (1- (point)))) '?w))) | 335 | (eq (char-syntax (char-before (1- (point)))) '?w))) |
| 333 | (< pos (point-max)) | ||
| 334 | (memq (char-syntax (char-after pos)) '(?w ?\")))) | 336 | (memq (char-syntax (char-after pos)) '(?w ?\")))) |
| 335 | 337 | ||
| 336 | (defun ruby-smie--forward-id () | 338 | (defun ruby-smie--forward-id () |
| @@ -440,20 +442,39 @@ explicitly declared in magic comment." | |||
| 440 | (`(:elem . args) (if (looking-at "\\s\"") 0)) | 442 | (`(:elem . args) (if (looking-at "\\s\"") 0)) |
| 441 | ;; (`(:after . ",") (smie-rule-separator kind)) | 443 | ;; (`(:after . ",") (smie-rule-separator kind)) |
| 442 | (`(:after . ";") | 444 | (`(:after . ";") |
| 443 | (if (smie-rule-parent-p "def" "begin" "do" "class" "module" "for" | 445 | (cond |
| 444 | "while" "until" "unless" | 446 | ((smie-rule-parent-p "def" "begin" "do" "class" "module" "for" |
| 445 | "if" "then" "elsif" "else" "when" | 447 | "while" "until" "unless" |
| 446 | "rescue" "ensure") | 448 | "if" "then" "elsif" "else" "when" |
| 447 | (smie-rule-parent ruby-indent-level) | 449 | "rescue" "ensure") |
| 448 | ;; For (invalid) code between switch and case. | 450 | (smie-rule-parent ruby-indent-level)) |
| 449 | ;; (if (smie-parent-p "switch") 4) | 451 | ((and (smie-rule-parent-p "{") |
| 450 | 0)) | 452 | (save-excursion |
| 453 | (goto-char (1+ (cadr (smie-indent--parent)))) | ||
| 454 | (ruby-smie--opening-pipe-p) | ||
| 455 | (forward-char -1) | ||
| 456 | ;; Can't delegate to `smie-rule-parent' because it | ||
| 457 | ;; short-circuits to `current-column' when the parent | ||
| 458 | ;; token is of paren syntax class and not hanging. | ||
| 459 | (cons 'column (+ (smie-indent-virtual) | ||
| 460 | ruby-indent-level))))) | ||
| 461 | ;; For (invalid) code between switch and case. | ||
| 462 | ;; (if (smie-parent-p "switch") 4) | ||
| 463 | (t 0))) | ||
| 451 | (`(:before . ,(or `"(" `"[" `"{")) | 464 | (`(:before . ,(or `"(" `"[" `"{")) |
| 452 | ;; Treat purely syntactic block-constructs as being part of their parent, | 465 | (cond |
| 453 | ;; when the opening statement is hanging. | 466 | ((and (equal token "{") |
| 454 | (when (smie-rule-hanging-p) | 467 | (not (smie-rule-prev-p "(" "{" "[" "," "=>"))) |
| 455 | (smie-backward-sexp 'halfsexp) (smie-indent-virtual))) | 468 | ;; Curly block opener. |
| 469 | (smie-rule-parent)) | ||
| 470 | ((smie-rule-hanging-p) | ||
| 471 | ;; Treat purely syntactic block-constructs as being part of their parent, | ||
| 472 | ;; when the opening statement is hanging. | ||
| 473 | (let ((state (smie-backward-sexp 'halfsexp))) | ||
| 474 | (when (eq t (car state)) (goto-char (cadr state)))) | ||
| 475 | (cons 'column (smie-indent-virtual))))) | ||
| 456 | (`(:after . ,(or "=" "iuwu-mod")) 2) | 476 | (`(:after . ,(or "=" "iuwu-mod")) 2) |
| 477 | (`(:after . " @ ") (smie-rule-parent)) | ||
| 457 | (`(:before . "do") (smie-rule-parent)) | 478 | (`(:before . "do") (smie-rule-parent)) |
| 458 | (`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure")) 0) | 479 | (`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure")) 0) |
| 459 | (`(:before . ,(or `"when")) | 480 | (`(:before . ,(or `"when")) |
diff --git a/test/ChangeLog b/test/ChangeLog index 9a8a61eb062..609a4e2d007 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2013-10-21 Dmitry Gutov <dgutov@yandex.ru> | ||
| 2 | |||
| 3 | * indent/ruby.rb: New examples for indentation of blocks. Example | ||
| 4 | of hash inside parens that inflooped before the present commit. | ||
| 5 | |||
| 1 | 2013-10-17 Barry O'Reilly <gundaetiapo@gmail.com> | 6 | 2013-10-17 Barry O'Reilly <gundaetiapo@gmail.com> |
| 2 | 7 | ||
| 3 | * test/automated/timer-tests.el: New file. Tests that (sit-for 0) | 8 | * test/automated/timer-tests.el: New file. Tests that (sit-for 0) |
diff --git a/test/indent/ruby.rb b/test/indent/ruby.rb index ef89ebc1aa7..56966ebb8c0 100644 --- a/test/indent/ruby.rb +++ b/test/indent/ruby.rb | |||
| @@ -40,6 +40,11 @@ foo = { # ruby-deep-indent-disabled | |||
| 40 | a: b | 40 | a: b |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | foo({ | ||
| 44 | a: b, | ||
| 45 | c: d | ||
| 46 | }) | ||
| 47 | |||
| 43 | foo = [ # ruby-deep-indent-disabled | 48 | foo = [ # ruby-deep-indent-disabled |
| 44 | 1 | 49 | 1 |
| 45 | ] | 50 | ] |
| @@ -165,6 +170,18 @@ method? arg1, | |||
| 165 | method! arg1, | 170 | method! arg1, |
| 166 | arg2 | 171 | arg2 |
| 167 | 172 | ||
| 173 | it "is a method call with block" do |asd| | ||
| 174 | foo | ||
| 175 | end | ||
| 176 | |||
| 177 | it("is too!") { | ||
| 178 | bar | ||
| 179 | } | ||
| 180 | |||
| 181 | and_this_one(has) { |block, parameters| | ||
| 182 | tee | ||
| 183 | } | ||
| 184 | |||
| 168 | # Examples below still fail with `ruby-use-smie' on: | 185 | # Examples below still fail with `ruby-use-smie' on: |
| 169 | 186 | ||
| 170 | foo + | 187 | foo + |
| @@ -192,11 +209,3 @@ method :foo, | |||
| 192 | 209 | ||
| 193 | method (a + b), | 210 | method (a + b), |
| 194 | c | 211 | c |
| 195 | |||
| 196 | it "is a method call with block" do | ||
| 197 | foo | ||
| 198 | end | ||
| 199 | |||
| 200 | it("is too!") { | ||
| 201 | bar | ||
| 202 | } | ||