Bram Moolenaar | db6ea06 | 2014-07-10 22:01:47 +0200 | [diff] [blame] | 1 | " Vim indent file |
| 2 | " Language: Rrst |
| 3 | " Author: Jakson Alves de Aquino <jalvesaq@gmail.com> |
Bram Moolenaar | 77cdfd1 | 2016-03-12 12:57:59 +0100 | [diff] [blame] | 4 | " Homepage: https://github.com/jalvesaq/R-Vim-runtime |
| 5 | " Last Change: Tue Apr 07, 2015 04:38PM |
Bram Moolenaar | db6ea06 | 2014-07-10 22:01:47 +0200 | [diff] [blame] | 6 | |
| 7 | |
| 8 | " Only load this indent file when no other was loaded. |
| 9 | if exists("b:did_indent") |
| 10 | finish |
| 11 | endif |
| 12 | runtime indent/r.vim |
| 13 | let s:RIndent = function(substitute(&indentexpr, "()", "", "")) |
| 14 | let b:did_indent = 1 |
| 15 | |
| 16 | setlocal indentkeys=0{,0},:,!^F,o,O,e |
| 17 | setlocal indentexpr=GetRrstIndent() |
| 18 | |
| 19 | if exists("*GetRrstIndent") |
| 20 | finish |
| 21 | endif |
| 22 | |
| 23 | function GetRstIndent() |
| 24 | let pline = getline(v:lnum - 1) |
| 25 | let cline = getline(v:lnum) |
| 26 | if prevnonblank(v:lnum - 1) < v:lnum - 1 || cline =~ '^\s*[-\+\*]\s' || cline =~ '^\s*\d\+\.\s\+' |
| 27 | return indent(v:lnum) |
| 28 | elseif pline =~ '^\s*[-\+\*]\s' |
| 29 | return indent(v:lnum - 1) + 2 |
| 30 | elseif pline =~ '^\s*\d\+\.\s\+' |
| 31 | return indent(v:lnum - 1) + 3 |
| 32 | endif |
| 33 | return indent(prevnonblank(v:lnum - 1)) |
| 34 | endfunction |
| 35 | |
| 36 | function GetRrstIndent() |
| 37 | if getline(".") =~ '^\.\. {r .*}$' || getline(".") =~ '^\.\. \.\.$' |
| 38 | return 0 |
| 39 | endif |
| 40 | if search('^\.\. {r', "bncW") > search('^\.\. \.\.$', "bncW") |
| 41 | return s:RIndent() |
| 42 | else |
| 43 | return GetRstIndent() |
| 44 | endif |
| 45 | endfunction |
| 46 | |
| 47 | " vim: sw=2 |