<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: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif,"EmojiFont","Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols,"EmojiFont","Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;" dir="ltr">
<p></p>
<div style="color: rgb(0, 0, 0);">
<div>
<div id="x_divRplyFwdMsg" dir="ltr">
<div></div>
</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 <b>tuple(bytesstring_of_block_start_chars, pointer_to_style)</b>, 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 <span>blockStart() and blockEnd()</span> methods of my custom lexer to:<br>
<blockquote><span>def blockStart(self):</span><br>
    return b'{', 0<br>
<br>
<div><span>def blockStart(self):</span><br>
    return b'}', 0</div>
</blockquote>
and set the qscintilla editors <b><span>setAutoIndent</span>(True)</b> and my custom lexers
<b><span>setAutoIndentStyle</span>(QsciScintilla.AiOpening | <span>QsciScintilla.AiOpening</span>)</b>. 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>
<blockquote>if (test) <br>
{<br>
|<- doesn't indent<br>
</blockquote>
Then I manually indent:<br>
<blockquote>
<div>if (test) <br>
{<br>
    |<- manual indent with the tab key<br>
     test line added;<br>
</div>
</blockquote>
Inserting the '}' character unindents automatically:<br>
<blockquote>
<div>if (test) <br>
{<br>
    <br>
     test line added;</div>
} <span><- automatically unindented from the previous line's indentation level</span><br>
</blockquote>
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>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText"><font size="2"><span style="font-size:10pt;"></span></font></div>
</span></font></div>
</div>
</body>
</html>