Indentation

Indentation character

The function
setIndentationsUseTabs(use_tabs)
determines whether the indent/unindent uses either the TAB ‘\t’ character or the WHITESPACE ‘ ‘ character.

  • False
    self.__editor.setIndentationsUseTabs(False)
    Indentation uses the whitespace character.
     
  • True
    self.__editor.setIndentationsUseTabs(True)
    Indentation uses the tab character.
     

Indentation size

The function
setTabWidth(indentation_size)
selects the number of space characters to indent by. When indentation is done with TABS, this parameter defines the width of the TAB character – expressed as a multiple of whitespaces.

  • self.__editor.setTabWidth(4)
    Indentation is now 4 spaces wide.
     

Indentation guides

QScintilla can show dotted vertical lines to indicate the indentation levels.
setIndentationGuides(visible)

  • False
    self.__editor.setIndentationGuides(False)

     
  • True
    self.__editor.setIndentationGuides(True)

     

Indentation at spaces

This one is a bit difficult to grasp. The function
setTabIndents(at_spaces)
impacts the behaviour of the TAB key when the cursor is surrounded by whitespaces. If set to False, the editor simply inserts n whitespaces (or a ‘\t’ character) whenever the TAB key is pressed. But if set to True, the editor pushes the first non-whitespace character to the next indentation-level!

  • False
    self.__editor.setTabIndents(False)

     
  • True
    self.__editor.setTabIndents(True)

     

Automatic indentation

When inserting a new line, automatic indentation pushes the cursor to the same indentation level as the previous one.
setAutoIndent(autoindent_on)

  • False
    self.__editor.setAutoIndent(False)

     
  • True
    self.__editor.setAutoIndent(True)

     

Note: A lexer can modify this behaviour with its setAutoIndentStyle method!