BlogKate Love: HighlightInterface, Autobrace Syndicate content

Sun, 11/22/2009 - 20:15

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 with class or struct (C++ mode only)
  • don’t add brace when current line contains class, interface or struct and the following line contains private, public, protected. C++ code is also checked for signals, Q_SIGNALS", other modes are checked forfunction`.

This should fix the bug for code like (note the indendation levels):

  1. namespace foo { // insert line here
  2. class bar;
  3. }
  4. class asdf { // insert line here
  5. private:
  6. ...
  7. };

Comments

Does kate already have Sun, 01/17/2010 - 06:11 — chandra (not verified)

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.

First of all: No, kate Sun, 01/17/2010 - 13:27 — Milian Wolff

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!

i am not sure if this is the Sun, 11/29/2009 - 03:29 — vasilis (not verified)

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

no, not possible. use Sun, 11/29/2009 - 13:01 — Milian Wolff

no, not possible. use kdevelop 4 or qt creator for that.

Thanx for the quick answer:-) Sun, 11/29/2009 - 19:10 — vasilis (not verified)

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

yes, katepart is used in Sat, 12/12/2009 - 18:09 — Milian Wolff

yes, katepart is used in kdevelop. no, if you want kdevelop features, use kdevelop - not kate.

Well, I don’t really Mon, 11/23/2009 - 21:43 — DanaKil (not verified)

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>, <a>…), 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 :)

No, not related to the post Mon, 11/23/2009 - 23:48 — Milian Wolff

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.

Good to hear your progress Mon, 11/23/2009 - 00:40 — Jurian Sluiman (not verified)

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 :)

I completely agree with Mon, 02/15/2010 - 09:24 — rpedersen (not verified)

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.

regarding the Jurian Mon, 11/23/2009 - 09:29 — ZeD (not verified)

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.

Take a look at NetBeans. Mon, 02/15/2010 - 11:12 — Frank (not verified)

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(…))).

I think that this might be Mon, 11/23/2009 - 18:45 — Milian Wolff

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.

Post new comment

  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <pre>.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options