Merge lp:~spud/spud/syntaxhighlighting into lp:spud
Status: | Merged |
---|---|
Merged at revision: | 520 |
Proposed branch: | lp:~spud/spud/syntaxhighlighting |
Merge into: | lp:spud |
Diff against target: |
156 lines (+56/-17) 5 files modified
diamond/diamond/datawidget.py (+8/-4) diamond/diamond/mixedtree.py (+24/-7) diamond/diamond/tree.py (+19/-5) schema/spud_base.rnc (+2/-1) schema/spud_base.rng (+3/-0) |
To merge this branch: | bzr merge lp:~spud/spud/syntaxhighlighting |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Patrick Farrell | Approve | ||
Review via email:
|
Description of the change
I'd like to be able to add code snippets to my options file and use syntax highlighting other than python. This is my proposal to do this but as I'm messing around in files I've never looked at before I'd appreciate feedback.
This merge would change the current python_code in spud_base.rnc from:
python_code =
(
element string_value{
attribute type { "python" },
...
)
to:
python_code =
(
element string_value{
attribute type { "code" },
attribute language { "python" },
...
)
i.e. type is now "code" and a new attribute language {"python"} has been added.
In combination with changes to mixedtree.py, tree.py and datawidget.py this would allow developers to add various other code types into their schemas (so long as they are available in gtksourceview2). For example, I've added:
cpp_code =
(
element string_value{
attribute type { "code" },
attribute language { "cpp" },
...
)
to my schema.
To achieve this is_python_code() in mixedtree.py and tree.py have been modified to is_code() and just checks for the existence of the type {"code"} attribute.
IMPORTANT QUESTION: what did the lines:
try:
lang = self.get_
if lang == "python":
return True
except:
pass
in is_python_code() do? I couldn't see how they did anything, as there's no "language" attribute in the spud_base schema so I've removed them here but I'd like to double check as I'm probably missing something.
After add_text_view() in datawidget.py checks whether the current node is_code() it then retrieves the language from get_code_language() in mixedtree.py (adding this to tree.py seemed superfluous as is_code() now always returns false here). In get_code_language() there's a lot of defaulting to "python" to try to smooth the changes in the schema with old files. add_text_view() also defaults to "python" if the language type selected isn't available.
The major disadvantage of this merge is the change to the schema and hence modification of most options files. Hopefully the defaulting will smooth this for users, though it would also be good to remove the defaults with time. I'd appreciate any input on a method of achieving this without such difficulties.
Cheers,
Cian
I think syntax highlighting of other languages is desirable and important, so thanks for the contribution.
I agree with you: I think the self.get_ attr("language" ) did nothing. It is probably a leftover from some previous way of denoting python code in the schema; I think you are correct in deleting it.
I think that if you're going to change the schema in such a way that a currently valid flml becomes invalid, then you should write a script that converts from type == "python" to (type, language) == ("code", "python"). I'm not sure how to manage the transition, and I'm not sure we'd want this to go in before release. David, Stephan, any thoughts?