aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorDmitry Gutov2012-08-14 08:38:11 -0400
committerStefan Monnier2012-08-14 08:38:11 -0400
commitf063063a8a8bfc1ba343e7e9eb5d17f866f6fccd (patch)
tree2c68a80c0f9f14d93250ad8f5b4619eae3870f31 /lisp
parente636fafe20f0238d0aaabc4b822642efe68cad9b (diff)
downloademacs-f063063a8a8bfc1ba343e7e9eb5d17f866f6fccd.tar.gz
emacs-f063063a8a8bfc1ba343e7e9eb5d17f866f6fccd.zip
* lisp/progmodes/ruby-mode.el (ruby-syntax-methods-before-regexp): New const.
(ruby-syntax-propertize-function): Use it to recognize regexps. Don't look at the text after regexp, just use the whitelist. * test/indent/ruby.rb: Rearrange examples, add new ones. Fixes: debbugs:6286
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog3
-rw-r--r--lisp/progmodes/ruby-mode.el39
2 files changed, 23 insertions, 19 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index db4cc8e7fab..875ab5d3188 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -10,6 +10,9 @@
10 (ruby-syntax-propertize-percent-literal): Only propertize when not 10 (ruby-syntax-propertize-percent-literal): Only propertize when not
11 inside a simple string or comment. When the literal is unclosed, 11 inside a simple string or comment. When the literal is unclosed,
12 leave the text after it unpropertized. 12 leave the text after it unpropertized.
13 (ruby-syntax-methods-before-regexp): New constant.
14 (ruby-syntax-propertize-function): Use it to recognize regexps.
15 Don't look at the text after regexp, just use the whitelist.
13 16
142012-08-14 Andreas Schwab <schwab@linux-m68k.org> 172012-08-14 Andreas Schwab <schwab@linux-m68k.org>
15 18
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 42e1ac72b33..457c7fee36c 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -1178,7 +1178,13 @@ See `add-log-current-defun-function'."
1178 (eval-and-compile 1178 (eval-and-compile
1179 (defconst ruby-percent-literal-beg-re 1179 (defconst ruby-percent-literal-beg-re
1180 "\\(%\\)[qQrswWx]?\\([[:punct:]]\\)" 1180 "\\(%\\)[qQrswWx]?\\([[:punct:]]\\)"
1181 "Regexp to match the beginning of percent literal.")) 1181 "Regexp to match the beginning of percent literal.")
1182
1183 (defconst ruby-syntax-methods-before-regexp
1184 '("gsub" "gsub!" "sub" "sub!" "scan" "split" "split!" "index" "match"
1185 "assert_match" "Given" "Then" "When")
1186 "Methods that can take regexp as the first argument.
1187It will be properly highlighted even when the call omits parens."))
1182 1188
1183 (defun ruby-syntax-propertize-function (start end) 1189 (defun ruby-syntax-propertize-function (start end)
1184 "Syntactic keywords for Ruby mode. See `syntax-propertize-function'." 1190 "Syntactic keywords for Ruby mode. See `syntax-propertize-function'."
@@ -1196,28 +1202,23 @@ See `add-log-current-defun-function'."
1196 ;; Not within a string. 1202 ;; Not within a string.
1197 (nth 3 (syntax-ppss (match-beginning 0)))) 1203 (nth 3 (syntax-ppss (match-beginning 0))))
1198 (string-to-syntax "\\")))) 1204 (string-to-syntax "\\"))))
1199 ;; Regexps: regexps are distinguished from division either because 1205 ;; Regexps: regexps are distinguished from division because
1200 ;; of the keyword/symbol before them, or because of the code 1206 ;; of the keyword, symbol, or method name before them.
1201 ;; following them.
1202 ((concat 1207 ((concat
1203 ;; Special tokens that can't be followed by a division operator. 1208 ;; Special tokens that can't be followed by a division operator.
1204 "\\(?:\\(^\\|[[=(,~?:;<>]\\|\\(?:^\\|\\s \\)" 1209 "\\(^\\|[[=(,~?:;<>]"
1210 ;; Control flow keywords and operators following bol or whitespace.
1211 "\\|\\(?:^\\|\\s \\)"
1205 (regexp-opt '("if" "elsif" "unless" "while" "until" "when" "and" 1212 (regexp-opt '("if" "elsif" "unless" "while" "until" "when" "and"
1206 "or" "&&" "||" 1213 "or" "not" "&&" "||"))
1207 "gsub" "gsub!" "sub" "sub!" "scan" "split" "split!")) 1214 ;; Method name from the list.
1208 "\\)\\s *\\)?" 1215 "\\|\\_<"
1216 (regexp-opt ruby-syntax-methods-before-regexp)
1217 "\\)\\s *"
1209 ;; The regular expression itself. 1218 ;; The regular expression itself.
1210 "\\(/\\)[^/\n\\\\]*\\(?:\\\\.[^/\n\\\\]*\\)*\\(/\\)" 1219 "\\(/\\)[^/\n\\\\]*\\(?:\\\\.[^/\n\\\\]*\\)*\\(/\\)")
1211 ;; Special code that cannot follow a division operator. 1220 (2 (string-to-syntax "\"/"))
1212 ;; FIXME: Just because the second slash of "/foo/ do bar" can't 1221 (3 (string-to-syntax "\"/")))
1213 ;; be a division, doesn't mean it can't *start* a regexp, as in
1214 ;; "x = toto/foo; if /do bar/".
1215 "\\([imxo]*\\s *\\(?:,\\|\\_<do\\_>\\)\\)?")
1216 (2 (when (or (match-beginning 1) (match-beginning 4))
1217 (string-to-syntax "\"/")))
1218 (3 (if (or (match-beginning 1) (match-beginning 4))
1219 (string-to-syntax "\"/")
1220 (goto-char (match-end 2)))))
1221 ("^=en\\(d\\)\\_>" (1 "!")) 1222 ("^=en\\(d\\)\\_>" (1 "!"))
1222 ("^\\(=\\)begin\\_>" (1 "!")) 1223 ("^\\(=\\)begin\\_>" (1 "!"))
1223 ;; Handle here documents. 1224 ;; Handle here documents.