Loading ...
Sorry, an error occurred while loading the content.
 

python auto indentation problem of indent/python.vim

Expand Messages
  • Peng Yu
    Hi, I have the following lines in my .vimrc and I installed indent/ python.vim from http://www.vim.org/scripts/script.php?script_id=974 fun BenIndent() let
    Message 1 of 3 , Sep 30, 2009
      Hi,

      I have the following lines in my .vimrc and I installed indent/
      python.vim from http://www.vim.org/scripts/script.php?script_id=974

      fun BenIndent()
      let oldLine=line('.')
      normal gg=G
      execute ':' . oldLine
      endfun
      map -- :call BenIndent()<CR>

      However, it will not correctly indent my code. Suppose I have the
      following code,

      def fun(x,y):
      if x > y:
      print x
      else
      print y

      Vim indents it to

      def fun(x,y):
      if x > y:
      print x
      else
      print y

      Apparently, the last line 'print y' is not indented correctly.


      If I have

      def fun(x,y):
      if x > y:
      print x

      else
      print y


      After vim indentation, I have

      def fun(x,y):
      if x > y:
      print x

      else
      print y

      There is still the problem with the last line 'print y'. I also what
      to 4 space characters in the line after 'print x', because sometime I
      might paste the code to a python interactive session.

      I'm wondering if someone can help fix the indentation script. Thank
      you!

      Regards,
      Peng
      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • sc
      ... i don t believe the python indent script will recognize the else as an else unless it is followed by a : sc
      Message 2 of 3 , Sep 30, 2009
        On Wednesday 30 September 2009, Peng Yu wrote:

        > If I have
        >
        > def fun(x,y):
        > if x > y:
        >   print x
        >
        > else
        >   print y
        >
        >
        > After vim indentation, I have
        >
        > def fun(x,y):
        >   if x > y:
        >     print x
        >
        >   else
        >   print y

        i don't believe the python indent script will recognize the
        else as an else unless it is followed by a ":"

        sc

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Peng Yu
        ... I m sorry. It was my mistake. But how to make vim automatically indentation add 4 spaces after print x ? Currently, if there is a # in that line, vim
        Message 3 of 3 , Oct 1, 2009
          On Sep 30, 9:39 pm, sc <tooth...@...> wrote:
          > On Wednesday 30 September 2009, Peng Yu wrote:
          >
          >
          >
          > > If I have
          >
          > > def fun(x,y):
          > > if x > y:
          > >   print x
          >
          > > else
          > >   print y
          >
          > > After vim indentation, I have
          >
          > > def fun(x,y):
          > >   if x > y:
          > >     print x
          >
          > >   else
          > >   print y
          >
          > i don't believe the python indent script will recognize the
          > else as an else unless it is followed by a ":"

          I'm sorry. It was my mistake. But how to make vim automatically
          indentation add 4 spaces after 'print x'? Currently, if there is a '#'
          in that line, vim will correctly add 4 spaces, but if there is not a
          '#', vim will leave that line empty.

          Regards,
          Peng
          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        Your message has been successfully submitted and would be delivered to recipients shortly.