[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 91f2ade57bb: ruby-mode: Better detect regexp vs division (bug#6
From: |
Dmitry Gutov |
Subject: |
emacs-29 91f2ade57bb: ruby-mode: Better detect regexp vs division (bug#67569) |
Date: |
Sat, 9 Dec 2023 12:54:39 -0500 (EST) |
branch: emacs-29
commit 91f2ade57bb72e9bb4a44da44e5dc69adb3c7584
Author: Dmitry Gutov <dmitry@gutov.dev>
Commit: Dmitry Gutov <dmitry@gutov.dev>
ruby-mode: Better detect regexp vs division (bug#67569)
* lisp/progmodes/ruby-mode.el (ruby-syntax-before-regexp-re):
Add grouping around methods from the whitelist.
(ruby-syntax-propertize): Also look for spaces around the slash.
---
lisp/progmodes/ruby-mode.el | 12 +++++++++---
test/lisp/progmodes/ruby-mode-tests.el | 12 ++++++++++++
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index b252826680c..0ecb3579278 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -2124,7 +2124,7 @@ It will be properly highlighted even when the call omits
parens.")
"or" "not" "&&" "||"))
;; Method name from the list.
"\\|\\_<"
- (regexp-opt ruby-syntax-methods-before-regexp)
+ (regexp-opt ruby-syntax-methods-before-regexp t)
"\\)\\s *")
"Regexp to match text that can be followed by a regular expression."))
@@ -2182,14 +2182,20 @@ It will be properly highlighted even when the call
omits parens.")
(when (save-excursion
(forward-char -1)
(cl-evenp (skip-chars-backward "\\\\")))
- (let ((state (save-excursion (syntax-ppss (match-beginning 1)))))
+ (let ((state (save-excursion (syntax-ppss (match-beginning 1))))
+ division-like)
(when (or
;; Beginning of a regexp.
(and (null (nth 8 state))
(save-excursion
+ (setq division-like
+ (or (eql (char-after) ?\s)
+ (not (eql (char-before (1- (point)))
?\s))))
(forward-char -1)
(looking-back ruby-syntax-before-regexp-re
- (line-beginning-position))))
+ (line-beginning-position)))
+ (not (and division-like
+ (match-beginning 2))))
;; End of regexp. We don't match the whole
;; regexp at once because it can have
;; string interpolation inside, or span
diff --git a/test/lisp/progmodes/ruby-mode-tests.el
b/test/lisp/progmodes/ruby-mode-tests.el
index 117385ea3e8..a931541ba35 100644
--- a/test/lisp/progmodes/ruby-mode-tests.el
+++ b/test/lisp/progmodes/ruby-mode-tests.el
@@ -157,6 +157,18 @@ VALUES-PLIST is a list with alternating index and value
elements."
(ert-deftest ruby-regexp-is-not-mistaken-for-slash-symbol ()
(ruby-assert-state "x = /foo:/" 3 nil))
+(ert-deftest ruby-slash-not-regexp-when-surrounded-by-spaces ()
+ (ruby-assert-state "x = index / 3" 3 nil))
+
+(ert-deftest ruby-slash-not-regexp-when-no-spaces ()
+ (ruby-assert-state "x = index/3" 3 nil))
+
+(ert-deftest ruby-regexp-not-division-when-only-space-before ()
+ (ruby-assert-state "x = index /3" 3 ?/))
+
+(ert-deftest ruby-slash-not-regexp-when-only-space-after ()
+ (ruby-assert-state "x = index/ 3" 3 nil))
+
(ert-deftest ruby-indent-simple ()
(ruby-should-indent-buffer
"if foo
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- emacs-29 91f2ade57bb: ruby-mode: Better detect regexp vs division (bug#67569),
Dmitry Gutov <=