* Re: master e8acfc7: Add a command for string quotes toggling to ruby-mode
[not found] ` <E1XyOqS-0007dA-S5@vcs.savannah.gnu.org>
@ 2014-12-09 21:47 ` Dmitry Gutov
2014-12-09 21:50 ` Bozhidar Batsov
2014-12-09 22:07 ` Bozhidar Batsov
2014-12-10 2:11 ` Ted Zlatanov
1 sibling, 2 replies; 9+ messages in thread
From: Dmitry Gutov @ 2014-12-09 21:47 UTC (permalink / raw)
To: emacs-devel; +Cc: Bozhidar Batsov
Hi!
Bozhidar Batsov <bozhidar@batsov.com> 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))))
?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: master e8acfc7: Add a command for string quotes toggling to ruby-mode
2014-12-09 21:47 ` master e8acfc7: Add a command for string quotes toggling to ruby-mode Dmitry Gutov
@ 2014-12-09 21:50 ` Bozhidar Batsov
2014-12-09 22:10 ` Dmitry Gutov
2014-12-09 22:07 ` Bozhidar Batsov
1 sibling, 1 reply; 9+ messages in thread
From: Bozhidar Batsov @ 2014-12-09 21:50 UTC (permalink / raw)
To: Dmitry Gutov, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1086 bytes --]
I was thinking it might cause problems for strings that are not quoted literals. I might be wrong, though.
—
Cheers,
Bozhidar
On December 9, 2014 at 23:47:37, Dmitry Gutov (dgutov@yandex.ru) wrote:
Hi!
Bozhidar Batsov <bozhidar@batsov.com> 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))))
?
[-- Attachment #2: Type: text/html, Size: 2147 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: master e8acfc7: Add a command for string quotes toggling to ruby-mode
2014-12-09 21:47 ` master e8acfc7: Add a command for string quotes toggling to ruby-mode Dmitry Gutov
2014-12-09 21:50 ` Bozhidar Batsov
@ 2014-12-09 22:07 ` Bozhidar Batsov
2014-12-09 22:23 ` Dmitry Gutov
1 sibling, 1 reply; 9+ messages in thread
From: Bozhidar Batsov @ 2014-12-09 22:07 UTC (permalink / raw)
To: Dmitry Gutov, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1224 bytes --]
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 (dgutov@yandex.ru) wrote:
Hi!
Bozhidar Batsov <bozhidar@batsov.com> 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))))
?
[-- Attachment #2: Type: text/html, Size: 2643 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: master e8acfc7: Add a command for string quotes toggling to ruby-mode
2014-12-09 21:50 ` Bozhidar Batsov
@ 2014-12-09 22:10 ` Dmitry Gutov
0 siblings, 0 replies; 9+ messages in thread
From: Dmitry Gutov @ 2014-12-09 22:10 UTC (permalink / raw)
To: Bozhidar Batsov, emacs-devel
On 12/09/2014 11:50 PM, Bozhidar Batsov wrote:
> I was thinking it might cause problems for strings that are not quoted
> literals. I might be wrong, though.
What kind of problems? The suggestion does check the string's type (the
terminating character).
IIRC, I have this kind of code somewhere else, so I'd be good to know if
it's not ideal.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: master e8acfc7: Add a command for string quotes toggling to ruby-mode
2014-12-09 22:07 ` Bozhidar Batsov
@ 2014-12-09 22:23 ` Dmitry Gutov
0 siblings, 0 replies; 9+ messages in thread
From: Dmitry Gutov @ 2014-12-09 22:23 UTC (permalink / raw)
To: Bozhidar Batsov, emacs-devel
On 12/10/2014 12:07 AM, Bozhidar Batsov wrote:
> I’ll update the code.
Thanks.
> P.S. Got to love cryptic code like (nth 8 state). This definitely needs
> a more digestible API.
I don't know, I kinda like the succinctness.
Although the fact that I do have to look up the `parse-partial-sexp'
description almost every time, says that a handful of defsubsts might
indeed be of help.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: master e8acfc7: Add a command for string quotes toggling to ruby-mode
[not found] ` <E1XyOqS-0007dA-S5@vcs.savannah.gnu.org>
2014-12-09 21:47 ` master e8acfc7: Add a command for string quotes toggling to ruby-mode Dmitry Gutov
@ 2014-12-10 2:11 ` Ted Zlatanov
2014-12-10 8:30 ` Bozhidar Batsov
1 sibling, 1 reply; 9+ messages in thread
From: Ted Zlatanov @ 2014-12-10 2:11 UTC (permalink / raw)
To: emacs-devel; +Cc: Bozhidar Batsov
On Tue, 09 Dec 2014 17:45:09 +0000 Bozhidar Batsov <bozhidar@batsov.com> wrote:
BB> Add a command for string quotes toggling to ruby-mode
BB> * progmodes/ruby-mode.el (ruby-toggle-string-quotes): New command that
BB> allows you to quickly toggle between single-quoted and double-quoted
BB> string literals.
Boshidar, this would be useful for other languages too (at least Perl
and CFEngine). Would you be able to generalize your contribution? If
not, would it be OK with you if I do it?
Thanks
Ted
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: master e8acfc7: Add a command for string quotes toggling to ruby-mode
2014-12-10 2:11 ` Ted Zlatanov
@ 2014-12-10 8:30 ` Bozhidar Batsov
2014-12-10 13:25 ` Ted Zlatanov
0 siblings, 1 reply; 9+ messages in thread
From: Bozhidar Batsov @ 2014-12-10 8:30 UTC (permalink / raw)
To: emacs-devel, Ted Zlatanov
[-- Attachment #1: Type: text/plain, Size: 751 bytes --]
I’m fine with you generalising it, but I guess I’ll have to apply the refactoring suggested by Dmitry first.
--
Bozhidar Batsov
On December 10, 2014 at 04:10:48, Ted Zlatanov (tzz@lifelogs.com) wrote:
On Tue, 09 Dec 2014 17:45:09 +0000 Bozhidar Batsov <bozhidar@batsov.com> wrote:
BB> Add a command for string quotes toggling to ruby-mode
BB> * progmodes/ruby-mode.el (ruby-toggle-string-quotes): New command that
BB> allows you to quickly toggle between single-quoted and double-quoted
BB> string literals.
Boshidar, this would be useful for other languages too (at least Perl
and CFEngine). Would you be able to generalize your contribution? If
not, would it be OK with you if I do it?
Thanks
Ted
[-- Attachment #2: Type: text/html, Size: 1609 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: master e8acfc7: Add a command for string quotes toggling to ruby-mode
2014-12-10 8:30 ` Bozhidar Batsov
@ 2014-12-10 13:25 ` Ted Zlatanov
2014-12-22 15:06 ` Bozhidar Batsov
0 siblings, 1 reply; 9+ messages in thread
From: Ted Zlatanov @ 2014-12-10 13:25 UTC (permalink / raw)
To: emacs-devel
On Wed, 10 Dec 2014 10:30:28 +0200 Bozhidar Batsov <bozhidar@batsov.com> wrote:
BB> On December 10, 2014 at 04:10:48, Ted Zlatanov (tzz@lifelogs.com) wrote:
TZ> Bozhidar, this would be useful for other languages too (at least Perl
TZ> and CFEngine). Would you be able to generalize your contribution? If
TZ> not, would it be OK with you if I do it?
BB> I’m fine with you generalising [`ruby-toggle-string-quotes'], but I
BB> guess I’ll have to apply the refactoring suggested by Dmitry first.
OK, let me know when you're ready with that and I'll extract it.
I am excited to use it, I've needed it several times :)
Ted
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: master e8acfc7: Add a command for string quotes toggling to ruby-mode
2014-12-10 13:25 ` Ted Zlatanov
@ 2014-12-22 15:06 ` Bozhidar Batsov
0 siblings, 0 replies; 9+ messages in thread
From: Bozhidar Batsov @ 2014-12-22 15:06 UTC (permalink / raw)
To: Ted Zlatanov, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 874 bytes --]
Just committed the updated version. Looking forward to seeing this in as many modes as possible.
—
Cheers,
Bozhidar
On December 10, 2014 at 3:25:56 PM, Ted Zlatanov (tzz@lifelogs.com) wrote:
On Wed, 10 Dec 2014 10:30:28 +0200 Bozhidar Batsov <bozhidar@batsov.com> wrote:
BB> On December 10, 2014 at 04:10:48, Ted Zlatanov (tzz@lifelogs.com) wrote:
TZ> Bozhidar, this would be useful for other languages too (at least Perl
TZ> and CFEngine). Would you be able to generalize your contribution? If
TZ> not, would it be OK with you if I do it?
BB> I’m fine with you generalising [`ruby-toggle-string-quotes'], but I
BB> guess I’ll have to apply the refactoring suggested by Dmitry first.
OK, let me know when you're ready with that and I'll extract it.
I am excited to use it, I've needed it several times :)
Ted
[-- Attachment #2: Type: text/html, Size: 1754 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-12-22 15:06 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20141209174508.29184.57986@vcs.savannah.gnu.org>
[not found] ` <E1XyOqS-0007dA-S5@vcs.savannah.gnu.org>
2014-12-09 21:47 ` master e8acfc7: Add a command for string quotes toggling to ruby-mode Dmitry Gutov
2014-12-09 21:50 ` Bozhidar Batsov
2014-12-09 22:10 ` Dmitry Gutov
2014-12-09 22:07 ` Bozhidar Batsov
2014-12-09 22:23 ` Dmitry Gutov
2014-12-10 2:11 ` Ted Zlatanov
2014-12-10 8:30 ` Bozhidar Batsov
2014-12-10 13:25 ` Ted Zlatanov
2014-12-22 15:06 ` Bozhidar Batsov
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.