Add automatic attribute styling for python#49
Add automatic attribute styling for python#49Red-M wants to merge 14 commits intoScintillaOrg:masterfrom
Conversation
|
This is a disruptive change that may be incompatible with downstream projects and usage. For example, it stops the following SciTE settings from highlighting "findall" and "replace" methods as these are now treated as SCE_P_ATTRIBUTE instead of SCE_P_IDENTIFIER: The change may cause scripts that depend on the results of lexing to break. It could be safer to guard attribute recognition with an enabling In The tests in the test subdirectory fail after this change so should be updated. See The SCE_P_ATTRIBUTE state doesn't persist over new lines and some users like splitting complex lines after '.' so will see some attributes highlighted and others not: x = s.findall("thing")
y = a.very.complicated.expression.
findall("<p><script>// Inserted by macrothing") |
|
Thank you for taking the time to look at this change. I think it will be easier to add an option to enable this style of lexing, I only want it for making SciTE able to more closely replicate a code highlighting theme I enjoy. I'll fix |
Fix `lexicalClasses` description for attributes.
|
I've fixed everything else up except the tests because I'm not sure why but I'm getting errors that don't seem related to my changes when I run There are more errors but this is the first. |
Lines 9 to 10 in ebb1211 Does |
|
I'll need to update my g++ apologies. |
|
The tests are passing now but I'll need to add new tests for this setting. |
|
How should I add tests for this? |
Update styling tests for python to include new attribute code to style, pending advice on how this should be done.
|
I've figured the tests out and this should be good to review again. |
|
20, "SCE_P_ATTRIBUTE", "identifier", "Attribute of identifier",The persistent state over new lines appears to work well. The added tests are exhaustive which initially appears to be a good thing as changes to other lexical classes will be noticed. However, this may not be great for maintenance. Will someone adding a new test to AllStyles.py in the main directory know/remember to add it to each subdirectory? How will this scale to more settings? It may be better to add a new short test ("attributes.py"?) that concentrates on the new feature. |
I think how aggressive the amount of attribute styling is important as for example, I would prefer to use using
I have fixed this in the latest commit.
I have reduced the number of tests to just testing mode |
|
That appears to have improved things. |
|
Thanks, please let me know if there is anything else I need to do for this to get merged. |
|
This has sat in my queue for a while, almost getting pushed but the 5 state setting looks to me like it will confuse users, particularly the difference between 2 and 3. Complex settings don't get used. The main requirement of the setting is to protect current user setups while allowing some progress. However, that progress doesn't have to reach the final state which may be better informed if a simpler version was introduced initially. Identifier and decorator attributes appear distinct to me so would be better with distinct properties which would both default to 0.
|
|
Could I also suggest a 3rd option which controls if already styled attributes are respected? |
…tions with undocumented 3rd option.
|
Just noting that if there is a way to get the styler to give me the style at a text location for backwards searching, I could remove the entire loop for comment and decorator detection. It may make the new code easier to read and maintain. |
Lines 120 to 122 in 66a030c
I don't see how the loop can be eliminated, unless you're expecting the significant character to be at exactly the start or end of the line. But it's always a good idea to check the lexical style and character value at the same time — e.g., |
|
I did try |
See issue #54, you need to call |
That may be a detour. My thinking was that if users consider attributes to be different then there should be distinct list(s) of highlighted attributes. Or maybe consider identifier.attribute pairs ('codecs.open', 'pathlib.Path'). I didn't say that as there are many possibilities here making it a large topic which should be discussed in a separate issue. |
Another possibility is to maintain a state enumeration (start, identifier, identifierDot, ...) and store / retrieve it with line state or a lexer field similar to ftripleStateAtEol. |
Personally, I wanted this change so that lists of attributes didn't have to be maintained, I might want to change the idea behind this to be around allowing default styling of attributes. Since I was wanting to be able to imitate themes from other editors. If such a list is going to be required, please just decline this PR. |
|
Give me a moment to figure out how I want to present this patch. |
|
That is more along the lines of what I think is being offered. |
|
I think this is a good starting point as is and would prefer this to be accepted as is, if there are more changes you'd like, please let me know. |
(1) implies you want attributes to be styled specially when they are included in an special identifier list but (2) says you want attributes to just be a single style that isn't affected by any lists.
Did you interpret my comment as not styling attributes as attributes unless they are in a list? I meant they might be plain attributes unless in a list just like identifiers. "Attribute" is reasonably well understood in Python but "subword" is unfamiliar. Is this commonly used? |
I am on the side of (2) here but I don't mind if subwords from
I did and your clarification is a relief since I really don't enjoy the idea as a developer of libraries to have to release/maintain wordlists for editors to pick up on, its kinda why I did this feature the way I did since it allowed styling identifiers differently.
I used subwords from the vernacular that is in scite/scintilla vs Python, similar to |
|
I am happy to revert the subword change back to attributes however. |
|
"substyle" is a Lexilla term for taking one style (like The problem it solves was that users want multiple sets of identifiers highlighted differently (sometimes one colour per library) and there may be multiple types of identifier-like lexemes in a file (in HTML: tags, attributes, JavaScript identifiers, PHP identifiers, ...). Lexilla has a fixed number of styles available and different users may want more distinctions in different types. I think the last 2 changes on this pull request should be reverted and the property descriptions simplified to just describe their positive effect for the value |
|
I think that is fine and I'll revert those changes this afternoon. |
|
That should be what we're looking for, after I fix the tests. |
…ifier.attributes and lexer.python.decorator.attributes.
|
Committed feature. Credited to "Red-M". If you want a different name in the credits then reply with desired name. |
|
|
Fixed. |
|
Included in 5.1.5 release. |
"attribute" is for highlighting object attributes or methods, i.e. to style foo and bar differently in foo.bar. Also set lexer properties to allow scintilla using different styles. See ScintillaOrg/lexilla#49
"attribute" is for highlighting object attributes or methods, i.e. to style foo and bar differently in foo.bar. Also set lexer properties to allow scintilla using different styles. See ScintillaOrg/lexilla#49
This allows for styling attributes of identifiers like the screenshot below.

Please let me know if I've missed anything.