[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] /srv/bzr/emacs/trunk r109558: Merge stuff from upsteam rub
From: |
Stefan Monnier |
Subject: |
[Emacs-diffs] /srv/bzr/emacs/trunk r109558: Merge stuff from upsteam ruby-mode, part 1. |
Date: |
Fri, 10 Aug 2012 16:19:09 -0400 |
User-agent: |
Bazaar (2.5.0) |
------------------------------------------------------------
revno: 109558
fixes bug: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=12169
author: Dmitry Gutov <address@hidden>
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Fri 2012-08-10 16:19:09 -0400
message:
Merge stuff from upsteam ruby-mode, part 1.
* lisp/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'.
* test/automated/ruby-mode-tests.el (ruby-should-indent)
(ruby-assert-state): New functions.
Add new tests.
modified:
lisp/ChangeLog
lisp/progmodes/ruby-mode.el
test/ChangeLog
test/automated/ruby-mode-tests.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog 2012-08-10 19:34:36 +0000
+++ b/lisp/ChangeLog 2012-08-10 20:19:09 +0000
@@ -1,3 +1,16 @@
+2012-08-09 Dmitry Gutov <address@hidden>
+
+ Merge stuff from upsteam ruby-mode, part 1 (bug#12169).
+ * 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'.
+
2012-08-10 Stefan Monnier <address@hidden>
* emacs-lisp/cl-macs.el (cl-loop): Improve debug spec.
=== modified file 'lisp/progmodes/ruby-mode.el'
--- a/lisp/progmodes/ruby-mode.el 2012-07-20 11:10:25 +0000
+++ b/lisp/progmodes/ruby-mode.el 2012-08-10 20:19:09 +0000
@@ -151,7 +151,6 @@
(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 C-c") 'comment-region)
map)
"Keymap used in Ruby mode.")
@@ -380,11 +379,19 @@
((and (eq c ?:) (or (not b) (eq (char-syntax b) ? ))))
((eq c ?\\) (eq b ??)))))
+(defun ruby-singleton-class-p (&optional pos)
+ (save-excursion
+ (when pos (goto-char pos))
+ (forward-word -1)
+ (and (or (bolp) (not (eq (char-before (point)) ?_)))
+ (looking-at "class\\s *<<"))))
+
(defun ruby-expr-beg (&optional option)
"TODO: document."
(save-excursion
(store-match-data nil)
- (let ((space (skip-chars-backward " \t")))
+ (let ((space (skip-chars-backward " \t"))
+ (start (point)))
(cond
((bolp) t)
((progn
@@ -393,7 +400,8 @@
(or (eq (char-syntax (char-before (point))) ?w)
(ruby-special-char-p))))
nil)
- ((and (eq option 'heredoc) (< space 0)) t)
+ ((and (eq option 'heredoc) (< space 0))
+ (not (progn (goto-char start) (ruby-singleton-class-p))))
((or (looking-at ruby-operator-re)
(looking-at "[\\[({,;]")
(and (looking-at "[!?]")
@@ -409,7 +417,7 @@
ruby-block-mid-keywords)
'words))
(goto-char (match-end 0))
- (not (looking-at "\\s_")))
+ (not (looking-at "\\s_\\|!")))
((eq option 'expr-qstr)
(looking-at "[a-zA-Z][a-zA-z0-9_]* +%[^ \t]"))
((eq option 'expr-re)
@@ -581,9 +589,7 @@
(eq ?. w)))))
(goto-char pnt)
(setq w (char-after (point)))
- (not (eq ?_ w))
(not (eq ?! w))
- (not (eq ?? w))
(skip-chars-forward " \t")
(goto-char (match-beginning 0))
(or (not (looking-at ruby-modifier-re))
@@ -1159,7 +1165,10 @@
("^\\(=\\)begin\\_>" (1 "!"))
;; Handle here documents.
((concat ruby-here-doc-beg-re ".*\\(\n\\)")
- (7 (prog1 "\"" (ruby-syntax-propertize-heredoc end))))
+ (7 (unless (ruby-singleton-class-p (match-beginning 0))
+ (put-text-property (match-beginning 7) (match-end 7)
+ 'syntax-table (string-to-syntax "\""))
+ (ruby-syntax-propertize-heredoc end))))
;; Handle percent literals: %w(), %q{}, etc.
("\\(?:^\\|[[ \t\n<+(,=]\\)\\(%\\)[qQrswWx]?\\([[:punct:]]\\)"
(1 (prog1 "|" (ruby-syntax-propertize-general-delimiters end)))))
@@ -1174,7 +1183,8 @@
(beginning-of-line)
(while (re-search-forward ruby-here-doc-beg-re
(line-end-position) t)
- (push (concat (ruby-here-doc-end-match) "\n") res)))
+ (unless (ruby-singleton-class-p (match-beginning 0))
+ (push (concat (ruby-here-doc-end-match) "\n") res))))
(let ((start (point)))
;; With multiple openers on the same line, we don't know in which
;; part `start' is, so we have to go back to the beginning.
@@ -1310,7 +1320,8 @@
(let ((old-point (point)) (case-fold-search nil))
(beginning-of-line)
(catch 'found-beg
- (while (re-search-backward ruby-here-doc-beg-re nil t)
+ (while (and (re-search-backward ruby-here-doc-beg-re nil t)
+ (not (ruby-singleton-class-p)))
(if (not (or (ruby-in-ppss-context-p 'anything)
(ruby-here-doc-find-end old-point)))
(throw 'found-beg t)))))))
=== modified file 'test/ChangeLog'
--- a/test/ChangeLog 2012-07-29 19:57:28 +0000
+++ b/test/ChangeLog 2012-08-10 20:19:09 +0000
@@ -1,3 +1,9 @@
+2012-08-09 Dmitry Gutov <address@hidden>
+
+ * automated/ruby-mode-tests.el (ruby-should-indent)
+ (ruby-assert-state): New functions.
+ Add new tests.
+
2012-07-29 David Engster <address@hidden>
* automated/xml-parse-tests.el (xml-parse-tests--qnames): New
=== modified file 'test/automated/ruby-mode-tests.el'
--- a/test/automated/ruby-mode-tests.el 2012-07-20 11:10:25 +0000
+++ b/test/automated/ruby-mode-tests.el 2012-08-10 20:19:09 +0000
@@ -23,16 +23,39 @@
(require 'ruby-mode)
-(ert-deftest indent-line-after-symbol-made-from-string-interpolation ()
+(defun ruby-should-indent (content column)
+ (with-temp-buffer
+ (insert content)
+ (ruby-mode)
+ (ruby-indent-line)
+ (should (= (current-column) column))))
+
+(defun ruby-assert-state (content &rest values-plist)
+ "Assert syntax state values at the end of CONTENT.
+
+VALUES-PLIST is a list with alternating index and value elements."
+ (with-temp-buffer
+ (insert content)
+ (ruby-mode)
+ (syntax-propertize (point))
+ (while values-plist
+ (should (eq (nth (car values-plist)
+ (parse-partial-sexp (point-min) (point)))
+ (cadr values-plist)))
+ (setq values-plist (cddr values-plist)))))
+
+(ert-deftest ruby-indent-after-symbol-made-from-string-interpolation ()
"It can indent the line after symbol made using string interpolation."
- (let ((initial-content "def foo(suffix)\n :\"bar#{suffix}\"\n")
- (expected-content "def foo(suffix)\n :\"bar#{suffix}\"\n "))
- (with-temp-buffer
- (insert initial-content)
- (ruby-indent-line) ; Doesn't rely on text properties or the syntax table.
- (let ((buffer-content (buffer-substring-no-properties (point-min)
- (point-max))))
- (should (string= buffer-content expected-content))))))
+ (ruby-should-indent "def foo(suffix)\n :\"bar#{suffix}\"\n"
+ ruby-indent-level))
+
+(ert-deftest ruby-indent-after-js-style-symbol-with-block-beg-name ()
+ "JS-style hash symbol can have keyword name."
+ (ruby-should-indent "link_to \"home\", home_path, class: \"foo\"\n" 0))
+
+(ert-deftest ruby-discern-singleton-class-from-heredoc ()
+ (ruby-assert-state "foo <<asd\n" 3 ?\n)
+ (ruby-assert-state "class <<asd\n" 3 nil))
(provide 'ruby-mode-tests)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] /srv/bzr/emacs/trunk r109558: Merge stuff from upsteam ruby-mode, part 1.,
Stefan Monnier <=