How can I make QScintilla auto-indent like SublimeText? How can I make QScintilla auto-indent like SublimeText? python python

How can I make QScintilla auto-indent like SublimeText?


It looks like you have to code your own version, the documentation mentions the most important point's about it already in the chapter Installation:

As supplied QScintilla will be built as a shared library/DLL and installed in the same directories as the Qt libraries and include files.

If you wish to build a static version of the library then pass CONFIG+=staticlib on the qmake command line.

If you want to make more significant changes to the configuration then edit the file qscintilla.pro in the Qt4Qt5 directory.

If you do make changes, specifically to the names of the installation directories or the name of the library, then you may also need to update the Qt4Qt5/features/qscintilla2.prf file.*

Further steps are explained there too.


There is no integrated way to make auto-indentation work in QScintilla (especially as it is in SublimeText). This behaviour is a language-specific and user-specific. Native Scintilla documentation includes examples of how to trigger auto-indentation. Sorry but it's written in C#. I haven't found it written in Python.

Here's a code (I know that a QScintilla is a Port to Qt, this Scintilla-oriented code should work with QScintilla too, or at the worst you can adapt it for C++):

private void Scintilla_InsertCheck(object sender, InsertCheckEventArgs e) {    if ((e.Text.EndsWith("" + Constants.vbCr) || e.Text.EndsWith("" + Constants.vbLf))) {        int startPos = Scintilla.Lines(Scintilla.LineFromPosition(Scintilla.CurrentPosition)).Position;        int endPos = e.Position;        string curLineText = Scintilla.GetTextRange(startPos, (endPos - startPos));         // Text until the caret so that the whitespace is always        // equal in every line.        Match indent = Regex.Match(curLineText, "^[ \\t]*");        e.Text = (e.Text + indent.Value);        if (Regex.IsMatch(curLineText, "{\\s*$")) {            e.Text = (e.Text + Constants.vbTab);        }    }}private void Scintilla_CharAdded(object sender, CharAddedEventArgs e) {    //The '}' char.    if (e.Char == 125) {        int curLine = Scintilla.LineFromPosition(Scintilla.CurrentPosition);        if (Scintilla.Lines(curLine).Text.Trim() == "}") {         //Check whether the bracket is the only thing on the line.         //For cases like "if() { }".            SetIndent(Scintilla, curLine, GetIndent(Scintilla, curLine) - 4);        }    }}//Codes for the handling the Indention of the lines.//They are manually added here until they get officially //added to the Scintilla control.#region "CodeIndent Handlers"    const int SCI_SETLINEINDENTATION = 2126;    const int SCI_GETLINEINDENTATION = 2127;    private void SetIndent(ScintillaNET.Scintilla scin, int line, int indent) {        scin.DirectMessage(SCI_SETLINEINDENTATION, new IntPtr(line), new IntPtr(indent));    }    private int GetIndent(ScintillaNET.Scintilla scin, int line) {        return (scin.DirectMessage(SCI_GETLINEINDENTATION, new IntPtr(line), null).ToInt32);    }#endregion

Hope this helps.