[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: General delimited literals in ruby-mode patch
From: |
Dmitry Gutov |
Subject: |
Re: General delimited literals in ruby-mode patch |
Date: |
Fri, 10 Feb 2012 09:03:17 +0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.93 (windows-nt) |
>> The bug: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=6286.
And here's a tentative patch for the last example (regexp as a first
parameter in a paren-less method invocation).
It adds a check whether the regexp is followed by a comma or a
block, though, so the full example should look like this:
Given /A user is logged in/ do
# whatever
end
AFAIK, all Cucumber step definitions need a block (that's where the
definition goes), so it shouldn't be a problem.
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index e93f8b3..a0a6509 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -1130,9 +1130,8 @@ See `add-log-current-defun-function'."
(nth 3 (syntax-ppss (match-beginning 0))))
(string-to-syntax "\\"))))
;; regexps
- ("\\(^\\|[[=(,~?:;<>]\\|\\(^\\|\\s
\\)\\(if\\|elsif\\|unless\\|while\\|until\\|when\\|and\\|or\\|&&\\|||\\)\\|g?sub!?\\|scan\\|split!?\\)\\s
*\\(/\\)[^/\n\\\\]*\\(\\\\.[^/\n\\\\]*\\)*\\(/\\)"
- (4 "\"/")
- (6 "\"/"))
+ ("\\(^\\|[[=(,~?:;<>]\\|\\(?:^\\|\\s
\\)\\(?:if\\|elsif\\|unless\\|while\\|until\\|when\\|and\\|or\\|&&\\|||\\)\\|g?sub!?\\|scan\\|split!?\\)?\\s
*\\(/\\)[^/\n\\\\]*\\(?:\\\\.[^/\n\\\\]*\\)*\\(/\\)"
+ (2 (ruby-syntax-propertize-regexp)))
("^=en\\(d\\)\\_>" (1 "!"))
("^\\(=\\)begin\\_>" (1 "!"))
;; Handle here documents.
@@ -1143,6 +1142,21 @@ See `add-log-current-defun-function'."
(1 (prog1 "|" (ruby-syntax-propertize-general-delimiters end)))))
(point) end))
+ (defun ruby-syntax-propertize-regexp ()
+ (let ((syn (string-to-syntax "\"/")))
+ (goto-char (match-end 3))
+ (if (or
+ ;; after paren, comma, operator, control flow keyword,
+ ;; or a method from hardcoded list
+ (match-beginning 1)
+ ;; followed by comma or block
+ (looking-at "[imxo]*\\s *\\(?:,\\|\\<do\\>\\)"))
+ (progn
+ (put-text-property (1- (point)) (point)
+ 'syntax-table syn)
+ syn)
+ (goto-char (match-end 2)))))
+
(defun ruby-syntax-propertize-heredoc (limit)
(let ((ppss (syntax-ppss))
(res '()))