Reply to topic

Kate: scripts or external tools

jerry1970
Registered Member
Posts
1
Karma
0

Kate: scripts or external tools

Fri Mar 12, 2021 10:06 am
Hi all,

I am trying to add functionality to Kate but although I see documentation I am missing some info to start.

As an example, I'd like to create a script to surround the selected text in the editor with underscores, so it's in italics in a Markdown document, and then assign a shortcut Ctrl-Shift-I to that script.

First of all, I am on Ubuntu 20 with XFCE, using Kate 19.12.3 with KatePart 5.68.0. The $XDG_DATA_HOME variable is not set and I cannot find anything on indentation. I have one instance of katepart5 and that is the folder /usr/share/katepart5 which has a sub folder scripts that is empty.

Under Tools > Scripts there are Emmet, Navigation, Quick Coding, and Editing. And there is Tools > External Tools, which I see are configured in the Setting > Configure Kate > External Tools.

My questions are:
Using the kjs/KateScript/javascript sounded easiest, but where do the files go?
I assume these will show up under Scripts. Is that correct? Is there a way to group any more scripts like Emmet, Navigation, etc.?
Shouldn't the scripts already in the menu be somewhere on disc?

I also read this: "Developing an indenter requires reloading the scripts to see whether the changes behave appropriately. Instead of restarting the application, simply switch to the command line and invoke the command reload-scripts."
That "the command line" - is that Tools > Focus Terminal? It will show a docked window but no terminal there. Reloading scripts without having to close and reopen Kate would be very nice, of course.

I hope someone can help give me a few tips on how to get started.
User avatar pvzh
Registered Member
Posts
14
Karma
0
OS

Re: Kate: scripts or external tools

Fri Mar 12, 2021 2:09 pm
Hello! I also like to add commands to Kate.

Scripts (*.js files) must be placed in the directory ~/.local/share/katepart5/script/commands
For convenience, I created a link to it inside Documents folder.

You can of course create groups for your scripts. This is set in the script itself:
category [optional]: If a category is specified, the script appears in a submenu.

https://docs.kde.org/stable5/en/applica ... pting.html
User avatar pvzh
Registered Member
Posts
14
Karma
0
OS

Re: Kate: scripts or external tools

Fri Mar 12, 2021 2:18 pm
jerry1970 wrote:I also read this: "Developing an indenter requires reloading the scripts to see whether the changes behave appropriately. Instead of restarting the application, simply switch to the command line and invoke the command reload-scripts."


This refers to the Command line from the View menu (F7). Try to press F7 and enter help or help list.
User avatar pvzh
Registered Member
Posts
14
Karma
0
OS

Re: Kate: scripts or external tools

Fri Mar 12, 2021 2:31 pm
jerry1970 wrote:I'd like to create a script to surround the selected text in the editor with underscores, so it's in italics in a Markdown document


I made a draft, saved it as a file ~/.local/share/katepart5/script/commands/markdown.js and run command reload-scripts - it works!

Code: Select all
var katescript = {
    "author": "Average user",
    "license": "LGPLv2+",
    "revision": 1,
    "kate-version": "19",
    "functions": ["mdItalic"],
    "actions": [{
        "function": "mdItalic",
        "name": "Italic style",
        "category": "Markdown",
        "interactive": "false"
    }]
}; // kate-script-header, must be at the start of the file without comments

require('range.js');

function mdItalic() {
    var selection = view.selection();
    if (!selection.isValid()) {
        return;
    }

    // some kind of text conversion
    var text = document.text(selection);
    text = '_' + text + '_';

    view.clearSelection();
    document.editBegin();
    document.removeText(selection);
    document.insertText(selection.start, text);
    document.editEnd();
}

 
Reply to topic

Bookmarks



Who is online

Registered users: allirion, Baidu [Spider], Bing [Bot], duns, Google [Bot], Ignacio Serantes, markhm, mfraser, rblackwell, Sogou [Bot], Termy, terra, thunder422, tubbadu, Yahoo [Bot]