Comments (7)
We might be able to fix the indentation after ):
, but I don't think that we can fix it inside the parens. So it will be something like this:
def f(a, b, c,
d):
pass
Please give us some time to experiment and research.
from magicpython.
FWIW, here's a vim plugin that I think nails this (one of the very few editors that does):
from magicpython.
"proper" pyton-friendly indenting would indeed be very, very nice. It is handled well by Peppy:
about which says "Autoindenting of source code, including a regex-based autoindenter based on KDE's Kate"
Also -- IIRC, the Emacs Python mode did a really nice job -- but it's been years since I"ve used that.
My preferences for indenting:
For contiuation after an non-closed paren, PEP 8 supports a LOT of variations on styles. But what' I"ve most often seen, at least for funciton call and defnintions with lot sof arguments is what was suggested in this issue:
def f(a, b, c,
d):
pass
but I personally, prefer, once there is too much to fit on one line, to put them all on their own line, and aligned with the opening parens:
def f(a,
b,
c,
d):
pass
This looks kind of silly in this example, but this example would all fit on one line anyway. But if you have a lot or parameters, particularly keyword parameters, then it really make sense:
def f(param1,
param2,
kwparam1=some_value,
kwparam2=some_other_value,
)
And these lists can get a lot longer. I find it a lot easier to figure out what the parameters are if they each get their own line.
Perhaps an option to select one or the other of these styles -- or you leave it up to the user -- wherever they put the \n, it lines things up properly. But I think aligning with the opening parens makes the most sense.
Also: have the same behavior for continuation lines for unclosed brackets for lists, tuples, dicts,,,,
While we are at it -- I'd really like the key to "do the right thing"
hitting ANYWHERE on the line means: " indent this line correctly"
it will then put the curser at the end of the indentation.
(and, of course, an explicit tab (\t) character is NEVER put in anywhere!)
If the cursor is within the indentation zone, then
means: "remove one level of indentation"
and the cursor is put at the end of the indentation
In python, of course, there are multiple levels of indentation that might be legal. But these guidelines make it work well:
After hitting either (anywhere on the line) or (with the cursor in the indentation space):
- The indentation will always be in a legal state. (i.e if you are using 4 spaces per indent (which you always should!) and it is not a continuation line, the indent will always be a multiple of four spaces)
- the cursor will be left at the end of the indentation space
- this lets you reduce the level of indentation easily and obviously with the <backspace> key.
I've found this approach really makes it a lot faster and easier to have correct indentation of my code -- and not just Python!
from magicpython.
One other thought -- you could probably have bound to "autoindent' when there is more than one line selected. IT would then apply the indentation rules to all the lines, in such as way as not to change the pythonic meaning. So would always mean "indent this correctly"
from magicpython.
I came here to report the same issue, where indent-after-'(' is wrong. (and, yes, Emacs gets it right; that's what I miss it from.) subscribing.
from magicpython.
I'm going to close this issue. I think that formatting/editing rules are outside of what MagicPython is doing/capable of doing. This should really be handled by an editor-specific extension, not by a syntax highlighter.
from magicpython.
If all Magic Python does is syntax highlighting, then yes, this is not the place for it.
But a "proper" Python mode would include things like this.
If anyone can suggest a good place to add this code to Sublime I'd love to hear it.
from magicpython.
Related Issues (20)
- Backend MacOSX is interactive backend. Turning interactive mode on.
- ST4 loading error: Error in regex HOT 2
- Incorrect tokenization of querystring
- python string syntax highlight errors HOT 2
- Python function annotation is not working
- Support for Python PEP 677 in Python TextMate grammar HOT 1
- No ability to configure soft vs hard tabs when using tab type auto HOT 7
- Intellij support
- Highlight all PEP-0350 defined codetags
- Interpreter Stops Working
- Getting invalid.illegal.name.python on valid python code from textmate
- Syntax highlighting issue when @ appears as first character after line continuation when indexing is present
- Syntax Highlighting regex+format strings (rf)
- `#` in read-only string highlights as a comment
- Boolean True/False independent highlight support
- Wrong highlight for raw string HOT 4
- Tag and push the python 3.8 and 3.10 syntax additions to Pulsar
- Decorator Syntax Errors
- Support for PEP 695 (Type parameters / generics)
- Python modulo operator parsed in a string
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magicpython.