* [Caml-list] Vim 6.0 OCaml indent file
@ 2001-08-23 0:56 Michael Leary
0 siblings, 0 replies; only message in thread
From: Michael Leary @ 2001-08-23 0:56 UTC (permalink / raw)
To: caml
This message sent separately to both of:
<caml-list@inria.fr>
<pleac-discuss@lists.sourceforge.net>
Now that vim 6.0 is in beta, it seems like a good time for me to throw out
what I've got so far (not much) for an ocaml ident file. It's been a while
since I looked at this, and I don't rightly recall how spiffy it was when I
left it. :-}
I would most appreciate any comments, critcisms, pointers, patches, flames,
and samples of money from around the world...
I've tried to follow the official OCaml style guide, but I've also tried to
choose consistency over fanciness -- mostly because its a lot easier to
code, and I'm no genius in either indent files or OCaml. :)
For reference, this is the notion of indenting that I've been working from.
Indent file follows.
(* either like the first one if not on one line, else like the second *)
let
...
in
let ... in
(* either like the first one if not on one line, else like the second *)
try
...
with
try ... with
...
(* either like the first one if not on one line, else like the second *)
match
...
with
match ... with
...
(* indent after a line ending with = *)
=
...
(* outdent when the line is just ;; *)
...
;;
(* um... I forget... outdent a line ending in ;; seems off... *)
...
...;;
(* indent after a line ending with 'then' *)
(* outdent a line starting with 'else' *)
then$
...
^else
(* indent after a line ending with 'begin' *)
(* outdent a line starting with 'end' *)
begin$
...
^end
" Vim indent file
" Language: OCaml
" Maintainer: Mike Leary <leary@nwlink.com>
" Last Change: 2001/06/28
" URL: http://www.nwlink.com/~leary/ocaml.vim
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetOCamlIndent()
setlocal nolisp
setlocal nosmartindent
setlocal indentkeys+==in,=with,=else,=end,=;;,=|
setlocal textwidth=80
" Only define the function once.
if exists("*GetOCamlIndent")
finish
endif
function GetOCamlIndent()
" Find a non-blank line above the current line.
let lnum = prevnonblank(v:lnum - 1)
" At the start of the file use zero indent.
if lnum == 0
return 0
endif
let ind = indent(lnum)
" indent after a line starts with 'let' and doesn't end with 'in'
if getline(lnum) =~ '^\s*\(\<let\>\)' && getline(lnum) !~ '\(\<in\>\)\s*$'
let ind = ind + &sw
endif
" indent after a line starts with 'try' or 'match' and doesn't end with 'with'
" and set the alignment for cases
if getline(lnum) =~ '^\s*\(\<try\>\|\<match\>\)' && getline(lnum) !~ '\(\<with\>\)\s*$'
let ind = ind + &sw
let align = indent(v:lnum)
endif
" indent after a line ends with '=', 'then', 'begin', or '->'
if getline(lnum) =~ '\(\<then\>\|\<begin\>\|->\|=\)\s*$'
let ind = ind + &sw
endif
" outdent immediately when a line starts with 'in', 'with', 'else', 'end', or ';;'
if getline(v:lnum) =~ '^\s*\(\<in\>\|\<with\>\|\<else\>\|\<end\>\|;;\)'
let ind = ind - &sw
endif
" outdent after a line ends with ';;', but had something before it
if getline(lnum) =~ '\s*\S+\s*;;\s*$'
let ind = ind - &sw
endif
" set indent to align when a line starts with '|'
if getline(v:lnum) =~ '^\s*|'
let ind = align
endif
return ind
endfunction
" vim:sw=2
--
Would you mind terribly much if I asked you
to take your silly-assed problem down the hall?
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2001-08-23 0:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-23 0:56 [Caml-list] Vim 6.0 OCaml indent file Michael Leary
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox