noembryo/KV4Jetbrains

Language Injection

Closed this issue · 6 comments

Hi! I like your settings file.
Unfortunately, I often write kv-code inside python.

from kivy.lang import Builder

Builder.load_string("""
BoxLayout:
    Widget:
""")

I found feature in PyCharm to make Language injections. (Settings > Editor > Language Injections) but I could not figure out how to use it.
image

Maybe you can add this setting to your settings file?

I wrote regex for this

Begin:

(Builder\.load_string\(|kv = )(\s*['"]{3}|[\s ^\n\r]*['"])

End:

(['"]{3}|['"])(\s*\)|)

Matches:

Builder.load_string("""
BoxLayout:
    Widget:
""")
Builder.load_string(
    """
BoxLayout:
    Widget:
    """
)
kv = """
BoxLayout:
    Widget:
"""

This is great!
Can you please post your settings?
I get the same dialog in IDEA but I can't understand where to put your regex..
kv_inject

@noembryo I didn't figure out how to use Language Injection Settings. That regex is just to help you

Well, almost totally bad news.. :o(
You can't use Language Injection with a language that is not supported from the IDE (like kivy).

One little thing that I did though, was to use YAML for the injection.
For this to work, we must put keywords for the start and end of the .kv code.
I use # kv_start and # kv_end
Then, you have to create an injection for YAML with this
+ pyStringLiteralMatches("# kv_start(.+?)# kv_end")

kv_inject2

... and you have some kind of injection that is not much, but better then nothing...

kvX

To fast enclose some kv code to the keywords, you can create a live template
kv_inject4
Remember to make it applicable to Other.

After that, just select the code and..

kv_inject5

Closing this for now, and waiting for the official JetBrains support...