/* kate-scriptThe header line functions: sorter makes Kate Part aware of the function in the script. A list of functions is supported, separated by white spaces. You can use the function by typing 'sorter' in the commandline.
* name: unused
* author: foo bar
* license: LGPL
* version: 1
* kate-version: 3.0
* functions: sorter
*/
function sorter ()
{
if (view.hasSelection()) {
var start = view.startOfSelection().line;
var end = view.endOfSelection().line;
var text = document.textRange(start, 0, end, document.lineLength(end));
var lines = text.split("\n");
lines.sort();
text = lines.join("\n");
view.clearSelection();
document.editBegin();
document.removeText(start, 0, end, document.lineLength(end));
document.insertText(start, 0, text);
document.editEnd();
}
}
Some todo items:
- provide better JavaScript API. For example: document.textRange() takes 4 parameters. It would be more elegant to take one range or two cursors, just like we do in the KTextEditor interfaces in kdelibs/interfaces/ktexteditor
- make is possible to bind scripts to shortcuts. This could be done by e.g. binding commandline functions to shortcuts or implementing a vim-like command-mode in Kate's commandline. How to configure the shortcuts is unclear, though.
- then, think about replacing the C++ implementations of 'uppercase', 'lowercase', 'capitalize' etc. with scripts
- things I forgot...