Discussion:
Auto-Indent in scintilla
Anas Chakfeh
2014-05-07 14:31:24 UTC
Permalink
Hello,

Have anyone done auto-indentation for any C-like language?
I am trying to auto indent c code, but it is proving troublesome.

Thanks
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/d/optout.
Stefano Mtangoo
2014-05-07 15:52:02 UTC
Permalink
Post by Anas Chakfeh
Hello,
Have anyone done auto-indentation for any C-like language?
I am trying to auto indent c code, but it is proving troublesome.
I use this with wxStyledTextCtrl (wrapper around scintilla) catching event
where charcter is added. Feel free to adopt to your Component

chr = get_typed_character_some_how();

if(chr == '\n' || chr == '\r')
{
//Now time to deal with auto indenting
int lineInd = 0;

if(currentLine > 0)
{
lineInd = GetLineIndentation(currentLine - 1);
}

if(lineInd != 0) // NOT in the beginning
{
SetLineIndentation(currentLine, lineInd);
GotoPos(PositionFromLine(currentLine) + lineInd);
}
}
Post by Anas Chakfeh
Thanks
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/d/optout.
Anas Chakfeh
2014-05-08 09:29:12 UTC
Permalink
Many Thanks!
Post by Stefano Mtangoo
Post by Anas Chakfeh
Hello,
Have anyone done auto-indentation for any C-like language?
I am trying to auto indent c code, but it is proving troublesome.
I use this with wxStyledTextCtrl (wrapper around scintilla) catching event
where charcter is added. Feel free to adopt to your Component
chr = get_typed_character_some_how();
if(chr == '\n' || chr == '\r')
{
//Now time to deal with auto indenting
int lineInd = 0;
if(currentLine > 0)
{
lineInd = GetLineIndentation(currentLine - 1);
}
if(lineInd != 0) // NOT in the beginning
{
SetLineIndentation(currentLine, lineInd);
GotoPos(PositionFromLine(currentLine) + lineInd);
}
}
Post by Anas Chakfeh
Thanks
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/d/optout.
Mike Lischke
2014-05-19 10:38:21 UTC
Permalink
Hi,
I use this with wxStyledTextCtrl (wrapper around scintilla) catching event where charcter is added. Feel free to adopt to your Component
chr = get_typed_character_some_how();
if(chr == '\n' || chr == '\r')
{
//Now time to deal with auto indenting
int lineInd = 0;
if(currentLine > 0)
{
lineInd = GetLineIndentation(currentLine - 1);
}
if(lineInd != 0) // NOT in the beginning
{
SetLineIndentation(currentLine, lineInd);
GotoPos(PositionFromLine(currentLine) + lineInd);
}
}
Note: caret positioning as above doesn't work with enabled tabs as SETLINEINDENTATION will use a mix of tabs and spaces. In that case you either switch off tabs temporarily or use GETCOLUMN and do some extra calculations to determine the real value for GOTOPOS.

Mike
--
www.soft-gems.net
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/d/optout.
Loading...