diff options
Diffstat (limited to '')
| -rw-r--r-- | indent/ocaml.vim | 10 | ||||
| -rw-r--r-- | indent/omake.vim | 118 | 
2 files changed, 126 insertions, 2 deletions
diff --git a/indent/ocaml.vim b/indent/ocaml.vim index 73ab127a..2da3e15b 100644 --- a/indent/ocaml.vim +++ b/indent/ocaml.vim @@ -8,9 +8,13 @@ endif  "               Mike Leary           <leary@nwlink.com>  "               Markus Mottl         <markus.mottl@gmail.com>  " URL:          http://www.ocaml.info/vim/indent/ocaml.vim -" Last Change:  2010 Sep 04 - Added an indentation improvement by Mark Weber +" Last Change:  2013 Jun 29  "               2005 Jun 25 - Fixed multiple bugs due to 'else\nreturn ind' working  "               2005 May 09 - Added an option to not indent OCaml-indents specially (MM) +"               2013 June   - commented textwidth (Marc Weber) +" +" Marc Weber's comment: This file may contain a lot of (very custom) stuff +" which eventually should be moved somewhere else ..  " Only load this indent file when no other was loaded.  if exists("b:did_indent") @@ -23,7 +27,9 @@ setlocal indentexpr=GetOCamlIndent()  setlocal indentkeys+=0=and,0=class,0=constraint,0=done,0=else,0=end,0=exception,0=external,0=if,0=in,0=include,0=inherit,0=initializer,0=let,0=method,0=open,0=then,0=type,0=val,0=with,0;;,0>\],0\|\],0>},0\|,0},0\],0)  setlocal nolisp  setlocal nosmartindent -setlocal textwidth=80 + +" At least Marc Weber and Markus Mottl do not like this: +" setlocal textwidth=80  " Comment formatting  if !exists("no_ocaml_comments") diff --git a/indent/omake.vim b/indent/omake.vim new file mode 100644 index 00000000..cac4521a --- /dev/null +++ b/indent/omake.vim @@ -0,0 +1,118 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'ocaml') != -1 +  finish +endif + +" Vim indent file +" Language:         OMakefile + +if exists("b:did_indent") +  finish +endif +let b:did_indent = 1 + +setlocal indentexpr=GetMakeIndent() +setlocal indentkeys=!^F,o,O,<:>,=else,=endif +setlocal nosmartindent + +if exists("*GetMakeIndent") +  finish +endif + +let s:comment_rx = '^\s*#' +let s:rule_rx = '^[^ \t#:][^#:]*:\{1,2}\%([^=:]\|$\)' +let s:continued_rule_rx = '^[^#:]*:\{1,2}\%([^=:]\|$\)' +let s:continuation_rx = '\\$' +let s:assignment_rx = '^\s*\h\w*\s*[+?]\==\s*\zs.*\\$' +let s:folded_assignment_rx = '^\s*\h\w*\s*[+?]\==' +" TODO: This needs to be a lot more restrictive in what it matches. +let s:just_inserted_rule_rx = '^\s*[^#:]\+:\{1,2}$' +let s:conditional_directive_rx = '^ *\%(ifn\=\%(eq\|def\)\|else\)\>' +let s:end_conditional_directive_rx = '^\s*\%(else\|endif\)\>' + +function s:remove_continuation(line) +  return substitute(a:line, s:continuation_rx, "", "") +endfunction + +function GetMakeIndent() +  " TODO: Should this perhaps be v:lnum -1? +"  let prev_lnum = prevnonblank(v:lnum - 1) +  let prev_lnum = v:lnum - 1 +  if prev_lnum == 0 +    return 0 +  endif +  let prev_line = getline(prev_lnum) + +  let prev_prev_lnum = prev_lnum - 1 +  let prev_prev_line = prev_prev_lnum != 0 ? getline(prev_prev_lnum) : "" + +  " TODO: Deal with comments.  In comments, continuations aren't interesting. +  if prev_line =~ s:continuation_rx +    if prev_prev_line =~ s:continuation_rx +      return indent(prev_lnum) +    elseif prev_line =~ s:rule_rx +      return &sw +    elseif prev_line =~ s:assignment_rx +      call cursor(prev_lnum, 1) +      if search(s:assignment_rx, 'W') != 0 +        return virtcol('.') - 1 +      else +        " TODO: ? +        return &sw +      endif +    else +      " TODO: OK, this might be a continued shell command, so perhaps indent +      " properly here?  Leave this out for now, but in the next release this +      " should be using indent/sh.vim somehow. +      "if prev_line =~ '^\t' " s:rule_command_rx +      "  if prev_line =~ '^\s\+[@-]\%(if\)\>' +      "    return indent(prev_lnum) + 2 +      "  endif +      "endif +      return indent(prev_lnum) + &sw +    endif +  elseif prev_prev_line =~ s:continuation_rx +    let folded_line = s:remove_continuation(prev_prev_line) . ' ' . s:remove_continuation(prev_line) +    let lnum = prev_prev_lnum - 1 +    let line = getline(lnum) +    while line =~ s:continuation_rx +      let folded_line = s:remove_continuation(line) . ' ' . folded_line +      let lnum -= 1 +      let line = getline(lnum) +    endwhile +    let folded_lnum = lnum + 1 +    if folded_line =~ s:rule_rx +      if getline(v:lnum) =~ s:rule_rx +        return 0 +      else +        return &ts +      endif +    else +"    elseif folded_line =~ s:folded_assignment_rx +      if getline(v:lnum) =~ s:rule_rx +        return 0 +      else +        return indent(folded_lnum) +      endif +"    else +"      " TODO: ? +"      return indent(prev_lnum) +    endif +  elseif prev_line =~ s:rule_rx +    if getline(v:lnum) =~ s:rule_rx +      return 0 +    else +      return &ts +    endif +  elseif prev_line =~ s:conditional_directive_rx +    return &sw +  else +    let line = getline(v:lnum) +    if line =~ s:just_inserted_rule_rx +      return 0 +    elseif line =~ s:end_conditional_directive_rx +      return v:lnum - 1 == 0 ? 0 : indent(v:lnum - 1) - &sw +    else +      return v:lnum - 1 == 0 ? 0 : indent(v:lnum - 1) +    endif +  endif +endfunction  | 
