Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Indent/outdent selected lines
-
This will indent or outdent all selected lines:
<code>
#Indent/Outdent selected linesimport editor
import consoleindent_char = '\t'
text = editor.get_text()
selection = editor.get_line_selection()
selected_text = text[selection[0]:selection[1]]indent = console.alert('indent or outdent?', '', '<<', '>>') == 2
replacement = ''
for line in selected_text.splitlines():
if indent:
replacement += indent_char + line + '\n'
else:
replacement += line[line.find(indent_char) + len(indent_char):] + '\n'editor.replace_text(selection[0], selection[1], replacement)
editor.set_selection(selection[0], selection[0] + len(replacement) - 1)
</code>Most of it is stolen from the (un)comment script. Change the indent_char variable to whatever your preference is, e.g. this could be 2 or 4 spaces. Outdent will only work if all lines use the same indent_char.