<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;" dir="ltr">
<div style="color: rgb(0, 0, 0);">
<div id="divRplyFwdMsg" dir="ltr">
<div> </div>
<div>> > On 14 May 2017, at 11:24 pm, Matic Kukovec <kukovecmatic@hotmail.com> wrote:<br>
> > ><br>
> > ><br>
> > > > On 14 May 2017, at 11:26 am, kristof.mulier@telenet.be wrote:<br>
> > > > ><br>
> > > > > Dear QScintilla users,<br>
> > > > ><br>
> > > > > Automatic indentation is a very nice feature offered by QScintilla. When inserting a new line, automatic indentation pushes the cursor to the same indentation level as the previous one. You have two options to switch on this feature: (1) call the
function setAutoIndent(True) on the QsciScintilla editor or (2) call the function setAutoIndentStyle(..) on the lexer.<br>
> > > > ><br>
> > > > > The first option works. The second doesn't. For full details on the problem, please take a look at the following StackOverflow question:<br>
> > > > ><br>
> > > > > http://stackoverflow.com/questions/43962669/setautoindentstyle-on-the-qscintilla-lexer-doesnt-work<br>
> > > > ><br>
> > > > > Do you know the answer?<br>
> > > ><br>
> > > > You have to implement the various block method (blockStart(), blockEnd() etc).<br>
> > > ><br>
> > > > Phil<br>
> > ><br>
> > > Hey Phil,<br>
> > ><br>
> > > Tried implementing blockStart() and blockEnd(), but it throws a TypeError if using for example:<br>
> > > def blockStart(self):<br>
> > > return "{"<br>
> > ><br>
> > > def blockEnd(self):<br>
> > > return "}"<br>
> > > With a bit of trial&error I found that the methods need to return a tuple of (bytes, int). Why?<br>
> ><br>
> > http://pyqt.sourceforge.net/Docs/QScintilla2/classQsciLexer.html#a7c99eb2877dc6a9762815bc0471f0c36<br>
> ><br>
> > Phil<br>
> <br>
> Hey Phil,<br>
> <br>
> I'm assuming it means that it returns a tuple(bytesstring_of_block_start_chars, pointer_to_style), because lexers that implement the blockStart method (like QsciLexerPython) return (None, some_large_number). But why do they always return the byte_string as
None?<br>
> <br>
> Anyway, I edited the blockStart() and blockEnd() methods of my custom lexer to:<br>
> <br>
> def blockStart(self):<br>
> return b'{', 0<br>
> <br>
> def blockStart(self):<br>
> return b'}', 0<br>
> <br>
> and set the qscintilla editors setAutoIndent(True) and my custom lexers setAutoIndentStyle(QsciScintilla.AiOpening | QsciScintilla.AiOpening). Now the next line after inserting a '{' doesn't indent (like in the QsciLexerCPP, for example), but it does unindent
when inserting a '}'?<br>
> Example:<br>
> <br>
> if (test)<br>
> {<br>
> |<- doesn't indent <br>
> <br>
> Then I manually indent:<br>
> <br>
> if (test)<br>
> {<br>
> |<- manual indent with the tab key<br>
> test line added;<br>
> <br>
> Inserting the '}' character unindents automatically:<br>
> <br>
> if (test)<br>
> {<br>
> <br>
> test line added;<br>
> } <- automatically unindented from the previous line's indentation level <br>
> <br>
> I really have no idea if I'm doing something wrong or if I'm misunderstanding something, could you please help?<br>
> <br>
> P.S.:<br>
> I'm also helping Kristof, so that is why we are both posting separately on the same topic.<br>
> <br>
> Matic<br>
<br>
Hey Phil, <br>
<br>
I realize that I have no idea how this autoIndentStyle works. Could you explain step-by-step what and how things need to be implemented for this functionality to work correctly?<br>
<br>
Thanks,<br>
Matic<br>
</div>
</div>
</div>
</div>
</body>
</html>