caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Michael Leary <leary@nwlink.com>
To: caml <caml-list@inria.fr>
Subject: [Caml-list] Vim 6.0 OCaml indent file
Date: Wed, 22 Aug 2001 17:56:58 -0700	[thread overview]
Message-ID: <20010822175658.C15239@jean.nwlink.com> (raw)

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


                 reply	other threads:[~2001-08-23  0:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010822175658.C15239@jean.nwlink.com \
    --to=leary@nwlink.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).