emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master e8acfc7: Add a command for string quotes toggling to ruby-mod


From: Bozhidar Batsov
Subject: Re: master e8acfc7: Add a command for string quotes toggling to ruby-mode
Date: Wed, 10 Dec 2014 00:07:55 +0200

The thought about using syntax-ppss crossed my mind, but I’m not particularly knowledgable there so I took a familiar route.
I’ll update the code.

P.S. Got to love cryptic code like (nth 8 state). This definitely needs a more digestible API.

-- 
Bozhidar Batsov

On December 9, 2014 at 23:47:37, Dmitry Gutov (address@hidden) wrote:

Hi!

Bozhidar Batsov <address@hidden> writes:

> +(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)))))

Any reason this doesn't do something like

(let ((state (syntax-ppss)))
(when (memq (nth 3 state) '(?' ?\"))
(goto-char (nth 8 state))
(forward-sexp)
(list (nth 8 state) (point))))

?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]