3 ms·
Sounds like a problem with your choice of editor, not Python. Try emacs or vim.
by mattdeboard 15y ago
Sounds like a problem with your choice of editor, not Python. Try emacs or vim.
- pnathan 15y agoI use emacs. It's an ambiguity problem similar to the dangling else. There's no way to automatically tell the editor that I want the statements to go here or there. edit: Yes, there's a reformat command in emacs. No, it does not work correctly for Python, because the lack of delimiters means it does not have the information it needs to do the job right.
- rmc 15y agoIn Vim, just select the text (with V), then use < or > to deinter or indent resp.
- decklin 15y agoThat's what he meant by "manually".
- exDM69 15y agoDo you have the appropriate emacs plugins for writing Python? I'm a bit surprised that the code isn't formatted properly with emacs out of the box. Then again, many editors need some sort of addon to be able to cope with whitespace sensitive syntax. If it were an actual grammatical ambiguity, any editor couldn't get it right but it can't be since the Python parser can understand it.
- pnathan 15y agoIt is not a grammatical ambiguity in terms of Python. Here's a pastebin that illuminates the problem. http://pastebin.com/3fdxts4n http://pastebin.com/3fdxts4n
- mattdeboard 15y agoI see. I never have that problem because when I C-S-<Backspace> and put my cursor at the beginning of the line I want to paste it retains indentation level fine. edit: What version of emacs are you using? Are you using python.el or python-mode.el for editing Python? python.el handles try/except, if/else, etc., etc., indentation pretty marvelously. edit2: If you'd rather talk about this out-of-band I'm on freenode as mdeboard or my email address is in my profile.
- pnathan 15y ago23.3.x and python.el. It's very stock. What function does C-S-backspace give you? I see kill-whole-line on my install. Once I am writing in a block, the indents work fine, but... I can't paste something into a block and whack the 'reformat all' to come out correctly, especially if it has multiple levels of indentation. Since my code gets reworked substantially while I'm in the middle of it, this wastes my time. Braces are not noise...
- mattdeboard 15y agoIt sounds like you need to use the kill ring & pasting from the kill ring more. It preserves indentation levels, and selecting a region then M-x indent-region will handle all this for you.
- Dobbs 15y agoVim has this problem also.
- obtu 15y agovim has a :set paste toggle for its input mode.