File:  [local] / rpl / vim / indent / rpl.vim
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Fri Aug 6 15:33:05 2010 UTC (13 years, 8 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_9, rpl-4_1_8, rpl-4_1_7, rpl-4_1_6, rpl-4_1_5, rpl-4_1_4, rpl-4_1_35, rpl-4_1_34, rpl-4_1_33, rpl-4_1_32, rpl-4_1_31, rpl-4_1_30, rpl-4_1_3, rpl-4_1_29, rpl-4_1_28, rpl-4_1_27, rpl-4_1_26, rpl-4_1_25, rpl-4_1_24, rpl-4_1_23, rpl-4_1_22, rpl-4_1_21, rpl-4_1_20, rpl-4_1_2, rpl-4_1_19, rpl-4_1_18, rpl-4_1_17, rpl-4_1_16, rpl-4_1_15, rpl-4_1_14, rpl-4_1_13, rpl-4_1_12, rpl-4_1_11, rpl-4_1_10, rpl-4_1_1, rpl-4_1_0, rpl-4_0_24, rpl-4_0_22, rpl-4_0_21, rpl-4_0_20, rpl-4_0_19, rpl-4_0_18, rpl-4_0, HEAD
Cohérence

    1: " Vim indent file
    2: " Language: RPL/2
    3: " Version:  0.3
    4: " Last Change:  2005 October 22
    5: " Maintainer:   BERTRAND Joël <joel.bertrand@systella.fr>
    6: 
    7: " Only load this indent file when no other was loaded.
    8: if exists("b:did_indent")
    9:   finish
   10: endif
   11: let b:did_indent = 1
   12: 
   13: setlocal indentkeys+==~end,=~case,=~if,=~then,=~else,=~do,=~until,=~while,=~repeat,=~select,=~default,=~for,=~start,=~next,=~step,<<>,<>>
   14: 
   15: " Define the appropriate indent function but only once
   16: setlocal indentexpr=RplGetFreeIndent()
   17: if exists("*RplGetFreeIndent")
   18:   finish
   19: endif
   20: 
   21: function RplGetIndent(lnum)
   22:   let ind = indent(a:lnum)
   23:   let prevline=getline(a:lnum)
   24:   " Strip tail comment
   25:   let prevstat=substitute(prevline, '!.*$', '', '')
   26: 
   27:   " Add a shiftwidth to statements following if, iferr, then, else, elseif,
   28:   " case, select, default, do, until, while, repeat, for, start
   29:   if prevstat =~? '\<\(if\|iferr\|do\|while\)\>' && prevstat =~? '\<end\>'
   30:   elseif prevstat =~? '\(^\|\s\+\)<<\($\|\s\+\)' && prevstat =~? '\s\+>>\($\|\s\+\)'
   31:   elseif prevstat =~? '\<\(if\|iferr\|then\|else\|elseif\|select\|case\|do\|until\|while\|repeat\|for\|start\|default\)\>' || prevstat =~? '\(^\|\s\+\)<<\($\|\s\+\)'
   32:     let ind = ind + &sw
   33:   endif
   34: 
   35:   if prevstat =~? '/\*'
   36:     let ind = ind + 1
   37:   endif
   38: 
   39:   " Subtract a shiftwidth from then, else, elseif, end, until, repeat, next,
   40:   " step
   41:   let line = getline(v:lnum)
   42:   if line =~? '^\s*\(then\|else\|elseif\|until\|repeat\|next\|step\|default\|end\)\>'
   43:     let ind = ind - &sw
   44:   elseif line =~? '^\s*>>\($\|\s\+\)'
   45:     let ind = ind - &sw
   46:   endif
   47: 
   48:   if prevstat =~? '\*/'
   49:     let ind = ind - 1
   50:   endif
   51:   return ind
   52: endfunction
   53: 
   54: function RplGetFreeIndent()
   55:   " Find the previous non-blank line
   56:   let lnum = prevnonblank(v:lnum - 1)
   57: 
   58:   " Use zero indent at the top of the file
   59:   if lnum == 0
   60:     return 0
   61:   endif
   62: 
   63:   let ind=RplGetIndent(lnum)
   64:   return ind
   65: endfunction
   66: 
   67: " vim:sw=2 tw=130

CVSweb interface <joel.bertrand@systella.fr>