Bug 497266 - Support some easier scripting language to write plugins
Summary: Support some easier scripting language to write plugins
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: scripting (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-12-10 09:09 UTC by Bart Ribbers
Modified: 2025-01-02 06:59 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bart Ribbers 2024-12-10 09:09:23 UTC
One of the reasons editors like VSCode became big is good plugin support. Plugins are really easy to write using JavaScript/Typescript and because of that there are absolute tons of them to add all kind of functionality to the editor.

Kate of course supports plugins but as far as I can see they require to be written in C++. I understand why that is, 99% of KDE software is written in that language of course, but this makes it harder for people to get into writing plugins. C++ (and Qt) is a system level language and not something you just pick up and write something quickly for.

It would be good if some easier scripting language is supported. I'm not advocating for adding JavaScript support, personally I rather see a language like Python (KDE frameworks has Python bindings too so in the context of KDE it would make sense) or perhaps even Lua, but I think some easier to use scripting language would boost the creation of plugins significantly.
Comment 1 Waqar Ahmed 2024-12-10 10:48:44 UTC
This is too general to be actionable. What do you actually want to do? Do you have a clear/specific idea? 

Note that we do have javascript scripting support.
Comment 2 Bart Ribbers 2024-12-10 10:52:40 UTC
> What do you actually want to do? Do you have a clear/specific idea? 

Support anything other than C++ for writing plugins, preferably an easier to get into language like scripting languages.

> Note that we do have javascript scripting support.

This is new to me, is there documentation for this somewhere? The plugins shipped with Kate are all C++ and I couldn't find any examples.
I'm not personally a fan of JavaScript but I'm glad this support exists and would love to make use of it.
Comment 3 Waqar Ahmed 2024-12-10 11:03:28 UTC
See: https://docs.kde.org/stable5/en/kate/katepart/dev-scripting.html

This is how kate indents your code while you type.

> Support anything other than C++ for writing plugins, preferably an easier to get into language like scripting languages.

Still too general. While possible in theory, in practice, I dont think its really possible for us to support another language which can do all the things that we can do from C++ for many reasons such as stability/maintainability. I tried to expose our APIs in python last year but it didn't work out. It would be better for us to expose specific things as needed by people in a higher level language, similar to how sublime does it. This is why I asked if you want to build something and perhaps we can find a way to expose the functionality.
Comment 4 Bart Ribbers 2024-12-10 11:48:58 UTC
> It would be better for us to expose specific things as needed by people in a higher level language, similar to how sublime does it

That is basically what I'm asking: allowing to write extensions/plugins in a different language. You're just doing it on request per feature rather than the entire API at once. And I get why you're doing that, that's fine. However right now I have no clue at all where to start with that. That scripting API seems promising, would adding a script add it to the "Plugins" list in Kate? In a quick local test it seems not.

As for what I'd personally like: I'd like to get my Python development workflow going. For that Kate needs to support Python's virtual environments (so it automatically opens the terminal with it activated and runs additional commands inside that virtualenv) and some additionals tools like the Ruff formatter. To me this seemed like good reasons to build a plugin.
Comment 5 Waqar Ahmed 2024-12-10 12:34:34 UTC
> would adding a script add it to the "Plugins" list in Kate? In a quick local test it seems not.

No. Scripts are limited to the current document. You execute them in the command bar (F7) or via shortcuts or via menu actions. I think the docs cover this. Some example built in scripts: https://invent.kde.org/frameworks/ktexteditor/-/blob/master/src/script/data/commands/utils.js You can find some of them if you right click and check the "Editing" submenu and others inside Tools->Scripts main menu.

> As for what I'd personally like: I'd like to get my Python development workflow going. For that Kate needs to support Python's virtual environments (so it automatically opens the terminal with it activated and runs additional commands inside that virtualenv) 

So I think this would be possible within our current scripting framework with some extra work. Some things need to be exposed. I mentioned earlier that a script is limited to a document, this is true but it can access other commands exposed by kate c++ plugins, see view.executeCommand. So, to do something like what you want, the "project plugin" can expose commands that allow you to execute stuff in the terminal.

> and some additionals tools like the Ruff formatter. To me this seemed like good reasons to build a plugin.

Ruff formatter is available in the formatting plugin already if you would like to use it.
Comment 6 Christoph Cullmann 2024-12-10 20:08:31 UTC
To support the Python workflow better a plugin or extensions to the build plugin would be nice, atm the only really feasible way is to use C++ for that. So far the Python bindings we tried to add again did not work out.
Comment 7 Waqar Ahmed 2025-01-02 06:59:22 UTC
This is done via https://invent.kde.org/utilities/kate/-/merge_requests/1672

We can extend and improve things as needed.