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

New Python indent file

Expand Messages
  • David Bustos
    Here s an updated version of my Python indent file. It should fix a function detection typo and not being smarter than the user after a stop-execution
    Message 1 of 1 , Sep 28, 2000
      Here's an updated version of my Python indent file. It should fix a
      function detection typo and not being smarter than the user after a
      stop-execution statement.

      David Bustos


      " Python indent file
      " Language: Python
      " Maintainer: David Bustos <bustos@...>
      " Last Change: 9/28/2000

      setlocal indentexpr=GetPythonIndent(v:lnum)
      setlocal cinkeys+=:

      " Only define the function once.
      if exists("*GetPythonIndent")
      finish
      endif

      function GetPythonIndent(lnum)
      " Give up if this line is explicitly joined.
      if getline(a:lnum - 1) =~ '\\$'
      return -1
      endif

      " Search backwards for the frist non-empty line.
      let plnum = a:lnum - 1
      while plnum > 0 && getline(plnum) =~ '^\s*$'
      let plnum = plnum - 1
      endwhile

      if plnum == 0
      " This is the first non-empty line, use zero indent.
      return 0
      endif

      " If the previous line ended with a colon, indent this line
      if getline(plnum) =~ '^[^#]*:\s*\(#.*\)\=$'
      return indent(plnum) + &sw

      " If the previous line was a stop-execution statement...
      elseif getline(plnum) =~ '^\s*\(break\|continue\|raise\|return\)\>'
      " See if the user has already dedented
      if indent(a:lnum) > indent(plnum) - &sw
      " If not, recommend one dedent
      return indent(plnum) - &sw
      else
      " Otherwise, trust the user
      return -1
      endif

      " If the current line begins with a header keyword, dedent
      elseif getline(a:lnum) =~ '^\s*\(elif\|else\|except\|finaly\)\>'

      " Unless the previous line was a one-liner
      if getline(plnum) =~ '^\s*\(for\|if\|try\)\>'
      return indent(plnum)
      endif

      return indent(plnum) - &sw

      else
      return -1

      endif
      endfunction

      " vim:sw=2
    Your message has been successfully submitted and would be delivered to recipients shortly.