KDevelop - ExternalScript plugin

Heyho, me again :)

Seems like I have quite the urge to write blog posts recently… Anyhow:

The last two days I reimplemented / ported two features from Quanta 3 times to KDevelop (if you still didn’t get it: everything is a plugin, hece it will be reused in Quanta 4). What I’m talking about is most importantly the revival of a “execute external script” plugin. It’s currently still in a feature branch, but will hopefully be merged into master soon. But what can you do with it? Well, think about the following usecases and see how they can be solved with this plugin:

I want to compile and run a simple helloworld.cpp-like file without setting up a build environment nor do I want to setup a project for it.

Use an external script: _quick compile_. It just runs this command: `g++ -o %b %f && ./%f`   In this code `%f` gets replaced with the path to the currently active file and`%b` is it’s basename (i.e. without extension).

I want to sort / uniq / … the selection in the current document.

Here you can either use [Kate Scripts](, which gives you the same features. But to show you the capabilities of the external script plugin, this is a good example:   Setup an external script, that gets the current selection (or the whole file if nothing is selected) piped into it’s `STDIN` and let the selection (or, again, the whole file if nothing was selected) in the active document get replaced by the `STDOUT` of the external script. I’ve added an example doing just that.

I want to google for the selection in the active document.

I got this example from the _External Tools_ plugin for Kate, and made it possible to do that with the new plugin in KDevelop. Simply use the following script: `xdg-open ""`   Note: `%s` gets replaced by the shell-escaped version of the selected text in the document.

I want to run an external syntax checker on my file / folder / …

Simply use an external script for it :) With the various `%...` placeholders it should be easy enough to do.

Here are a few screenshots showing the tool in action:

Second feature that I pushed in, which you can also see in action for the external scripts, is the possibility to assign shortcuts to snippets and external scripts. Eventually I’ll also try to bring back the “user toolbars” from Quanta 3 times, but I hope to do that properly inside KDELibs for reuse by other applications.

Another thing: In Quanta 3 times it was easier to create external scripts that showed some UI and asked for more user input. This is not possible since Kommander (which was used back then) is not available nowadays. If someone polishes the afaik halfway working port, I’m willing to implement it again. Anyhow I think nowadays one should use Qt Designer and Ruby or Python bindings to create UIs. Sure, a bit harder but much more powerful.

But well, now it’s your turn to write cool external scripts :) And to give me feedback: What kind of scripts would you write? What %... placeholders do you need?

PS: Even though I booked flights and accommodation ages ago, I haven’t yet announced it in proper KDE-style yet:

I'm going to Akademy 2010


Want to comment? Send me an email!

Published on June 16, 2010.