def METHOD_NAME(self, METHOD_NAME=True):
    sel = self.getSelection()[:]
    text = self.text()
    lines = text.split('\n')
    if sel[0] == -1:
        # toggle for just this line
        row, col = self.getCursorPosition()
        line = lines[row]
        self.setSelection(row, 0, row, len(line))
        if METHOD_NAME:
            line = '#' + line
        else:
            line = line.replace("#", "", 1)
        self.replaceSelectedText(line)
        self.setCursorPosition(row, col+(1 if col > 0 else 0))
    else:
        block = lines[sel[0]:sel[2]]
        # make sure all lines have #
        new = []
        if METHOD_NAME:
            for line in block:
                new.append('#' + line)
        else:
            for line in block:
                if line.strip() == '':
                    new.append(line)
                    continue
                if re.match(r'\s*\#', line) is None:
                    return
                new.append(line.replace('#', '', 1))
        self.setSelection(sel[0], 0, sel[2], 0)
        self.replaceSelectedText('\n'.join(new) + '\n')
        # shift = 1 if comment else -1
        self.setSelection(sel[0], max(0, sel[1]), sel[2], sel[3])