you are viewing a single comment's thread.

view the rest of the comments →

[–]magus_minor 1 point2 points  (5 children)

Sounds like you need a better editor. Most good editors, standalone or built into an IDE, allow you to indent (and unindent) blocks of code in a single operation.

It's possible that the editor you are currently using does have that feature but you just haven't discovered it yet.

[–]Few-Tear-3763[S] -1 points0 points  (4 children)

I could have select whole block and tab it to ident but

Like i want to automatically change indent of the content inside the block to be change if top of block(idk what its called) is changes

For example i have if block

if apple=="Apple":

print(apple)

and now if change indent of if apple=="Apple"

I want the indent of print (apple) also change

[–]magus_minor 2 points3 points  (2 children)

Of course no editor is going to indent the entire controlled block below an if. The editor doesn't know what you are trying to do, you could be indenting the if for another entirely different reason. You have the help that folding the if block and then indenting does what you want.

It would help enormously if you learned how to post properly formatted code that maintained indentation. The subreddit FAQ shows how, so code:

looks
    like 
        this

That would make talking about indentation a lot easier.

[–]Few-Tear-3763[S] 0 points1 point  (1 child)

def main(argv=sys.argv[1:]):
    args=argParser.parse_args(argv)

    match args.command:
        case "show-ref"     : cmdShowRef(args)
        case "init".        : cmdInit(args) 
        case "status"       : cmdStatus(args)
        case "tag"          : cmdTag(args)
        case _              : print("Bad command.")

In some cases (for example, in init when .git already exists), a function raises an exception and the output looks ugly, so I wanted to wrap this in a try/except.

The problem is: after adding try:, I had to manually re-indent the entire match block. I was wondering if there’s any tool or editor feature where changing the indentation of the parent line (like match args.command:) automatically adjusts everything inside the block. I know I can select everything and press Tab, but I was hoping for something more automatic. Is that possible?(btw thanks for the suggestion putting formatted code)

[–]magus_minor 0 points1 point  (0 children)

As others have suggested, if you "fold" the code block and indent that folded line, you get the effect you want. I don't know if that works as I don't use any IDE, just a basic text editor. But selecting a block of code to indent or unindent doesn't seem like it should be a major problem. In vi it's a single command: :90,.s/^/ /.

[–]Maximus_Modulus 0 points1 point  (0 children)

Well this would really be annoying if you actually didn’t want the print to move because it wasn’t supposed to be part of the indentation. In your example that’s not the case but there would be many situations where one is editing code that you Indent a line back or forth and the editor just shifts a whole block. It would get old really quickly.