GNOME Bugzilla – Bug 656671
Macros in RPM SPEC files do not have to have braces
Last modified: 2011-09-11 14:45:53 UTC
The syntax file for RPM SPEC files, rpmspec.lang, only highlights defined macro names if they are enclosed in braces, like this %{name} However, just like in bash, the braces are optional most of the time. While using braces is much more common in SPEC files than in bash scripts, an expression like %name is still syntactically correct. The highlighting already works for macros with names that start with an underscore, but all such macro uses should be highlighted. I tested this using gedit on Fedora 15 with gtksourceview 3.0.5.
Created attachment 196012 [details] [review] closes bug? If I understood correctly, currently only the "other-macro" context needs fixing. Could you please test this patch see if it works? I can see now that it would still highlight something like %{other-macro %other-macro} which I think would be incorrect but some other contexts that have the braces as optional use the same solution. Also, there's a few contexts that still have the braces as compulsory. They are <context id="conditional-macro" style-ref="conditional-macro"> <match>%\{\?[A-Za-z0-9_]+\}</match> </context> and <context id="conditional-define" style-ref="define" end-at-line-end="true"> <start>%\{\!\?.*%define</start> <end>\}</end> <include> <context ref="def:line-continue" ignore-style="true"/> </include> </context> should these also be fixed?
Review of attachment 196012 [details] [review]: Let's get this pushed.
Pushed. This problem has been fixed in the development version. The fix will be available in the next major software release. I never used a rpm based distro so I don't know if should fixed the contexts mentioned on reply #1. Please reopen the bug if I should. Thank you for your bug report.
I tried the patch, and it looks good in gedit. As for the conditional macro you ask about in comment 1. The full syntax is %{?symbol: text} If "symbol" is defined, then insert "text", otherwise nothing. The exclamation point negates the test, and the conditional-define simply colors a specific use of this feature in a different way. There is a special case of this use. If ": text" is omitted, the inserted text is the value of "symbol". So %{?symbol} inserts the value of %symbol if it has any, and otherwise nothing. In this special case, the brackets are actually optional. "%?symbol" works the same way. In all other uses, the brackets are compulsory. I don't think it is worth it to try to cover this special case in the syntax highlighting. So as far as I'm concerned, this patch solves the problem.