+2012-12-14 Dmitry Gutov <dgutov@yandex.ru>
+
+ * 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 <lekktu@gmail.com>
* emacs-lisp/edebug.el (edebug-unload-function): Make sure that
((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))
(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,
"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))
(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 "\"<ul><li>#{@files.join(\"</li><li>\")}</li></ul>\""))
(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 "%(^#{\")\"}^)"))