Kate Love: HighlightInterface, Autobrace
Well, I have to admit: I didn’t spent much time developing the PHP plugin for KDevelop these past weeks. Instead I hacked on Kate:
HighlightInterface
I added another Kate interface, this time to access some of the highlighting information:
- what’s the Attribute for a given default style right now? Default styles are those known from syntax files, e.g.
dsKeyword
,dsFunction
,… - what are used Attributes in a given line and what range do they occupy?
- what modes do we embed? E.g. PHP embeds HTML, JavaScript, CSS, …
- what mode is used at a given Cursor position?
This made it possible to port the “Export to HTML” action to a real plugin. If you come up with other output formats I might add them, I wondered about LaTeX support… might do this at some point.
This should also make it possible to use KatePart in other applications and than export the highlighting to a different format, e.g. a Flake shape for Koffice. Afaik this is actually planned by The_User - lets see if it works out!
The other stuff gives huge potential in various places, but I fear it won’t make it in KDE 4.4. But think of it:
- simple code completion based on keyword databases, dependent on the mode at the position where completion was requested
- same as above for snippets (actually this will make it to 4.4).
- insert your ideas here :)
Auto-Brace plugin
Jakob Petsovits created this gem of a plugin some time ago, yet it lived in playground was probably only used by few. I imported it to kdelibs, hence it will be shipped with KDE 4.4. It supersedes the limited “auto-brackets” feature of Kate and only adds braces when a newline gets added. I find this fits my personal coding habits much better than blindly copying brackets when they get added.
And I don’t just copied to kdelibs, I also added a few features:
- automatically add a semicolon after the closing brace when we start a new struct/class in C++ mode
- check for auto-brackets feature and disable it automatically
Also did this:
- don’t add brace when current line contains
namespace
and a following line starts withclass
orstruct
(C++ mode only) - don’t add brace when current line contains
class
,interface
orstruct
and the following line containsprivate
,public
,protected
. C++ code is also checked forsignals
,Q_SIGNALS", other modes are checked for
function`.
This should fix the bug for code like (note the indendation levels):
namespace foo { // insert line here
class bar;
}
class asdf { // insert line here
private:
...
};
Comments
Want to comment? Send me an email!
Comment by Anonymous (2016-03-21 06:32:00)
The new version of it looks really nice. It is much more stable and faster than the previous versions that I have laid my hands on too. I am sure it will be taken in by a lot of users much more. :::
Comment by chandra (not verified) (2010-01-17 06:11:00)
Does kate already have automatic HTML tag completion so that when <p> is typed, it will insert a </p> intermediately like kile can do with LaTeX environments? If so, how may I get to use it? If not, is it likely to be available anytime soon? I am on KDE 4 with Kubuntu 9.10.
Thanks.
Comment by Milian Wolff (2010-01-17 13:27:00)
First of all: No, kate doesn’t have this feature so far, but it is definitely something useful.
Take a look at bugs.kde.org and see whether the feature is already requested there, if not: do so! Someone should implement something like that sooner rather than later and with the TemplateInterface something like that should not be very hard to do. Lets see when I or whoever comes around to do it, no promises here!
Comment by vasilis (not verified) (2009-11-29 03:29:00)
i am not sure if this is the correct place to post my action but i am desperate:-(
is it possible to have code completion in kate when writing c++ code like you can in have in kdevelop3/4 or qrcreator?? Could not find a way to do this. I tried with the ctags plugins, created a couple of .ctags databases (/usr/inlude/Qt*, current directory and others), adding the database but kate did not show any change. Could someone tell me if this is doable and how i can have this option? I don’t need the easy word completion model but the c++ one, e.g. for Qt.
thanx
vasilis
Comment by Milian Wolff (2009-11-29 13:01:00)
no, not possible. use kdevelop 4 or qt creator for that.
Comment by vasilis (not verified) (2009-11-29 19:10:00)
Thanx for the quick answer:-) At last now i know that this is not possible. However, as fas as i know, kate is being used as the editor of choice in kdevelop4. correct? Is it somehow possible to use the libraries used for code completion shipped with kdevelop4 or qtcreator and get these options??
vasilis
Comment by Milian Wolff (2009-12-12 18:09:00)
yes, katepart is used in kdevelop. no, if you want kdevelop features, use kdevelop - not kate.
Comment by DanaKil (not verified) (2009-11-23 21:43:00)
Well, I don’t really understand all what you said about the HighlightInterface but I will “insert an idea here” since it’s about highlighting :)
I use Notepad++ (http://notepad-plus.sourceforge.net/uk/site.htm) for all my HTML/PHP editing needs. When the cursor is on an html tag (<div>, </div>, …), it has the ability to auto highlight the corresponding closing or opening tag. This is like the “highlight braces” feature of Kate.
An other feature from notepad++ related to highlighting is that when you select a word (something surrounded by spaces, comma,…), all others similar words in the page are automatically highlighted.
…sorry if it wasn’t really related to your post :)
Comment by Milian Wolff (2009-11-23 23:48:00)
No, not related to the post :P
But the former idea I find useful (meaning: I’ll implement it once I work on HTML support for KDevelop), while the latter is implemented in KDevelop, albeit more sophisticated: When you highlight a declaration, definition or use, all other uses are highlighted in the current document.
Comment by Jurian Sluiman (not verified) (2009-11-23 00:40:00)
Good to hear your progress about Kate, KDevelop and the php plugin (this and your previous posts)! And I’d like to issue something immediately ;)
I’m used to Eclipse and am trying to use KDevelop because of the better integration into KDE. One thing I miss is an intelligent auto brackets function. I’m writing 99% php code and you use the () and {} quite often. Typing “function foo(” creates with auto brackets a “)” behind. This is a very useful option because you never forget a closing bracket anymore.
Nevertheless it happens you need to write something in between. So the cursor is between the ( ). Let’s say I add two parameters $bar and $baz (“function foo($bar, $baz)”). Now I’m in front of the closing ). In Kate you need to press your arrow button to step behind the character. It’s not (at least for me) the best option in terms of usability.
Now the magic: Eclipse knows the ) bracket belonds to the prior ( -hence the syntax highlighting as well. If I type a ) character, the ) isn’t added, but Eclipse passes the existing ) and now the cursor is behind the ). It sounds perhaps a bit difficult, but when you’re used to it you can write code a lot faster. How am I able to issue this properly? Thanks in advance :)
Comment by rpedersen (not verified) (2010-02-15 09:24:00)
I completely agree with Jurian. The auto brackets function is completely useless if it doesn’t do this. In fact, I have never had this function enabled in kate/kdevelop, but I did in other editors, and the difference is the behavior described above.
Comment by ZeD (not verified) (2009-11-23 09:29:00)
regarding the Jurian suggestion: please DON’T do it! >_<
At work I use eclipse and I never understand the logic of this behaviour. I always try to move the cursor with the arrows (generally CTRL-arrow, but that’s not the point) and I always remain stopped at the same position.
Moreover, i cannot add a real new close parentesis… (let’s say I have want I want to write foo(bar(…)), I always end in something like foo(bar( )…
I really miss Kate/KDevelop behaviour.
Comment by Frank (not verified) (2010-02-15 11:12:00)
Take a look at NetBeans. There they solved the issue. You can push -> to skip the closing braces, or you type them and NetBeans skips them. If you type foo(bar(…)), NetBeans will exactly type this. You can even type foo(bar(…))).
Comment by Milian Wolff (2009-11-23 18:45:00)
I think that this might be handy, and also would like it (of course as an optional setting). Imo an editor should adapt as much as possible to the user, and when it is implemented somewhat intelligently it might be useful. Lets see, maybe I’ll do something like that with the autobrace plugin for KDE 4.5.