Author Topic: indent/unindent plugin  (Read 13225 times)

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 205
indent/unindent plugin
« 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:
  • Add an interface to cbEditor (two static methods and some static attributes) to register/unregister a function-pointer corresponding to a lexer number.
  • A plugin has to register (set function pointer(s)) for a specific language (wxSCI_LEX_CPP or wxSCI_LEX...) in the attach method and to unregister in the detach method.
  • In the OnEditorCharAdded method select the function corresponding to the current lexer.

Advantages:
  • It is not needed to change cbEditor to add a new language.
  • Only the needed languages can be loaded.
  • An unstable indent/unindent mechanism can be disabled.
Disadvantages:
  • We have to provide a way to acces functions like GetLastNonWhitespaceChar() and FindBlockStart() from these plugins to reuse them.
  • Speed?
  • If the "repeat" mechanism is useful for other languages too, we should provide a way to use the same wxTimer object. A timer is a finite resource.

What do you think?


Thank you very much for developing Code::Blocks!



[attachment deleted by admin]

Offline dje

  • Lives here!
  • ****
  • Posts: 682
Re: indent/unindent plugin
« Reply #1 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

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 205
Re: indent/unindent plugin
« Reply #2 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?
« Last Edit: June 02, 2008, 07:05:35 am by danselmi »

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 205
Re: indent/unindent plugin
« Reply #3 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

Offline dje

  • Lives here!
  • ****
  • Posts: 682
Re: indent/unindent plugin
« Reply #4 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

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 205
Re: indent/unindent plugin
« Reply #5 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

Offline dje

  • Lives here!
  • ****
  • Posts: 682
Re: indent/unindent plugin
« Reply #6 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

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 205
Re: indent/unindent plugin
« Reply #7 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

Offline dje

  • Lives here!
  • ****
  • Posts: 682
Re: indent/unindent plugin
« Reply #8 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

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 205
Re: indent/unindent plugin
« Reply #9 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:
  • check if the user entered a '\n' (OnCharAdded)
  • check the last non comment word/character
  • if the last word is a "begin" (example for Verilog) indent the new line

unindent:
  • If the added character was not a '\n'
  • check if the current line contains only "end" and spaces
  • search the corresponding "begin"
  • indent the current line to the same value as the line containing the "begin"

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
« Last Edit: June 18, 2008, 09:29:21 am by danselmi »

Offline dje

  • Lives here!
  • ****
  • Posts: 682
Re: indent/unindent plugin
« Reply #10 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

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 205
Re: indent/unindent plugin
« Reply #11 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

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 205
Re: indent/unindent plugin
« Reply #12 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