~ubuntu-branches/ubuntu/vivid/vim/vivid

« back to all changes in this revision

Viewing changes to runtime/indent/lua.vim

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2008-11-05 11:37:43 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20081105113743-9i4urcsm3n44mhqe
Tags: 2:7.2.025-2ubuntu1
* Merge from debian unstable, remaining changes:
  - runtime/syntax/debcontrol.vim:
    + Add "metapackages" to the list of valid sections.
  - runtime/syntax/debchangelog.vim:
    + Add "jaunty" to the list of valid suites.
  - Drop vim-lesstif package and lesstif2-dev build-dependency.
  - Enable Python interpreter on basic builds.
  - Create a .pot file for translations.
  - Disable autoindent, line-wrapping, and backup files by default.
  - runtime/syntax/debsources.vim:
    + Add "jaunty" to debsourcesDistrKeyword
  - runtime/syntax/grub.vim:
    + Add Ubuntu-specific 'quiet' keyword.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
" Language:     Lua script
3
3
" Maintainer:   Marcus Aurelius Farias <marcus.cf 'at' bol.com.br>
4
4
" First Author: Max Ischenko <mfi 'at' ukr.net>
5
 
" Last Change:  2005 Jun 23
 
5
" Last Change:  2007 Jul 23
6
6
 
7
7
" Only load this indent file when no other was loaded.
8
8
if exists("b:did_indent")
25
25
 
26
26
function! GetLuaIndent()
27
27
  " Find a non-blank line above the current line.
28
 
  let lnum = prevnonblank(v:lnum - 1)
 
28
  let prevlnum = prevnonblank(v:lnum - 1)
29
29
 
30
30
  " Hit the start of the file, use zero indent.
31
 
  if lnum == 0
 
31
  if prevlnum == 0
32
32
    return 0
33
33
  endif
34
34
 
35
35
  " Add a 'shiftwidth' after lines that start a block:
36
36
  " 'function', 'if', 'for', 'while', 'repeat', 'else', 'elseif', '{'
37
 
  let ind = indent(lnum)
38
 
  let flag = 0
39
 
  let prevline = getline(lnum)
40
 
  if prevline =~ '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)'
41
 
        \ || prevline =~ '{\s*$' || prevline =~ '\<function\>\s*\%(\k\|[.:]\)\{-}\s*('
42
 
    let ind = ind + &shiftwidth
43
 
    let flag = 1
 
37
  let ind = indent(prevlnum)
 
38
  let prevline = getline(prevlnum)
 
39
  let midx = match(prevline, '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)')
 
40
  if midx == -1
 
41
    let midx = match(prevline, '{\s*$')
 
42
    if midx == -1
 
43
      let midx = match(prevline, '\<function\>\s*\%(\k\|[.:]\)\{-}\s*(')
 
44
    endif
44
45
  endif
45
46
 
46
 
  " Subtract a 'shiftwidth' after lines ending with
47
 
  " 'end' when they begin with 'while', 'if', 'for', etc. too.
48
 
  if flag == 1 && prevline =~ '\<end\>\|\<until\>'
49
 
    let ind = ind - &shiftwidth
 
47
  if midx != -1
 
48
    " Add 'shiftwidth' if what we found previously is not in a comment and
 
49
    " an "end" or "until" is not present on the same line.
 
50
    if synIDattr(synID(prevlnum, midx + 1, 1), "name") != "luaComment" && prevline !~ '\<end\>\|\<until\>'
 
51
      let ind = ind + &shiftwidth
 
52
    endif
50
53
  endif
51
54
 
52
55
  " Subtract a 'shiftwidth' on end, else (and elseif), until and '}'
53
56
  " This is the part that requires 'indentkeys'.
54
 
  if getline(v:lnum) =~ '^\s*\%(end\|else\|until\|}\)'
 
57
  let midx = match(getline(v:lnum), '^\s*\%(end\|else\|until\|}\)')
 
58
  if midx != -1 && synIDattr(synID(v:lnum, midx + 1, 1), "name") != "luaComment"
55
59
    let ind = ind - &shiftwidth
56
60
  endif
57
61