Git Product home page Git Product logo

Comments (7)

1st1 avatar 1st1 commented on May 16, 2024

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.

brianmhunt avatar brianmhunt commented on May 16, 2024

FWIW, here's a vim plugin that I think nails this (one of the very few editors that does):

from magicpython.

ChrisBarker-NOAA avatar ChrisBarker-NOAA commented on May 16, 2024

"proper" pyton-friendly indenting would indeed be very, very nice. It is handled well by Peppy:

http://peppy.flipturn.org/

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.

ChrisBarker-NOAA avatar ChrisBarker-NOAA commented on May 16, 2024

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.

slippycheeze avatar slippycheeze commented on May 16, 2024

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.

1st1 avatar 1st1 commented on May 16, 2024

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.

ChrisBarker-NOAA avatar ChrisBarker-NOAA commented on May 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.