Maximum impact, minimum code

Hi Planet KDE!

You might already know me from 2006 or 2007, but currently I'm gone from KDE because of other commitments. So technically you shouldn't hear from me right now; however, my buddy klausi drove me to it.

Surprising high amounts of KDE coders use non-KDE technology like vi or emacs to hack on KDE, and mostly they've got good reasons to do so. The only option to get those people use Kate or KDevelop is to continually improve those. The respective developer teams are doing awesome work in that regard, while my contribution for today is just a small KTextEditor plugin. (Which means you can use it in Kate, KDevelop or whatever KatePart-based editors exist out there.)

The plugin is called AutoBrace and, frankly, an uninspired clone of the best feature that you'll find in Eclipse (apart from the compile-as-you-go automatism and sheer infinite amounts of complexity). Right, it's the automatic insertion of a closing brace ("}") after you ended a line with an opening one ("{"). Kate's standard insertion of parentheses, brackets and braces is simply too obtrusive for me, so even if I tried it several times I always had to disable it again because I can't stand it. So here's how AutoBrace works.

  1. You, the developer, are writing a line of code, and want to open a new block delimited by braces. Looks like this:

  1. If you press Enter and AutoBrace is enabled, it will insert your favorite new brace where it belongs. Looks like this:

It's no big deal in the code - actually, I should be embarrassed to blog about such a minor thing when other people are continuously rocking KDE with stuff like SVG support in KHTML (new), a whole new power management solution for KDE (relatively new), or a window manager that's just terrific (not new, but still awesome).

But I've got no scruples, so here's your blog post anyways. You can get AutoBrace right now for your current Kate, you just need to compile it beforehand. Here is where I put it. See you some other time!

Comments

thanks for sharing, I'll

thanks for sharing, I'll definitely use it!

:w

Well, the main problem with using Kate is that after a while I get a bunch of ':w not recognized' syntax errors :)

:P

My suspicion is that this shortcoming will be fixed in the Kate version that comes with KDE 4.2, as the vi-workalike-mode has already been merged into trunk :D

Thanks for your contribution

It's no big deal in the code - actually, I should be embarrassed to blog about such a minor thing when other people are continuously rocking KDE with stuff like SVG support in KHTML (new), a whole new power management solution for KDE (relatively new), or a window manager that's just terrific (not new, but still awesome).

Do not feel embarrassed at all! You actually created something useful, instead of reinventing the wheel (or, I don't know, rewriting the kernel USB stack for the n-th time, creating a brand new desktop metaphor or revolutionizing yet again the way people think or work with the computer) just because you felt like it. Thank you!

Too bad this is only for braces

Its too bad this only works for braces. I wanted to use it to disable auto-bracketing in kate, because that completely breaks indentation and apparently kate devs don't have time to fix that.

Use case, please

Of course I don't promise anything, but I did consider adding a configuration dialog where you specify the characters that the plugin should trigger on. I left it out because I couldn't think of an actual use case that's useful for parentheses and brackets - those always need some more love, like a trailing semicolon or comma.

At least for the use cases that I could think of. If you can list other cases where this makes sense for brackets or parentheses too, I might (might. not will.) make the characters configurable.

Made my day

This absolutely made my day
Say it with me:
"This is not Drupal code. I will use 4 spaces for indentation."
"This is not Drupal code. I will use 4 spaces for indentation."
"This is not Drupal code. I will use 4 spaces for indentation."

  • Kyle Cunningham

auto-tab too?

I notice it produces a new line and a brace after that new line when you press enter. Though, the obvious key the user will press next is 'Tab'. Why not automate this too?
Of course, like vi, the tab can be translated to four spaces or whatever the project uses.

two reasons for that

  1. The KTextEditor interfaces don't offer any way to indent stuff, so the only way I can have indentation is to a) copy over the existing whitespace/tabs (which is what I do for the line with the brace) or b) try if the KTextEditor::View is actually implemented by Kate (which is probable) and call the indent() method on that one. I had already implemented the latter, but had to remove it because of the other reason:

  2. If I try to indent an empty line, the indenter scripts get in my way and do it the way they want to. So I even if AutoBrace indents the empty line perfectly fine, the indentation gets overridden by the current indenter script, I don't think I can do anything against that (nor should I, it's not the plugin's responsibility). The one shown on the screenshot is the Normal indenter which I'm normally using. If you're using the C indenter though, you get your empty line indented automatically with a tab like it should be.

one is gone

While solving the remaining problems of the plugin (crashes and messing up pasted text) I solved the technical issues that prevented indentations - those work nicely now if I enable the code. But I'm still not doing that, as the indenter scripts are still responsible for indenting all that stuff.

So the code is there, but probably the indentation system should be made so seamless that you get correct indentations automatically all of the time, without even thinking of which indenter is currently enabled.

:)

Great to see you around! You have done awesome work and I believe we all hope you'll be back. So this sign of life is a good thing. :)

doh

I need to find a way to disable links (for protection against spam) while still allowing one's name to be entered. Reading comments is only half the fun if you don't know where the kind words come from :P

great

I love such small enhancements in kate.

But what would REALLY rock would be auto code completion...

hmm...

Did someone say "KDevelop 4"? At the very least, I remember someone saying "It's gonna be great, you're gonna love it!". And you will, as will I, too :P