It would be great if the syntax highlighted, not only 'old' string format (format % substitutions), but the new style too ("string".format(substitutions)). The new format has new syntax, and I made a regex to highlight as it was highlighted the olther style. <RegExpr attribute="String Substitution" String="\{([a-zA-Z0-9_]+|[0-9]+)(\.[a-zA-Z0-9_]+|\[[^ \]]+\])*(![rs])?(:([^}]?[<>=^])?[ +-]?#?0?[0-9]*(\.[0-9]+)?[bcdeEfFgGnosxX%]?)?\}" context="#stay"/> (It should be placed under the other "String Substitution" is) Reproducible: Always Steps to Reproduce: Write a piece of code: print "My var value: {var}".format(var=10) print "My var value: {var[name]}".format(var={"name":"Bob"}) Actual Results: Strings are fully colored as strings. Expected Results: Variable substitution syntax should be visible in another color/style. The full syntax is as follows: ( http://docs.python.org/2/library/string.html#format-string-syntax ) replacement_field ::= "{" field_name ["!" conversion] [":" format_spec] "}" field_name ::= (identifier | integer) ("." attribute_name | "[" element_index "]")* attribute_name ::= identifier element_index ::= integer | index_string index_string ::= <any source character except "]"> + conversion ::= "r" | "s" format_spec ::= [[fill]align][sign][#][0][width][.precision][type] fill ::= <a character other than '}'> align ::= "<" | ">" | "=" | "^" sign ::= "+" | "-" | " " width ::= integer precision ::= integer type ::= "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"
Created attachment 78377 [details] Patch with respect syntax file v2.16 I have made a patch to the syntax file v2.16.
Thanks for the patch. Just had a look and it seems to work. However, in your example: print "My var value: {var}".format(var=10) `format` is colored like the matched {var}. This makes it hard to tell where the string ends. Also, other string methods aren't highlighted either, so imho it probably be better (for consistency) not to match the `format` function as a string substitution.
(In reply to comment #2) > Thanks for the patch. Just had a look and it seems to work. However, in your > example: > print "My var value: {var}".format(var=10) > `format` is colored like the matched {var}. This makes it hard to tell where > the string ends. Also, other string methods aren't highlighted either, so > imho it probably be better (for consistency) not to match the `format` > function as a string substitution. That's because format is also a built-in function. (see http://docs.python.org/2/library/functions.html#format -- all functions in that page are colored the same) In fact, they have different color styles: string substitution is 'dsOthers' and built-in functions are 'dsDataType'.
(In reply to comment #3) > That's because format is also a built-in function. (see > http://docs.python.org/2/library/functions.html#format -- all functions in > that page are colored the same) Thanks; good point. I had tried two built-in functions (like Python 3's print) and they weren't in that list yet (hence not in the same color). Therefore I was confused. Also the color scheme isn't particularly fortunate having the same color for BIFs. Will sort things out by the end of the week.
Git commit e60dbd2c68c822e6817f7120ba1c8eca87f05bd9 by Gerald Senarclens de Grancy. Committed on 15/05/2013 at 20:22. Pushed by geralds into branch 'master'. Python syntax for string.format patch by xOneca M +17 -1 part/syntax/data/python.xml http://commits.kde.org/kate/e60dbd2c68c822e6817f7120ba1c8eca87f05bd9