From ab89e9f9a594c30ce4c04e6d502bee3beaefe908 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Wed, 6 Mar 2013 22:56:29 +0400 Subject: [PATCH] * lisp/progmodes/ruby-mode.el (ruby-syntax-propertize-function): Only propertize regexp when not inside a string. Fixes: debbugs:13885 --- lisp/ChangeLog | 5 +++++ lisp/progmodes/ruby-mode.el | 6 ++++-- test/automated/ruby-mode-tests.el | 17 +++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 18242539cca..cef47715dc0 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2013-03-06 Dmitry Gutov + + * progmodes/ruby-mode.el (ruby-syntax-propertize-function): Only + propertize regexp when not inside a string (Bug#13885). + 2013-03-06 Alan Mackenzie Correct the position of point in some line-up functions. diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 9b007c0063a..6e471d1aa2a 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -1276,8 +1276,10 @@ It will be properly highlighted even when the call omits parens.")) "\\)\\s *" ;; The regular expression itself. "\\(/\\)[^/\n\\\\]*\\(?:\\\\.[^/\n\\\\]*\\)*\\(/\\)") - (2 (string-to-syntax "\"/")) - (3 (string-to-syntax "\"/"))) + (3 (unless (nth 3 (syntax-ppss (match-beginning 2))) + (put-text-property (match-beginning 2) (match-end 2) + 'syntax-table (string-to-syntax "\"/")) + (string-to-syntax "\"/")))) ("^=en\\(d\\)\\_>" (1 "!")) ("^\\(=\\)begin\\_>" (1 "!")) ;; Handle here documents. diff --git a/test/automated/ruby-mode-tests.el b/test/automated/ruby-mode-tests.el index c67f92e6ed9..81bae187218 100644 --- a/test/automated/ruby-mode-tests.el +++ b/test/automated/ruby-mode-tests.el @@ -47,17 +47,16 @@ The whitespace before and including \"|\" on each line is removed." (defun ruby-test-string (s &rest args) (apply 'format (replace-regexp-in-string "^[ \t]*|" "" s) args)) -(defun ruby-assert-state (content &rest values-plist) +(defun ruby-assert-state (content index value &optional point) "Assert syntax state values at the end of CONTENT. VALUES-PLIST is a list with alternating index and value elements." (ruby-with-temp-buffer content + (when point (goto-char point)) (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))))) + (should (eq (nth index + (parse-partial-sexp (point-min) (point))) + value)))) (defun ruby-assert-face (content pos face) (ruby-with-temp-buffer content @@ -104,6 +103,12 @@ VALUES-PLIST is a list with alternating index and value elements." (ruby-should-indent "a = %w[abc\n def]\n " 0) (ruby-should-indent "a = \"abc\n def\"\n " 0)) +(ert-deftest ruby-regexp-doest-start-in-string () + (ruby-assert-state "'(/', /\d+/" 3 nil)) + +(ert-deftest ruby-regexp-starts-after-string () + (ruby-assert-state "'(/', /\d+/" 3 ?/ 8)) + (ert-deftest ruby-indent-simple () (ruby-should-indent-buffer "if foo -- 2.39.2