unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#12169: [PATCH] Merge changes from upstream ruby-mode
@ 2012-08-10  0:36 Dmitry Gutov
       [not found] ` <handler.12169.B.13445594689259.ack@debbugs.gnu.org>
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Dmitry Gutov @ 2012-08-10  0:36 UTC (permalink / raw)
  To: 12169

[-- Attachment #1: Type: text/plain, Size: 214 bytes --]

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

[-- Attachment #2: ruby-upstream-1.diff --]
[-- Type: text/plain, Size: 7666 bytes --]

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  <dgutov@yandex.ru>
+
+	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  <schwab@linux-m68k.org>
 
 	* 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  <dgutov@yandex.ru>
+
+	* automated/ruby-mode-tests.el (ruby-should-indent)
+	(ruby-assert-state): New functions.
+	Add new tests.
+
 2012-07-29  David Engster  <deng@randomsample.de>
 
 	* 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 <<asd\n" 3 ?\n)
+  (ruby-assert-state "class <<asd\n" 3 nil))
 
 (provide 'ruby-mode-tests)
 

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-08-12 22:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-10  0:36 bug#12169: [PATCH] Merge changes from upstream ruby-mode Dmitry Gutov
     [not found] ` <handler.12169.B.13445594689259.ack@debbugs.gnu.org>
2012-08-10 14:52   ` bug#12169: Acknowledgement ([PATCH] Merge changes from upstream ruby-mode) Dmitry Gutov
2012-08-10 15:54 ` bug#12169: [PATCH] Merge changes from upstream ruby-mode Glenn Morris
2012-08-10 20:28 ` Stefan Monnier
2012-08-10 22:15   ` Dmitry Gutov
2012-08-10 23:06     ` Dmitry Gutov
2012-08-12 22:09     ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).