Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: wxLearner on March 09, 2007, 11:05:38 am

Title: [Code snippets plugin] Suggestion
Post by: wxLearner on March 09, 2007, 11:05:38 am
Hello,
I like the code snippets plugin and would like to suggest a small change. If you have a snippet, that consists of multiple lines, the content from the second line on isn't indented. I've looked into the code of the abbreviation feature, how to support indentation. The code snippets plugin needs one additional line of code only (in the method CodeSnippetsWindow::ApplySnippet before ctrl->AddText(snippet);):
Code
snippet.Replace(wxT("\n"), wxT('\n') + editor->GetLineIndentString(ctrl->GetCurrentLine()));
It would be nice, if that could be added.

Thank you.
Title: Re: [Code snippets plugin] Suggestion
Post by: jamieo on March 21, 2007, 10:29:03 pm
Yes, that would be a nice change (thanks wxLearner) - I tried this plugin but dismissed it because of this very issue.
Title: Re: [Code snippets plugin] Suggestion
Post by: Pecan on March 22, 2007, 12:32:52 am
Could you explain the problem more fully. I can't seem to get the error.

(http://img489.imageshack.us/img489/964/162xu3.png)

The first three lines have tabs, and the last three have spaces as indentations. They seemed to have "apply"'d properly.

Could you paste an example of the problem.
Title: Re: [Code snippets plugin] Suggestion
Post by: jamieo on March 22, 2007, 01:21:15 am
If you insert the same snippet after a couple of tabs the snippet won't maintain it's tab structure.  The first switch block below is correct as it has been inserted at the first column.  It is exactly the same as the original snippet template (no indentation applied).

Code
switch ()
{
case :
break;

default:
break;
}

The next snippet is inserted after two tabs but the tab structure is incorrect - only the first line is indented.  The snippet has just been pasted with the same tabs it had in the original template (no indentation applied).  This is awkward as most code has some level of indentation.

Code
		switch ()
{
case :
break;

default:
break;
}


With the change wxLearner has suggested the existing indentation level is automatically applied to the whole snippet so the block will match it's surrounding code.

Code
		switch ()
{
case :
break;

default:
break;
}
Title: Re: [Code snippets plugin] Suggestion
Post by: Pecan on March 22, 2007, 02:45:05 am
Ah.. I get it now

thanks

Edit: Fixed svn 3737