GNU/Linux Snippet Wrapping Text Kate – Quick-Start Guide
Hi! This tutorial will guide you step-by-step on How to make a Snippet Wrapping Text Selection in Html on Kate for GNU/Linux.
Kate, the KDE text editor, supports code snippets to automate repetitive typing tasks. While the snippets themselves are plain text, you can leverage JavaScript functions to add dynamic behavior.
Here's a quick rundown:
- Basic Snippets: You can define static snippets with placeholder text. Kate inserts these snippets upon triggering a keyword.
- JavaScript in Snippets: Kate allows embedding JavaScript functions within snippets using
${fn
followed by the function name and closing curly brace. These functions can interact with the editor and snippet itself.
Functionality with Scripts:
There isn't extensive documentation on Kate's snippet scripting, but some functionalities include:
- Accessing information like filename using
fn
functions likegetFileName
. - Potentially manipulating the snippet text based on user selection using functions like
getSelect
(functionality might be limited).
Learning More:
While official documentation might be scarce, you can find resources online to get you started:
- Blog post discussing snippets and
fn
functions: [Kate snippets with script ON Milian Wolff milianw.de] - Example snippet with JavaScript functions on GitHub (though it focuses on autocompletion): [GitHub kate javascript snippet ON github.com]
Keep in mind: Scripting capabilities for Kate snippets might be limited compared to more advanced code editors.
Just follow the instructions given in the Default Kate Snippets Official Documentation!
1. Making Script
First, create the Javascript Script
Like:function rangeCommand(command, def) { if (view.selectedText().length > 0) { return command.replace("%%1", view.selectedText()); } else { return command.replace("%%1", def); } }
Customize at your flavor following the Kate API Docs…
The def Var represent the Default substitution.2. Setting Snippet
Now to make use of the Kate Javascript Snipped
Put something like this as definition:${rangeCommand("lgt;strongrgt;%%1lgt;/strongrgt;", "")}
Just replace “strong” in the above as you need.
Enjoy your Kate Enhancement! :)