all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Help understanding ruby.el percent literal syntax
@ 2019-06-19  9:33 Philippe Vaucher
  2019-06-19 13:20 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Vaucher @ 2019-06-19  9:33 UTC (permalink / raw)
  To: Emacs developers

[-- Attachment #1: Type: text/plain, Size: 1240 bytes --]

Hello,

We are trying to solve a bug in evil-surround at
https://github.com/emacs-evil/evil-surround/issues/154. The bug is that
percent literals refuse to be replaced when you try to replace a pair of
"{}" with "()" using evil-surround, because ruby.el modifies the percent
literal syntax table in a special way (when we use `fundamental-mode' then
things works as expected).

Thus we are trying to understand the purpose of
`ruby-syntax-propertize-percent-literal' function (
https://github.com/emacs-mirror/emacs/blob/master/lisp/progmodes/ruby-mode.el#L1971-L1999)
which is called from `ruby-syntax-propertize' (
https://github.com/emacs-mirror/emacs/blob/master/lisp/progmodes/ruby-mode.el#L1929
).

If I comment out the call to `ruby-syntax-propertize-percent-literal', then
the bug in evil-surround is gone, and everything just looks the same
visually (the percent literals are correctly highlighted). I don't
understand what purpose this function has. Maybe some other parts of
ruby.el rely on this syntax-table modification?

If someone can point to other parts in ruby.el that require this function
to be called, maybe we can then figure out what the "bug" is in that
function, and possibly offer a patch.

Kind regards,
Philippe

[-- Attachment #2: Type: text/html, Size: 1726 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Help understanding ruby.el percent literal syntax
  2019-06-19  9:33 Help understanding ruby.el percent literal syntax Philippe Vaucher
@ 2019-06-19 13:20 ` Stefan Monnier
  2019-06-19 15:51   ` Philippe Vaucher
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2019-06-19 13:20 UTC (permalink / raw)
  To: emacs-devel

> We are trying to solve a bug in evil-surround at
> https://github.com/emacs-evil/evil-surround/issues/154. The bug is that
> percent literals refuse to be replaced when you try to replace a pair of
> "{}" with "()" using evil-surround, because ruby.el modifies the percent
> literal syntax table in a special way (when we use `fundamental-mode' then
> things works as expected).

ruby-mode uses syntax-propertize to make it so that

    config.allow_sites = %w{twitter facebook pinterest linkedin}
    
is treated somewhat like

    config.allow_sites = "w{twitter facebook pinterest linkedin"

So if you go to the end of the line and try to skip back over the
previous `sexp` you'll end up in front of the `%` rather than in front
of the `{`.

The purpose is probably to handle things like:

    config.allow_sites = %w{twitter facebook # pinterest linkedin}

where the `#` would otherwise be taken as the beginning of a comment.

> If I comment out the call to `ruby-syntax-propertize-percent-literal', then
> the bug in evil-surround is gone, and everything just looks the same
> visually (the percent literals are correctly highlighted).

Not sure what "comment out the call" means exactly, but from my reading
of the code, it would result in mayhem (the %w{ above would probably
be highlighted as if he extended to the end of the buffer).

In order to interact better with things like Evil's
delimiter-replacement, ruby-mode.el could be changed so that instead of
marking the opening `%` and the closing `}` with the `|` syntax, it
would mark the `%` and `w` part with `'` syntax and then arrange to mark
the inside of the delimited text with an ad-hoc syntax table that
doesn't treat `#` as a comment started nor `"` as a string delimiter
(i.e., the same syntax-table used by the `with-syntax-table`
in `ruby-syntax-propertize-percent-literal`).  Or alternatively, it
could look for things like `#` and `"` and give them a `.` syntax.


        Stefan




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Help understanding ruby.el percent literal syntax
  2019-06-19 13:20 ` Stefan Monnier
@ 2019-06-19 15:51   ` Philippe Vaucher
  0 siblings, 0 replies; 3+ messages in thread
From: Philippe Vaucher @ 2019-06-19 15:51 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs developers

[-- Attachment #1: Type: text/plain, Size: 1983 bytes --]

>
> ruby-mode uses syntax-propertize to make it so that
>
>     config.allow_sites = %w{twitter facebook pinterest linkedin}
>
> is treated somewhat like
>
>     config.allow_sites = "w{twitter facebook pinterest linkedin"
>
> So if you go to the end of the line and try to skip back over the
> previous `sexp` you'll end up in front of the `%` rather than in front
> of the `{`.
>
> The purpose is probably to handle things like:
>
>     config.allow_sites = %w{twitter facebook # pinterest linkedin}
>
> where the `#` would otherwise be taken as the beginning of a comment.
>

Ah right, that makes sense.



> > If I comment out the call to `ruby-syntax-propertize-percent-literal',
> then
> > the bug in evil-surround is gone, and everything just looks the same
> > visually (the percent literals are correctly highlighted).
>
> Not sure what "comment out the call" means exactly, but from my reading
> of the code, it would result in mayhem (the %w{ above would probably
> be highlighted as if he extended to the end of the buffer).
>

What I meant was "if I edit `ruby-syntax-propertize' so it never calls
`ruby-syntax-propertize-percent-literal' at line 1929". But I think you are
right, it would probably break on your example with the comment above.


In order to interact better with things like Evil's
> delimiter-replacement, ruby-mode.el could be changed so that instead of
> marking the opening `%` and the closing `}` with the `|` syntax, it
> would mark the `%` and `w` part with `'` syntax and then arrange to mark
> the inside of the delimited text with an ad-hoc syntax table that
> doesn't treat `#` as a comment started nor `"` as a string delimiter
> (i.e., the same syntax-table used by the `with-syntax-table`
> in `ruby-syntax-propertize-percent-literal`).  Or alternatively, it
> could look for things like `#` and `"` and give them a `.` syntax.


Thank you a lot for the explanation and the suggestion! We'll see what we
can do :-)

Kind regards,
Philippe

[-- Attachment #2: Type: text/html, Size: 2780 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-06-19 15:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-19  9:33 Help understanding ruby.el percent literal syntax Philippe Vaucher
2019-06-19 13:20 ` Stefan Monnier
2019-06-19 15:51   ` Philippe Vaucher

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.