view runtime/indent/idlang.vim @ 9998:3063d1acd0c9 v7.4.2272

commit https://github.com/vim/vim/commit/9f8187c335b4fb07be9095dfdd0fc52670ba3c3f Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 27 20:34:01 2016 +0200 patch 7.4.2272 Problem: getbufinfo(), getwininfo() and gettabinfo() are inefficient. Solution: Instead of making a copy of the variables dictionary, use a reference.
author Christian Brabandt <cb@256bit.org>
date Sat, 27 Aug 2016 20:45:05 +0200
parents dd6c2497c997
children 63b0b7b79b25
line wrap: on
line source

" IDL (Interactive Data Language) indent file.
" Language: IDL (ft=idlang)
" Last change:	2012 May 18
" Maintainer: Aleksandar Jelenak <ajelenak AT yahoo.com>

" Only load this indent file when no other was loaded.
if exists("b:did_indent")
   finish
endif
let b:did_indent = 1

setlocal indentkeys=o,O,0=endif,0=ENDIF,0=endelse,0=ENDELSE,0=endwhile,0=ENDWHILE,0=endfor,0=ENDFOR,0=endrep,0=ENDREP

setlocal indentexpr=GetIdlangIndent(v:lnum)

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

function GetIdlangIndent(lnum)
   " First non-empty line above the current line.
   let pnum = prevnonblank(v:lnum-1)
   " v:lnum is the first non-empty line -- zero indent.
   if pnum == 0
      return 0
   endif
   " Second non-empty line above the current line.
   let pnum2 = prevnonblank(pnum-1)

   " Current indent.
   let curind = indent(pnum)

   " Indenting of continued lines.
   if getline(pnum) =~ '\$\s*\(;.*\)\=$'
      if getline(pnum2) !~ '\$\s*\(;.*\)\=$'
	 let curind = curind+&sw
      endif
   else
      if getline(pnum2) =~ '\$\s*\(;.*\)\=$'
	 let curind = curind-&sw
      endif
   endif

   " Indenting blocks of statements.
   if getline(v:lnum) =~? '^\s*\(endif\|endelse\|endwhile\|endfor\|endrep\)\>'
      if getline(pnum) =~? 'begin\>'
      elseif indent(v:lnum) > curind-&sw
	 let curind = curind-&sw
      else
	 return -1
      endif
   elseif getline(pnum) =~? 'begin\>'
      if indent(v:lnum) < curind+&sw
	 let curind = curind+&sw
      else
	 return -1
      endif
   endif
   return curind
endfunction