aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/ruby-mode.el
diff options
context:
space:
mode:
authorBozhidar Batsov2014-12-22 17:03:32 +0200
committerBozhidar Batsov2014-12-22 17:03:32 +0200
commitfafba80d7353f4ab5c359df75798f8130599371a (patch)
tree00c561fb2e760ed3c3e0b840d071358a59fd7612 /lisp/progmodes/ruby-mode.el
parent251463c60bfb49920bdaba828e650806682ddd63 (diff)
downloademacs-fafba80d7353f4ab5c359df75798f8130599371a.tar.gz
emacs-fafba80d7353f4ab5c359df75798f8130599371a.zip
Simplify ruby--string-region
* progmodes/ruby-mode.el (ruby--string-region): Simplify code by leveraging `syntax-ppss'.
Diffstat (limited to 'lisp/progmodes/ruby-mode.el')
-rw-r--r--lisp/progmodes/ruby-mode.el17
1 files changed, 6 insertions, 11 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 225f1f62673..bf0884f3560 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."
1768 1768
1769(defun ruby--string-region () 1769(defun ruby--string-region ()
1770 "Return region for string at point." 1770 "Return region for string at point."
1771 (let ((orig-point (point)) (regex "'\\(\\(\\\\'\\)\\|[^']\\)*'\\|\"\\(\\(\\\\\"\\)\\|[^\"]\\)*\"") beg end) 1771 (let ((state (syntax-ppss)))
1772 (save-excursion 1772 (when (memq (nth 3 state) '(?' ?\"))
1773 (goto-char (line-beginning-position)) 1773 (save-excursion
1774 (while (and (re-search-forward regex (line-end-position) t) (not (and beg end))) 1774 (goto-char (nth 8 state))
1775 (let ((match-beg (match-beginning 0)) (match-end (match-end 0))) 1775 (forward-sexp)
1776 (when (and 1776 (list (nth 8 state) (point))))))
1777 (> orig-point match-beg)
1778 (< orig-point match-end))
1779 (setq beg match-beg)
1780 (setq end match-end))))
1781 (and beg end (list beg end)))))
1782 1777
1783(defun ruby-string-at-point-p () 1778(defun ruby-string-at-point-p ()
1784 "Check if cursor is at a string or not." 1779 "Check if cursor is at a string or not."