aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/ruby-mode.el
diff options
context:
space:
mode:
authorDmitry Gutov2012-12-14 08:55:23 +0400
committerDmitry Gutov2012-12-14 08:55:23 +0400
commitdbb530d9887fd51de9f8e338b325537d9eac0a3a (patch)
tree491ec463feca7a9993c5462a28e18e68ae70fb3c /lisp/progmodes/ruby-mode.el
parentfd1b1e2ed2efb9891ae3a709d62151a52e937bd6 (diff)
downloademacs-dbb530d9887fd51de9f8e338b325537d9eac0a3a.tar.gz
emacs-dbb530d9887fd51de9f8e338b325537d9eac0a3a.zip
* 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.
Diffstat (limited to 'lisp/progmodes/ruby-mode.el')
-rw-r--r--lisp/progmodes/ruby-mode.el38
1 files changed, 22 insertions, 16 deletions
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."))
1253 ((concat "\\(?:^\\|[[ \t\n<+(,=]\\)" ruby-percent-literal-beg-re) 1253 ((concat "\\(?:^\\|[[ \t\n<+(,=]\\)" ruby-percent-literal-beg-re)
1254 (1 (prog1 "|" (ruby-syntax-propertize-percent-literal end))))) 1254 (1 (prog1 "|" (ruby-syntax-propertize-percent-literal end)))))
1255 (point) end) 1255 (point) end)
1256 (remove-text-properties start end '(ruby-expansion-match-data)) 1256 (ruby-syntax-propertize-expansions start end))
1257 (goto-char start)
1258 ;; Find all expression expansions and
1259 ;; - set the syntax of all text inside to whitespace,
1260 ;; - save the match data to a text property, for font-locking later.
1261 (while (re-search-forward ruby-expression-expansion-re end 'move)
1262 (when (ruby-in-ppss-context-p 'string)
1263 (put-text-property (match-beginning 2) (match-end 2)
1264 'syntax-table (string-to-syntax "-"))
1265 (put-text-property (match-beginning 2) (1+ (match-beginning 2))
1266 'ruby-expansion-match-data
1267 (match-data)))))
1268 1257
1269 (defun ruby-syntax-propertize-heredoc (limit) 1258 (defun ruby-syntax-propertize-heredoc (limit)
1270 (let ((ppss (syntax-ppss)) 1259 (let ((ppss (syntax-ppss))
@@ -1331,6 +1320,23 @@ It will be properly highlighted even when the call omits parens."))
1331 (string-to-syntax "|"))) 1320 (string-to-syntax "|")))
1332 ;; Unclosed literal, leave the following text unpropertized. 1321 ;; Unclosed literal, leave the following text unpropertized.
1333 ((scan-error search-failed) (goto-char limit)))))) 1322 ((scan-error search-failed) (goto-char limit))))))
1323
1324 (defun ruby-syntax-propertize-expansions (start end)
1325 (remove-text-properties start end '(ruby-expansion-match-data))
1326 (goto-char start)
1327 ;; Find all expression expansions and
1328 ;; - save the match data to a text property, for font-locking later,
1329 ;; - set the syntax of all double quotes and backticks to puctuation.
1330 (while (re-search-forward ruby-expression-expansion-re end 'move)
1331 (let ((beg (match-beginning 2))
1332 (end (match-end 2)))
1333 (when (and beg (save-excursion (nth 3 (syntax-ppss beg))))
1334 (put-text-property beg (1+ beg) 'ruby-expansion-match-data
1335 (match-data))
1336 (goto-char beg)
1337 (while (re-search-forward "[\"`]" end 'move)
1338 (put-text-property (match-beginning 0) (match-end 0)
1339 'syntax-table (string-to-syntax ".")))))))
1334 ) 1340 )
1335 1341
1336 ;; For Emacsen where syntax-propertize-rules is not (yet) available, 1342 ;; For Emacsen where syntax-propertize-rules is not (yet) available,
@@ -1605,10 +1611,10 @@ See `font-lock-syntax-table'.")
1605 "Additional expressions to highlight in Ruby mode.") 1611 "Additional expressions to highlight in Ruby mode.")
1606 1612
1607(defun ruby-match-expression-expansion (limit) 1613(defun ruby-match-expression-expansion (limit)
1608 (let ((prop 'ruby-expansion-match-data) pos value) 1614 (let* ((prop 'ruby-expansion-match-data)
1609 (when (and (setq pos (next-single-char-property-change (point) prop 1615 (pos (next-single-char-property-change (point) prop nil limit))
1610 nil limit)) 1616 value)
1611 (> pos (point))) 1617 (when (and pos (> pos (point)))
1612 (goto-char pos) 1618 (goto-char pos)
1613 (or (and (setq value (get-text-property pos prop)) 1619 (or (and (setq value (get-text-property pos prop))
1614 (progn (set-match-data value) t)) 1620 (progn (set-match-data value) t))