From: Bob Proulx <bob@proulx.com>
To: help-gnu-emacs@gnu.org
Subject: Re: ruby-mode interpolated quotes error
Date: Fri, 2 May 2014 17:55:33 -0600 [thread overview]
Message-ID: <20140502235533.GA29686@hysteria.proulx.com> (raw)
In-Reply-To: <20140502231345.GA20703@hysteria.proulx.com>
Bob Proulx wrote:
> Andrew Pennebaker wrote:
> > Specifically, the initial double quote on line 46 should be colored yellow,
> > like the end double quote, and the single quoted string above.
> >
> > Anyone else experience this?
>
> The #{...} construct causes the character immediately preceding the
> '#' to be colored in the variable face color.
This motivated me to poke into the problem a little. The problem
appears to be ruby-match-expression-expansion which is looking for any
character not a backslash before the #{...}.
(defun ruby-match-expression-expansion (limit)
(when (re-search-forward "[^\\]\\(\\\\\\\\\\)*\\(#\\({[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\|\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+\\)\\)" limit 'move)
(or (ruby-in-ppss-context-p 'string)
(ruby-match-expression-expansion limit))))
It is trying to avoid matching a sub-expression in this case. Two
test cases would be:
"abc#{def}ghi"
"abc\#{def}ghi"
In the first #{def} is a subexpression. In the second the # is
escaped and is not evaluated.
So what is needed is a way to match a # that is not preceded by a
backslash but not to include the non-backslash character in the
expression. Or another method to accomplish the task. I am only an
infrequent elisp hacker and am unfamiliar with the idioms needed to
avoid this problem.
Anyone else on the list know a good idiom to use? It needs to match
but ignore the leading context. (This is the opposite of the "trailing
context" match feature provided by lex.)
As a quick hack to alleviate your particular symptom, while creating a
more rare different one, you could remove the [^\\] part from the
front of the expression. That would no longer match the non-backslash
in front of the #{...} construct and your case would work correctly.
It then would miscolor the new case "abc\#{def}ghi" which is not a
sub-expression due to the escape but would still be colored as if it
were. That might be a less annoying problem.
Bob
--- ruby-mode.el.orig 2014-05-02 17:29:15.312413975 -0600
+++ ruby-mode.el 2014-05-02 17:27:31.935234984 -0600
@@ -1578,7 +1578,7 @@
"Additional expressions to highlight in Ruby mode.")
(defun ruby-match-expression-expansion (limit)
- (when (re-search-forward "[^\\]\\(\\\\\\\\\\)*\\(#\\({[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\|\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+\\)\\)" limit 'move)
+ (when (re-search-forward "\\(\\\\\\\\\\)*\\(#\\({[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\|\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+\\)\\)" limit 'move)
(or (ruby-in-ppss-context-p 'string)
(ruby-match-expression-expansion limit))))
next prev parent reply other threads:[~2014-05-02 23:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-02 21:42 ruby-mode interpolated quotes error Andrew Pennebaker
2014-05-02 23:13 ` Bob Proulx
2014-05-02 23:55 ` Bob Proulx [this message]
2014-05-03 1:32 ` Stefan Monnier
2014-05-03 1:55 ` Bob Proulx
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140502235533.GA29686@hysteria.proulx.com \
--to=bob@proulx.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).