I've been playing around with constructs like that for quite some time, here are some thoughts on the matter:
If you use a string face with, say, both a background and a foreground color, it will matter if you *replace* the existing face as opposed to *prepend* a new face on top of it.
For example, the default Ruby mode replace the face, which doesn't look good when the string face has a background color:
With *prepend* it would have looked like:
In other words, the font-lock rule should use "prepend" and not "t" as the override flag. (I've got it on my todo-list to change a lot of "t":s to "prepend" but haven't had time to do it yet.)
One question is if the delimiters around the _expression_ should be highlighted as well? In Ruby they are highlighted. In my cmake-font-lock package I have opted not to highlight them, as it makes it easier to read the variable name:
Another reason for this is that CMake supports nested such constructs, which look better this way:
> how should font-lock display `name`. Should it have a normal face as if it weren't inside a string? Or should have a kind of combination of string-face and something else?
In all cases I've seen, the content is displayed using `font-lock-variable-name-face', even for the cases where the content is more complex than a plain variable. I would say that this is OK, as they stand out and, most of the time, it is a plain variable anyway.
As I said above, using *prepend*, the end result will be a mix of font-lock-variable-name-face and font-lock-string-face.
> several parts of Emacs like to know if we're inside
> code/string/comment (usually using (nth [3|4|8] (syntax-ppss))).
> Should these all consider "name" as being inside code?
> Or inside string? Or should we revisit all those cases one-by-one?
I see this as a pure syntax highlighting thing, so I would say that syntax-ppss should treat them as strings.
A side note: I've started to make an inventory of syntax highlighting in various modes in Emacs, as part of a font-lock regression test suite I've accumulated over the years. The suite and the inventory is far from complete, but it might be worth looking into:
One mode that stands out in this respect is "bat" mode, it handles "%alpha" but not "%alpha_beta", and doesn't support the construct in strings at all.