Hi,
In my GeanyGenDoc plugin I was using sci_insert_text() to insert the generated documentation comment; but I wanted to be able to indent the inserted comment to follow the indentation at the insertion position.
I found editor_insert_text_block() which seemed quite interesting, but it didn't do what I expected -- and still no indentation. Of course when going a bit in the code, since I inserted my comment at the start of the line, and editor_insert_text_block() adds the indentation that is found between the start of the line and the insertion position… which are the same in my case. Then, I wondered how to fix my problem, and finally found a solution that consists to insert at start of line + sci_get_line_indentation() [1].
But I have some questions: 1) How editor_insert_text_block() is meant to be used to get the right indentation, since (if I'm right) we need to insert at the right position in the first line? Is the solution I've found the right one, or is there a cleaner/simpler solution? 2) If this is a good way to proceed, could we have sci_get_line_indentation() in the plugin API? Even though it is easy to reproduce [2] it would be nicer to have it directly.
Regards, Colomban
[1] http://geany-plugins.svn.sourceforge.net/viewvc/geany-plugins/trunk/geanygen... [2] http://geany-plugins.svn.sourceforge.net/viewvc/geany-plugins/trunk/geanygen...
On Thu, 29 Apr 2010 00:28:02 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
In my GeanyGenDoc plugin I was using sci_insert_text() to insert the generated documentation comment; but I wanted to be able to indent the inserted comment to follow the indentation at the insertion position.
I found editor_insert_text_block() which seemed quite interesting, but it didn't do what I expected -- and still no indentation. Of course when going a bit in the code, since I inserted my comment at the start of the line, and editor_insert_text_block() adds the indentation that is found between the start of the line and the insertion position… which are the same in my case. Then, I wondered how to fix my problem, and finally found a solution that consists to insert at start of line + sci_get_line_indentation() [1].
But I have some questions:
- How editor_insert_text_block() is meant to be used to get the right
indentation, since (if I'm right) we need to insert at the right position in the first line? Is the solution I've found the right one, or is there a cleaner/simpler solution?
Can you give a code example of what you're trying to do?
- If this is a good way to proceed, could we have
sci_get_line_indentation() in the plugin API? Even though it is easy to reproduce [2] it would be nicer to have it directly.
We can do, send a patch if you like. It sounds like it might be better to use editor_insert_text_block in this case.
Regards, Nick
Nick Treleaven a écrit :
On Thu, 29 Apr 2010 00:28:02 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
In my GeanyGenDoc plugin I was using sci_insert_text() to insert the generated documentation comment; but I wanted to be able to indent the inserted comment to follow the indentation at the insertion position.
I found editor_insert_text_block() which seemed quite interesting, but it didn't do what I expected -- and still no indentation. Of course when going a bit in the code, since I inserted my comment at the start of the line, and editor_insert_text_block() adds the indentation that is found between the start of the line and the insertion position… which are the same in my case. Then, I wondered how to fix my problem, and finally found a solution that consists to insert at start of line + sci_get_line_indentation() [1].
But I have some questions:
- How editor_insert_text_block() is meant to be used to get the right
indentation, since (if I'm right) we need to insert at the right position in the first line? Is the solution I've found the right one, or is there a cleaner/simpler solution?
Can you give a code example of what you're trying to do?
The real code can be found only through SF's VC viewer: http://geany-plugins.svn.sourceforge.net/viewvc/geany-plugins/trunk/geanygen...
But let's explain a bit: I would insert a text block, and indent it to respect the indentation of the insertion's line. What I do is: 1) build a text block (line 326); 2) find *the line* at which insert it (I don't know the position, only the line -- this is from a tag) at the start (lines 338-339); 3) convert that line information to position information as needed (lines 340-343); 4) insert the text block (line 351).
Of course step 3 is an implementation detail, and it's where I have the "problem". My question is: "how am I supposed to insert a text block at the start of a particular *line* for it to be indented as this line is indented?"
- If this is a good way to proceed, could we have
sci_get_line_indentation() in the plugin API? Even though it is easy to reproduce [2] it would be nicer to have it directly.
We can do, send a patch if you like. It sounds like it might be better to use editor_insert_text_block in this case.
Yeah I do so but it needs to already know at which *position* insert the block. And the position where I want to insert is something like the "smart start" of the line (start of the line + indentation).
Thanks for responding :) Colomban
On Thu, 29 Apr 2010 19:13:25 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
Can you give a code example of what you're trying to do?
The real code can be found only through SF's VC viewer: http://geany-plugins.svn.sourceforge.net/viewvc/geany-plugins/trunk/geanygen...
But let's explain a bit: I would insert a text block, and indent it to respect the indentation of the insertion's line. What I do is:
- build a text block (line 326);
- find *the line* at which insert it (I don't know the position, only
the line -- this is from a tag) at the start (lines 338-339); 3) convert that line information to position information as needed (lines 340-343); 4) insert the text block (line 351).
Of course step 3 is an implementation detail, and it's where I have the "problem". My question is: "how am I supposed to insert a text block at the start of a particular *line* for it to be indented as this line is indented?"
- If this is a good way to proceed, could we have
sci_get_line_indentation() in the plugin API? Even though it is easy to reproduce [2] it would be nicer to have it directly.
We can do, send a patch if you like. It sounds like it might be better to use editor_insert_text_block in this case.
Yeah I do so but it needs to already know at which *position* insert the block. And the position where I want to insert is something like the "smart start" of the line (start of the line + indentation).
OK, I think I understand now ;-)
I think your solution is right. The function doesn't insert indentation on the first line.
Regards, Nick
Nick Treleaven a écrit :
On Thu, 29 Apr 2010 19:13:25 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
Can you give a code example of what you're trying to do?
The real code can be found only through SF's VC viewer: http://geany-plugins.svn.sourceforge.net/viewvc/geany-plugins/trunk/geanygen...
But let's explain a bit: I would insert a text block, and indent it to respect the indentation of the insertion's line. What I do is:
- build a text block (line 326);
- find *the line* at which insert it (I don't know the position, only
the line -- this is from a tag) at the start (lines 338-339); 3) convert that line information to position information as needed (lines 340-343); 4) insert the text block (line 351).
Of course step 3 is an implementation detail, and it's where I have the "problem". My question is: "how am I supposed to insert a text block at the start of a particular *line* for it to be indented as this line is indented?"
- If this is a good way to proceed, could we have
sci_get_line_indentation() in the plugin API? Even though it is easy to reproduce [2] it would be nicer to have it directly.
We can do, send a patch if you like. It sounds like it might be better to use editor_insert_text_block in this case.
Yeah I do so but it needs to already know at which *position* insert the block. And the position where I want to insert is something like the "smart start" of the line (start of the line + indentation).
OK, I think I understand now ;-)
I think your solution is right. The function doesn't insert indentation on the first line.
OK, thank you for the confirmation. I attach a patch that adds sci_get_line_indentation() and sci_set_line_indentation() to the plugin API. I don't need the latter but I have added it because I think they goes quite together; but if you don't think so, I can update the patch to only include the get().
Regards, Colomban
On Thu, 29 Apr 2010 20:59:40 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
I attach a patch that adds sci_get_line_indentation() and sci_set_line_indentation() to the plugin API. I don't need the latter
Thanks, committed.
but I have added it because I think they goes quite together; but if you don't think so, I can update the patch to only include the get().
I think 'set' could be useful too.
Regards, Nick
Nick Treleaven a écrit :
On Thu, 29 Apr 2010 20:59:40 +0200 Colomban Wendling lists.ban@herbesfolles.org wrote:
I attach a patch that adds sci_get_line_indentation() and sci_set_line_indentation() to the plugin API. I don't need the latter
Thanks, committed.
Great, thanks!
Regards, Colomban