From: Dmitry Gutov Date: Fri, 14 Dec 2012 04:55:23 +0000 (+0400) Subject: * lisp/progmodes/ruby-mode.el (ruby-syntax-propertize-function): X-Git-Tag: emacs-24.3.90~173^2~7^2~599 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=dbb530d9887fd51de9f8e338b325537d9eac0a3a;p=emacs.git * lisp/progmodes/ruby-mode.el (ruby-syntax-propertize-function): Extract `ruby-syntax-propertize-expansions'. (ruby-syntax-propertize-expansions): Only change syntax on certain string delimiters, to punctuation. This way the common functions like forward-word and thing-at-point still work. * test/automated/ruby-mode-tests.el Rename one interpolation test; add three more. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 66af3378b14..2d12a357cbf 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2012-12-14 Dmitry Gutov + + * progmodes/ruby-mode.el (ruby-syntax-propertize-function): + Extract `ruby-syntax-propertize-expansions'. + (ruby-syntax-propertize-expansions): Only change syntax on + certain string delimiters, to punctuation. This way the common + functions like forward-word and thing-at-point still work. + (ruby-match-expression-expansion): Improve readability. + 2012-12-13 Juanma Barranquero * emacs-lisp/edebug.el (edebug-unload-function): Make sure that diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 9d78b20ba4c..6b9e921be67 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -1253,18 +1253,7 @@ It will be properly highlighted even when the call omits parens.")) ((concat "\\(?:^\\|[[ \t\n<+(,=]\\)" ruby-percent-literal-beg-re) (1 (prog1 "|" (ruby-syntax-propertize-percent-literal end))))) (point) end) - (remove-text-properties start end '(ruby-expansion-match-data)) - (goto-char start) - ;; Find all expression expansions and - ;; - set the syntax of all text inside to whitespace, - ;; - save the match data to a text property, for font-locking later. - (while (re-search-forward ruby-expression-expansion-re end 'move) - (when (ruby-in-ppss-context-p 'string) - (put-text-property (match-beginning 2) (match-end 2) - 'syntax-table (string-to-syntax "-")) - (put-text-property (match-beginning 2) (1+ (match-beginning 2)) - 'ruby-expansion-match-data - (match-data))))) + (ruby-syntax-propertize-expansions start end)) (defun ruby-syntax-propertize-heredoc (limit) (let ((ppss (syntax-ppss)) @@ -1331,6 +1320,23 @@ It will be properly highlighted even when the call omits parens.")) (string-to-syntax "|"))) ;; Unclosed literal, leave the following text unpropertized. ((scan-error search-failed) (goto-char limit)))))) + + (defun ruby-syntax-propertize-expansions (start end) + (remove-text-properties start end '(ruby-expansion-match-data)) + (goto-char start) + ;; Find all expression expansions and + ;; - save the match data to a text property, for font-locking later, + ;; - set the syntax of all double quotes and backticks to puctuation. + (while (re-search-forward ruby-expression-expansion-re end 'move) + (let ((beg (match-beginning 2)) + (end (match-end 2))) + (when (and beg (save-excursion (nth 3 (syntax-ppss beg)))) + (put-text-property beg (1+ beg) 'ruby-expansion-match-data + (match-data)) + (goto-char beg) + (while (re-search-forward "[\"`]" end 'move) + (put-text-property (match-beginning 0) (match-end 0) + 'syntax-table (string-to-syntax "."))))))) ) ;; For Emacsen where syntax-propertize-rules is not (yet) available, @@ -1605,10 +1611,10 @@ See `font-lock-syntax-table'.") "Additional expressions to highlight in Ruby mode.") (defun ruby-match-expression-expansion (limit) - (let ((prop 'ruby-expansion-match-data) pos value) - (when (and (setq pos (next-single-char-property-change (point) prop - nil limit)) - (> pos (point))) + (let* ((prop 'ruby-expansion-match-data) + (pos (next-single-char-property-change (point) prop nil limit)) + value) + (when (and pos (> pos (point))) (goto-char pos) (or (and (setq value (get-text-property pos prop)) (progn (set-match-data value) t)) diff --git a/test/ChangeLog b/test/ChangeLog index 142dfcb42fd..ccebdda7411 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2012-12-14 Dmitry Gutov + + * automated/ruby-mode-tests.el + Rename one interpolation test; add three more. + 2012-12-11 Glenn Morris * automated/f90.el (f90-test-bug13138): New test. diff --git a/test/automated/ruby-mode-tests.el b/test/automated/ruby-mode-tests.el index 620fe72fb69..6ae23f94f1a 100644 --- a/test/automated/ruby-mode-tests.el +++ b/test/automated/ruby-mode-tests.el @@ -276,13 +276,33 @@ VALUES-PLIST is a list with alternating index and value elements." (ruby-assert-face "# #{comment}\n \"#{interpolation}\"" 16 font-lock-variable-name-face)) -(ert-deftest ruby-interpolation-suppresses-syntax-inside () +(ert-deftest ruby-interpolation-suppresses-quotes-inside () (let ((s "\"
  • #{@files.join(\"
  • \")}
\"")) (ruby-assert-state s 8 nil) (ruby-assert-face s 9 font-lock-string-face) (ruby-assert-face s 10 font-lock-variable-name-face) (ruby-assert-face s 41 font-lock-string-face))) +(ert-deftest ruby-interpolation-suppresses-one-double-quote () + (let ((s "\"foo#{'\"'}\"")) + (ruby-assert-state s 8 nil) + (ruby-assert-face s 8 font-lock-variable-name-face) + (ruby-assert-face s 11 font-lock-string-face))) + +(ert-deftest ruby-interpolation-suppresses-one-backtick () + (let ((s "`as#{'`'}das`")) + (ruby-assert-state s 8 nil))) + +(ert-deftest ruby-interpolation-keeps-non-quote-syntax () + (let ((s "\"foo#{baz.tee}bar\"")) + (with-temp-buffer + (save-excursion + (insert s)) + (ruby-mode) + (font-lock-fontify-buffer) + (search-forward "tee") + (should (string= (thing-at-point 'symbol) "tee"))))) + (ert-deftest ruby-interpolation-inside-percent-literal-with-paren () :expected-result :failed (let ((s "%(^#{\")\"}^)"))