Sublime Text handles these aspects rather excellently, and even
highlights the code inside as code, not string contents:
http://i.imgur.com/NH1Ye.png
Is there a proper way to do so in Emacs?
Currently, it's pretty difficult for Emacs to handle it like in the
picture above.
My first idea was, when propertizing interpolation, to see what kind of
string we're inside, and apply the appropriate syntax to the enclosing
braces, thus splitting the literal in two. But (a) string quotes class
doesn't work that way (text characters on both ends of a literal must
be the same), (b) if we're inside a percent literal (syntax class:
generic string), and the literal spans several lines, we need to be able
to jump to its real beginning position from its end, but with this
approach (nth 8 (syntax-ppss)) will just return the beginning of the
last piece. Saving buffer positions to text properties looks not very
reliable, since the respective text may be deleted and re-inserted.
Suggestions?
I think the better approach is to extend syntax.c with such a notion of
"syntax within strings". This could hopefully be used for:
- Strings within strings (e.g. Postscript nested strings).
- Comments within strings (I think some regexps allow comments).
- Code within strings (as here and in shell scripts).
I'm not sure what that would look like concretely. Maybe a new string
quote syntax which specifies a syntax-table to use within the string?