From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#12169: [PATCH] Merge changes from upstream ruby-mode Date: Fri, 10 Aug 2012 04:36:01 +0400 Message-ID: <50245771.6060109@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080108080604020406020602" X-Trace: dough.gmane.org 1344559022 13631 80.91.229.3 (10 Aug 2012 00:37:02 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 10 Aug 2012 00:37:02 +0000 (UTC) To: 12169@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Aug 10 02:36:56 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SzdDj-000322-TY for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 Aug 2012 02:36:56 +0200 Original-Received: from localhost ([::1]:55678 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzdDj-0004Gg-1w for geb-bug-gnu-emacs@m.gmane.org; Thu, 09 Aug 2012 20:36:55 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:39394) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzdDf-0004Gb-LD for bug-gnu-emacs@gnu.org; Thu, 09 Aug 2012 20:36:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzdDe-0005N4-6E for bug-gnu-emacs@gnu.org; Thu, 09 Aug 2012 20:36:51 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:36070) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzdDe-0005Mz-34 for bug-gnu-emacs@gnu.org; Thu, 09 Aug 2012 20:36:50 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SzdLa-0002QK-34 for bug-gnu-emacs@gnu.org; Thu, 09 Aug 2012 20:45:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 10 Aug 2012 00:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 12169 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.13445594689259 (code B ref -1); Fri, 10 Aug 2012 00:45:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 10 Aug 2012 00:44:28 +0000 Original-Received: from localhost ([127.0.0.1]:45615 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SzdL1-0002PI-5T for submit@debbugs.gnu.org; Thu, 09 Aug 2012 20:44:27 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:34933) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SzdKx-0002P9-0M for submit@debbugs.gnu.org; Thu, 09 Aug 2012 20:44:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzdCz-0004uX-72 for submit@debbugs.gnu.org; Thu, 09 Aug 2012 20:36:10 -0400 Original-Received: from lists.gnu.org ([208.118.235.17]:37021) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzdCz-0004tv-28 for submit@debbugs.gnu.org; Thu, 09 Aug 2012 20:36:09 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:39289) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzdCx-0004GJ-9O for bug-gnu-emacs@gnu.org; Thu, 09 Aug 2012 20:36:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzdCu-0004qv-LK for bug-gnu-emacs@gnu.org; Thu, 09 Aug 2012 20:36:07 -0400 Original-Received: from forward1.mail.yandex.net ([77.88.46.6]:44062) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzdCu-0004qZ-4h for bug-gnu-emacs@gnu.org; Thu, 09 Aug 2012 20:36:04 -0400 Original-Received: from smtp2.mail.yandex.net (smtp2.mail.yandex.net [77.88.46.102]) by forward1.mail.yandex.net (Yandex) with ESMTP id A7DEE1241E2B for ; Fri, 10 Aug 2012 04:35:59 +0400 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1344558959; bh=of7K7Ginc5gE50WVl0na0Gkr+YSY9JK3sgQxAET1RTI=; h=Message-ID:Date:From:MIME-Version:To:Subject:Content-Type; b=GHb+z/dPsqcKrJnpKDPTFy+HDq4JxLs1Mm/HL8WRhFhfvmRryFWBiHUW0Q38YdI2P IWEKSqavjB7YhEEbFurJEjWfzDET0uK1LvHyCvTKwFifyAMXd3ZTqwxcuAc9dlcKPv WOd4Fhf/Uu+uhhuE85McBC6sFTtfbSVIoGJzrKbM= Original-Received: from smtp2.mail.yandex.net (localhost [127.0.0.1]) by smtp2.mail.yandex.net (Yandex) with ESMTP id 954E2E205F1 for ; Fri, 10 Aug 2012 04:35:59 +0400 (MSK) Original-Received: from 98-87.nwlink.spb.ru (98-87.nwlink.spb.ru [178.252.98.87]) by smtp2.mail.yandex.net (nwsmtp/Yandex) with ESMTP id ZxJqBNHi-ZxJGSZ51; Fri, 10 Aug 2012 04:35:59 +0400 X-Yandex-Rcpt-Suid: bug-gnu-emacs@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1344558959; bh=of7K7Ginc5gE50WVl0na0Gkr+YSY9JK3sgQxAET1RTI=; h=Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type; b=TWCv07cE1nH1MATR0P41iIBF/ijc4IeJQRU5v95lC/AwQhAeGJvYD0NAFG5nr4V/o c2vwuY/lajcGRSP6XNqJUgmj6gDnYLqmYJ8n4T9s4W+zzKG6XVMWW/zVRRE2yVi/CO d3OvY1jEvPYemJyoAAlxTM2xWulP9B002sd4w1qY= User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:62984 Archived-At: This is a multi-part message in MIME format. --------------080108080604020406020602 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit This is part 1, 1 or 2 more to come. The change to `ruby-syntax-propertize-function' is kind of messy, but I don't see how to do it better without seriously rewriting `ruby-syntax-propertize-heredoc'. --Dmitry --------------080108080604020406020602 Content-Type: text/plain; charset=windows-1251; name="ruby-upstream-1.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="ruby-upstream-1.diff" diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 635456a..38379cd 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,17 @@ +2012-08-09 Dmitry Gutov + + Merge stuff from upsteam ruby-mode, part 1. + + * 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-07 Andreas Schwab * calc/calc-prog.el (math-do-defmath): Use backquote forms. Fix diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 091a7b7..68abaff 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -151,7 +151,6 @@ This should only be called after matching against `ruby-here-doc-beg-re'." (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 `\\' when preceded by `?'." ((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 @@ and `\\' when preceded by `?'." (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 @@ and `\\' when preceded by `?'." 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 @@ and `\\' when preceded by `?'." (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 @@ See `add-log-current-defun-function'." ("^\\(=\\)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 @@ See `add-log-current-defun-function'." (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 @@ isn't in a string or another comment." (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))))))) diff --git a/test/ChangeLog b/test/ChangeLog index 03d43d7..86f3019 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,9 @@ +2012-08-09 Dmitry Gutov + + * automated/ruby-mode-tests.el (ruby-should-indent) + (ruby-assert-state): New functions. + Add new tests. + 2012-07-29 David Engster * automated/xml-parse-tests.el (xml-parse-tests--qnames): New diff --git a/test/automated/ruby-mode-tests.el b/test/automated/ruby-mode-tests.el index 1a91f51..fbe1b8d 100644 --- a/test/automated/ruby-mode-tests.el +++ b/test/automated/ruby-mode-tests.el @@ -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 <