Commit 0d9e2599 authored by Nobuyoshi Nakada's avatar Nobuyoshi Nakada Committed by Stefan Monnier

Merge from upstream ruby-mode.el

* lisp/progmodes/ruby-mode.el (ruby-mode-map): Remove unnecessary
binding for `newline'.
(ruby-move-to-block): When moving backward, stop at block opening,
not indentation.
* progmodes/ruby-mode.el (ruby-brace-to-do-end)
(ruby-do-end-to-brace, ruby-toggle-block): New functions.
* progmodes/ruby-mode.el (ruby-mode-map): Add binding for
`ruby-toggle-block'.
* test/automated/ruby-mode-tests.el (ruby-move-to-block-stops-at-opening)
(ruby-toggle-block-to-do-end, ruby-toggle-block-to-brace): New test.
parent 577d5eea
2012-08-12 Nobuyoshi Nakada <nobu@ruby-lang.org>
* progmodes/ruby-mode.el (ruby-mode-map): Remove unnecessary
binding for `newline'.
(ruby-move-to-block): When moving backward, stop at block opening,
not indentation.
* progmodes/ruby-mode.el (ruby-brace-to-do-end)
(ruby-do-end-to-brace, ruby-toggle-block): New functions.
* progmodes/ruby-mode.el (ruby-mode-map): Add binding for
`ruby-toggle-block'.
2012-08-12 Stefan Monnier <monnier@iro.umontreal.ca>
* ibuffer.el (ibuffer-do-toggle-read-only):
......@@ -40,16 +51,18 @@
2012-08-09 Dmitry Gutov <dgutov@yandex.ru>
Merge stuff from upsteam ruby-mode, part 1 (bug#12169).
* progmodes/ruby-mode.el (ruby-expr-beg, ruby-parse-partial):
?, _, and : are symbol constituents, ! is not (but kinda should be).
(ruby-syntax-propertize-heredoc): Use ruby-singleton-class-p.
(ruby-syntax-propertize-function): Adjust for changes in
`ruby-syntax-propertize-heredoc'.
2012-08-09 Nobuyoshi Nakada <nobu@ruby-lang.org>
* progmodes/ruby-mode.el (ruby-mode-map): Remove deprecated
binding (use `M-;' instead).
(ruby-expr-beg, ruby-parse-partial): ?, _, and : are symbol
constituents, ! is not (but kinda should be).
(ruby-singleton-class-p): New function.
(ruby-expr-beg, ruby-in-here-doc-p)
(ruby-syntax-propertize-heredoc): Use it.
(ruby-syntax-propertize-function): Adjust for changes in
`ruby-syntax-propertize-heredoc'.
(ruby-expr-beg, ruby-in-here-doc-p) Use it.
2012-08-10 Stefan Monnier <monnier@iro.umontreal.ca>
......
......@@ -150,7 +150,7 @@ This should only be called after matching against `ruby-here-doc-beg-re'."
(define-key map (kbd "M-C-q") 'ruby-indent-exp)
(define-key map (kbd "C-M-h") 'backward-kill-word)
(define-key map (kbd "C-j") 'reindent-then-newline-and-indent)
(define-key map (kbd "C-m") 'newline)
(define-key map (kbd "C-c {") 'ruby-toggle-block)
map)
"Keymap used in Ruby mode.")
......@@ -881,10 +881,11 @@ or blocks containing the current block."
;; TODO: Make this work for n > 1,
;; make it not loop for n = 0,
;; document body
(let (start pos done down)
(setq start (ruby-calculate-indent))
(setq down (looking-at (if (< n 0) ruby-block-end-re
(concat "\\<\\(" ruby-block-beg-re "\\)\\>"))))
(let ((orig (point))
(start (ruby-calculate-indent))
(down (looking-at (if (< n 0) ruby-block-end-re
(concat "\\<\\(" ruby-block-beg-re "\\)\\>"))))
pos done)
(while (and (not done) (not (if (< n 0) (bobp) (eobp))))
(forward-line n)
(cond
......@@ -907,8 +908,18 @@ or blocks containing the current block."
(save-excursion
(back-to-indentation)
(if (looking-at (concat "\\<\\(" ruby-block-mid-re "\\)\\>"))
(setq done nil))))))
(back-to-indentation))
(setq done nil)))))
(back-to-indentation)
(when (< n 0)
(let ((eol (point-at-eol)) state next)
(if (< orig eol) (setq eol orig))
(setq orig (point))
(while (and (setq next (apply 'ruby-parse-partial eol state))
(< (point) eol))
(setq state next))
(when (cdaadr state)
(goto-char (cdaadr state)))
(backward-word)))))
(defun ruby-beginning-of-block (&optional arg)
"Move backward to the beginning of the current block.
......@@ -1116,6 +1127,47 @@ See `add-log-current-defun-function'."
(if mlist (concat mlist mname) mname)
mlist)))))
(defun ruby-brace-to-do-end ()
(when (looking-at "{")
(let ((orig (point)) (end (progn (ruby-forward-sexp) (point))))
(when (eq (char-before) ?\})
(delete-char -1)
(if (eq (char-syntax (char-before)) ?w)
(insert " "))
(insert "end")
(if (eq (char-syntax (char-after)) ?w)
(insert " "))
(goto-char orig)
(delete-char 1)
(if (eq (char-syntax (char-before)) ?w)
(insert " "))
(insert "do")
(when (looking-at "\\sw\\||")
(insert " ")
(backward-char))
t))))
(defun ruby-do-end-to-brace ()
(when (and (or (bolp)
(not (memq (char-syntax (char-before)) '(?w ?_))))
(looking-at "\\<do\\(\\s \\|$\\)"))
(let ((orig (point)) (end (progn (ruby-forward-sexp) (point))))
(backward-char 3)
(when (looking-at ruby-block-end-re)
(delete-char 3)
(insert "}")
(goto-char orig)
(delete-char 2)
(insert "{")
(if (looking-at "\\s +|")
(delete-char (- (match-end 0) (match-beginning 0) 1)))
t))))
(defun ruby-toggle-block ()
(interactive)
(or (ruby-brace-to-do-end)
(ruby-do-end-to-brace)))
(declare-function ruby-syntax-propertize-heredoc "ruby-mode" (limit))
(declare-function ruby-syntax-general-delimiters-goto-beg "ruby-mode" ())
(declare-function ruby-syntax-propertize-general-delimiters "ruby-mode" (limit))
......
2012-08-12 Dmitry Gutov <dgutov@yandex.ru>
* automated/ruby-mode-tests.el (ruby-move-to-block-stops-at-opening)
(ruby-toggle-block-to-do-end, ruby-toggle-block-to-brace): New test.
2012-08-11 Glenn Morris <rgm@gnu.org>
* automated/files.el: New file.
......@@ -12,6 +17,10 @@
Add tests for `ruby-deep-indent-paren' behavior.
Port all tests from test/misc/test_ruby_mode.rb in Ruby repo.
2012-08-10 Nobuyoshi Nakada <nobu@ruby-lang.org>
Original tests in test_ruby_mode.rb in upstream (author).
2012-08-09 Dmitry Gutov <dgutov@yandex.ru>
* automated/ruby-mode-tests.el (ruby-should-indent)
......
......@@ -191,6 +191,32 @@ VALUES-PLIST is a list with alternating index and value elements."
| end
|"))
(ert-deftest ruby-move-to-block-stops-at-opening ()
(with-temp-buffer
(insert "def f\nend")
(beginning-of-line)
(ruby-mode)
(ruby-move-to-block -1)
(should (looking-at "f$"))))
(ert-deftest ruby-toggle-block-to-do-end ()
(with-temp-buffer
(insert "foo {|b|\n}\n")
(ruby-mode)
(search-backward "{")
(ruby-toggle-block)
(should (string= "foo do |b|\nend\n" (buffer-substring-no-properties
(point-min) (point-max))))))
(ert-deftest ruby-toggle-block-to-brace ()
(with-temp-buffer
(insert "foo do |b|\nend\n")
(ruby-mode)
(search-backward "do")
(ruby-toggle-block)
(should (string= "foo {|b|\n}\n" (buffer-substring-no-properties
(point-min) (point-max))))))
(provide 'ruby-mode-tests)
;;; ruby-mode-tests.el ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment