[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master fafba80: Simplify ruby--string-region
From: |
Bozhidar Batsov |
Subject: |
[Emacs-diffs] master fafba80: Simplify ruby--string-region |
Date: |
Mon, 22 Dec 2014 15:04:19 +0000 |
branch: master
commit fafba80d7353f4ab5c359df75798f8130599371a
Author: Bozhidar Batsov <address@hidden>
Commit: Bozhidar Batsov <address@hidden>
Simplify ruby--string-region
* progmodes/ruby-mode.el (ruby--string-region): Simplify code
by leveraging `syntax-ppss'.
---
lisp/ChangeLog | 5 +++++
lisp/progmodes/ruby-mode.el | 17 ++++++-----------
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 37fbc6a..484ac1a 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2014-12-22 Bozhidar Batsov <address@hidden>
+
+ * progmodes/ruby-mode.el (ruby--string-region): Simplify code
+ by leveraging `syntax-ppss'.
+
2014-12-22 Artur Malabarba <address@hidden>
* let-alist.el (let-alist): Use `make-symbol' instead of `gensym'.
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 225f1f6..bf0884f 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -1768,17 +1768,12 @@ If the result is do-end block, it will always be
multiline."
(defun ruby--string-region ()
"Return region for string at point."
- (let ((orig-point (point)) (regex
"'\\(\\(\\\\'\\)\\|[^']\\)*'\\|\"\\(\\(\\\\\"\\)\\|[^\"]\\)*\"") beg end)
- (save-excursion
- (goto-char (line-beginning-position))
- (while (and (re-search-forward regex (line-end-position) t) (not (and
beg end)))
- (let ((match-beg (match-beginning 0)) (match-end (match-end 0)))
- (when (and
- (> orig-point match-beg)
- (< orig-point match-end))
- (setq beg match-beg)
- (setq end match-end))))
- (and beg end (list beg end)))))
+ (let ((state (syntax-ppss)))
+ (when (memq (nth 3 state) '(?' ?\"))
+ (save-excursion
+ (goto-char (nth 8 state))
+ (forward-sexp)
+ (list (nth 8 state) (point))))))
(defun ruby-string-at-point-p ()
"Check if cursor is at a string or not."
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master fafba80: Simplify ruby--string-region,
Bozhidar Batsov <=