Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: danselmi on June 01, 2008, 03:46:59 pm

Title: indent/unindent plugin
Post by: danselmi on June 01, 2008, 03:46:59 pm
Hello

I use codeblocks for HDL editing (on my every day job) so i added indent/unindent mechanism for vhdl and verilog.
For vhdl I also added the feature that codeblocks replaces the three characters ',' '.' and ';' if they are repeated (pressed twice in 400 ms behind each other):
,, will be replaced with <=  .. will be replaced with =>  and  ;; will be replaced with :=


Am I right, that it is not yet possible to implement indent/unindent through a plugin?

I think this should be easy:

Advantages:
Disadvantages:

What do you think?


Thank you very much for developing Code::Blocks!



[attachment deleted by admin]
Title: Re: indent/unindent plugin
Post by: dje on June 01, 2008, 04:04:21 pm
Hi !

With current plugin architecture, you can add items to menu, contextual menu and editors.
I don't understand why you could succeed in implementing a plugin that match your need.

Dje
Title: Re: indent/unindent plugin
Post by: danselmi on June 01, 2008, 08:05:45 pm
Hi

As you could see in the attachment from the previous post: I have not implemented these features
in a plugin but in the core.

My question was if this is the right place or if it would be better to extend the archtecture to make these
things possible in a plugin and not only in the core.
Further i have drawn a way to implement this interface to the current architecture (and reviewed it roughly).
I have not realized these changes. First I'd like to get some feedback.

Daniel

Edit: perhaps this is the wrong place for this post?
Title: Re: indent/unindent plugin
Post by: danselmi on June 09, 2008, 01:45:25 pm
Hi

Is there a plan to extend the plugin architecture to implement indent/unindent in a plugin?

You can find pros/cons in my first post.

Daniel
Title: Re: indent/unindent plugin
Post by: dje on June 09, 2008, 01:56:00 pm
Hi !

I think your need is too specific to be implemented in the core.
I personnally use ... in my comments and wouldn't like to see something else happen.

Plugin API is stable since C::B 8.02. That was a requirement to release it.
I see no reason in what you want to do to change it.

I think you should be more precise on your problem, maybe no change is required.
If you need a new feature, you can post it at BerliOS

Dje
Title: Re: indent/unindent plugin
Post by: danselmi on June 09, 2008, 02:12:10 pm
Hi

Do you really think it is too specific to be able to implement indent for an additional
language in a plugin? So you do not have to change the core for every
language someone wants to use?

Should I send a patch for the indent of the two HD languages?


Daniel
Title: Re: indent/unindent plugin
Post by: dje on June 09, 2008, 02:18:06 pm
Do you really think it is too specific to be able to implement indent for an additional
language in a plugin?
No, you can do whatever you want in a plugin, I said it is too specific to be implemented in the core.

Should I send a patch for the indent of the two HD languages?
You can, but I am a plugin developer and I don't take any decision concerning the core or patches.

When you tell
Quote
extend the plugin architecture
, do you mean a change in the API (what I understood) or to propose a new plugin ?

Dje
Title: Re: indent/unindent plugin
Post by: danselmi on June 09, 2008, 02:31:04 pm
Hi

As you mentioned in your first answer:
Quote
With current plugin architecture, you can add items to menu, contextual menu and editors.
I don't understand why you could succeed in implementing a plugin that match your need.

And in the previous post:
Quote
No, you can do whatever you want in a plugin,...

How is it possible to implement indent/unindent in a plugin? Isn't it needed to extend the plugin
architecture (I mean a change in the API) to be able to do this?


Daniel
Title: Re: indent/unindent plugin
Post by: dje on June 09, 2008, 02:45:59 pm
I don't remember in details the API of the editor, check the events you can register in C::B source code.
Maybe the one you need already exist.
Otherwise, you may trigger editor open event to play with its dynamic event table, but it begins beeing a little tricky.

Do you know AStyle plugin ?
It is a plugin that only does indentation, but it works on files, not on open editors.
It is also the most simple way to work, unless you just add a menu entry with the appropriate shortcut to indent when you want.

I think it would be better to tell exactly what you need, you won't get help with
Quote
How is it possible to implement indent/unindent in a plugin?
or
Quote
Isn't it needed to extend the plugin
architecture (I mean a change in the API) to be able to do this?
With those quotes, I guess you need something but I can't figure out what  :shock:

Dje
Title: Re: indent/unindent plugin
Post by: danselmi on June 17, 2008, 09:57:51 pm
Hi

Thanks for your patience!

I'd like to do auto indent/unindent for another language (VHDL and
Verilog in addition to c/c++, which is implemented in the core).

indent:

unindent:

This is near the same mechanism as for C/C++, only the '{' is replaced with "begin"
and the '}' is replaced with "end". For VHDL it is a bit more complicated because we
have to check for more different words/characters but basically it remains
the same mechanism.

As you could see in my first post, I have implemented these things (and the
mechanism which replaces ,, .. ;; with <= => := if they get typed fast enough) in the core.
Now i'd like to share this work (and do some more if needed) with other people.
Because VHDL and Verilog are not that widely used i think it is not realistic to get
these changes in the core.

If I have to implement these features in a plugin, I am not sure which event to
register to cbEVT_EDITOR_MODIFIED? And will this be fast enough?

Daniel
Title: Re: indent/unindent plugin
Post by: dje on June 17, 2008, 10:09:22 pm
Hi !

Unless I'm wrong, on Mac, you don't have '\n' but '\r'.
I am not a mac expert... can anyone confirm this ?

Dje
Title: Re: indent/unindent plugin
Post by: danselmi on June 18, 2008, 09:48:34 pm
Hi

Is the implementation for c/c++ not working on Mac?
Anyhow if needed this will be easy to solve.

Daniel
Title: Re: indent/unindent plugin
Post by: danselmi on July 07, 2008, 03:19:10 pm
Hi

I've found the answer myself: "EditorHooks"
Implement the functionality in a HookFunctorBase derived class.
In the plugin register the hook in OnAttach and Unregister in OnRelease.

Daniel