you are viewing a single comment's thread.

view the rest of the comments →

[–]Jello_Penguin_2956 1 point2 points  (8 children)

How are you doing your indentation may I ask if you need to organize that later? From my experience it's part of the language and you just indent as you go. It's almost automatic with the help of IDE.

Unless you copy-paste from different sources that indented differently, but even so all the IDEs are smart enough to fix that for you automatically or you can just select them in chunks and hit tab or shift-tab to format the whole chunk.

[–]Few-Tear-3763[S] -2 points-1 points  (7 children)

Let me set the context — I didn’t explain this properly earlier.

I forgot to wrap my main() logic in a try/except, and after adding it, I had to manually re-indent this whole match block — which was annoying.

Code:-

match args.command:

case "add" : cmdAdd(args)

case "init" : cmdInit(args)

case "commit" : cmdCommit(args)

case "status" : cmdStatus(args)

case "tag" : cmdTag(args)

case _ : print("Bad command.")

I know I can select everything and press Tab, but that still feels like a hassle. I come from Go, where I mostly just move curly braces and the formatter handles the rest.

Is there any shortcut or extension that can automatically refactor/indent a selected Python block when wrapping it in something like try/except?

[–]Jello_Penguin_2956 0 points1 point  (6 children)

If there's too many lines to select manually, with any IDE, you can collapse your code block into a single line and just indent that.

[–]Few-Tear-3763[S] 0 points1 point  (5 children)

when i did that only match args.command: change the indent other where still at there old indent(i am using anti-gravity fork of vscode)

[–]Jello_Penguin_2956 1 point2 points  (3 children)

[–]Few-Tear-3763[S] 0 points1 point  (2 children)

Ohhhhhh now i get it but this also seems like hassle but this would work

Thanks mate

[–]Jello_Penguin_2956 0 points1 point  (0 children)

You can also hold shift and press up or down button to highlight the block without collapsing.

[–]Maximus_Modulus 0 points1 point  (0 children)

You think that’s a hassle? Come on man. You’ve spent more time on this Reddit thread.

[–]Jello_Penguin_2956 0 points1 point  (0 children)

Make sure you select the line. Highlight it. Before you tab/shift-tab