Wikia

Vim Tips Wiki

Changes: Script:3003

Edit

Back to page

(adjust Template:ScriptComments to remove id as no longer needed; minor tweaks)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 60: Line 60:
 
</pre>
 
</pre>
   
Hitting <tt><ENTER></tt> will always indent the cursor to the level of the "{", ignoring the previous lines indentation level.
+
Hitting <code><ENTER></code> will always indent the cursor to the level of the "{", ignoring the previous lines indentation level.
   
 
-------------------
 
-------------------

Latest revision as of 09:49, July 14, 2012

Use this page to discuss script 3003 indent/python: yet another Python indentation script

  • Add constructive comments, bug reports, or discuss improvements (see the guideline).
  • Do not document the script here (the author should do that on vim.org).
  • This page may be out of date: check the script's vim.org page above, and its release notes.

Python indenting scriptEdit

This is my attempt at indenting Python to conform to PEP8. Based on the 7.2 Python indentation, with bits of script#974 hacked in.

Sample dataEdit

This is the Python code I tested with:

import line2, line3, line4, line5

class B:
    def foo():
        line1 = (line3({[a, b]
                        : 3,
                       }
                      ),
                 (
                  ( "hello" ),
                  99,
                 ),
                 line4)
        line5("foo",
              ("bar",
               "bat",
               "baz"),
              "snaf")

def bar(b, c):
    a = (b
         + c) - (c
                 + b)

class Rectangle(Blob):
    def __init__(self, width, height,
                 color='black', emphasis=None, highlight=0):
        """
        fjlaskdjf
        """
        if width == 0 and height == 0 and \
           color == 'red' and emphasis == 'strong' or \
           highlight > 100:
            raise ValueError("sorry, you lose")
        if width == 0 and height == 0 and (color == 'red' or
                                           emphasis is None):
            raise ValueError("I don't think so -- values are %s, %s" %
                             (width, height))
            Blob.__init__(self, width, height,
                          color, emphasis, highlight)

CommentsEdit

This is largely a huge improvement, but the indentation inside braces, brackets, etc. is a little aggressive.

For example:

 some_really_long_thing = {
    'foo': 'bar',<ENTER>

Hitting <ENTER> will always indent the cursor to the level of the "{", ignoring the previous lines indentation level.


I could change it to say a brace or parentheses only marks a new indent if it has text after it. If it is by itself at the end of the line, then the indentation for the next line should be unchanged.

Would that be an improvement?

-- David Moore 2010-10-24



That would be perfect, thanks David.

-- Alec Thomas 2010-10-24

Around Wikia's network

Random Wiki