def SmartIndent(self):
        """Handles smart indentation for the editor"""
        # Read settings from the config file

        # Determine how to indent
        usetab = self.conf.getboolean("editing", "usetab")
        if usetab:
            indent_amount = self.GetTabWidth()
            indent = "\t"
        else:
            indent_amount = self.conf.getint("editing", "indent")
            indent = indent_amount * " "

        cursorpos = self.GetColumn(self.GetCurrentPos())
        last_line_no = self.GetCurrentLine()
        last_line = split_comments(self.GetLine(last_line_no))[0]
        indent_level = self.GetLineIndentation(last_line_no) // indent_amount

        # Should we increase or decrease the indent level
        colonpos = last_line.find(":")
        if colonpos >= 0 and cursorpos > colonpos:
            indent_level += 1
        elif any(last_line.lstrip().startswith(token)
                 for token in ["return", "break", "yield"]):
            indent_level = max([indent_level - 1, 0])

        # Perform the actual smartindent
        self.NewLine()
        self.AddText(indent * indent_level)
    def SmartIndent(self):
        """Handles smart indentation for the editor"""
        # Read settings from the config file

        # Determine how to indent
        usetab = self.conf.getboolean("editing", "usetab")
        if usetab:
            indent_amount = self.GetTabWidth()
            indent = "\t"
        else:
            indent_amount = self.conf.getint("editing", "indent")
            indent = indent_amount * " "

        cursorpos = self.GetColumn(self.GetCurrentPos())
        last_line_no = self.GetCurrentLine()
        last_line = split_comments(self.GetLine(last_line_no))[0]
        indent_level = self.GetLineIndentation(last_line_no) // indent_amount

        # Should we increase or decrease the indent level
        colonpos = last_line.find(":")
        if colonpos >= 0 and cursorpos > colonpos:
            indent_level += 1
        elif any(last_line.lstrip().startswith(token)
                 for token in ["return", "break", "yield"]):
            indent_level = max([indent_level - 1, 0])

        # Perform the actual smartindent
        self.NewLine()
        self.AddText(indent * indent_level)
Beispiel #3
0
    def SmartIndent(self):     
        # Read settings from the config file
        indent_amount = int(self.conf["indent"])
        usetab = int(self.conf["usetab"])

        last_line_no = self.GetCurrentLine()
        last_line = split_comments(self.GetLine(last_line_no))[0]
        self.NewLine()
        indent_level = self.GetLineIndentation(last_line_no) // indent_amount
        
        if last_line.rstrip().endswith(':'):
            indent_level += 1
        elif any(last_line.lstrip().startswith(token) 
                 for token in ["return", "break", "yield"]):
            indent_level = max([indent_level - 1, 0])

        if usetab:
            indent = "/t" * indent_level
        else:
            indent = indent_amount * " " * indent_level

        self.AddText(indent)
        print self.conf