Python Forum
cheating with indented code - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html)
+--- Forum: Bar (https://python-forum.io/forum-27.html)
+--- Thread: cheating with indented code (/thread-23245.html)



cheating with indented code - Skaperen - Dec-18-2019

i had a block of code in a loop. i needed to copy it to a place before the loop to initialize some things. it was already indented one level too much. but rather than edit all those lines to unindent them (and because i might need to copy them back with changes) i cheated. i created a FAKE block that began with "if 1:". now i can just leave them indented.


RE: cheating with indented code - buran - Dec-18-2019

well, every decent IDE has a key combinations to indent and de-dent block of code.
e.g. in VS Code, select a block of code and Tab will indent one level Shift+Tab will de-dent one level. Same in Notepad++. No need of this weird stuff with fake if block.


RE: cheating with indented code - Gribouillis - Dec-18-2019

In Kate or Kdevelop it is Ctrl-I and Ctrl-Shift-I.


RE: cheating with indented code - Skaperen - Dec-19-2019

how about emacs (version 25.2)?


RE: cheating with indented code - buran - Dec-19-2019

I don't use emacs, but quick lool in the docs show there are 2 commands to indent and dedent regions of lines:
https://www.gnu.org/software/emacs/manual/html_node/emacs/Indentation-Commands.html#Indentation-Commands

Look at the last 2 in the above link.


RE: cheating with indented code - buran - Dec-19-2019

Look also at https://www.gnu.org/software/emacs/manual/html_node/emacs/C-Indent.html#C-Indent

Last 2 paragraphs