Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language Injection #2

Closed
ArtemSBulgakov opened this issue Oct 30, 2019 · 6 comments
Closed

Language Injection #2

ArtemSBulgakov opened this issue Oct 30, 2019 · 6 comments

Comments

@ArtemSBulgakov
Copy link

ArtemSBulgakov commented Oct 30, 2019

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?

@ArtemSBulgakov
Copy link
Author

ArtemSBulgakov commented Oct 30, 2019

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:
"""

@noembryo
Copy link
Owner

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

@ArtemSBulgakov
Copy link
Author

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

@noembryo
Copy link
Owner

noembryo commented Oct 30, 2019

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

@noembryo
Copy link
Owner

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

@noembryo
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants