Giter Site home page Giter Site logo

ocamlpro / ocp-indent Goto Github PK

View Code? Open in Web Editor NEW
200.0 31.0 63.0 1.67 MB

Indentation tool for OCaml, to be used from editors like Emacs and Vim.

Home Page: http://www.typerex.org/ocp-indent.html

License: Other

OCaml 67.40% Standard ML 0.75% Shell 3.24% HTML 26.85% Emacs Lisp 1.39% Vim Script 0.36%

ocp-indent's Introduction

A simple tool and library to indent OCaml programs, developed and maintained by OCamlPro (Louis Gesbert). License: LGPL 2.1 with linking exception

Installation

Using OPAM

The simplest way to install ocp-indent is using OPAM:

opam install ocp-indent

By hand

You can also compile and install ocp-indent from sources. You'll need ocaml (>= 3.12.1) and ocp-build (>= 1.99.6-beta):

./configure
make
make install

If you use opam and want it installed alongside ocaml, you may want to use ./configure --prefix $(opam config var prefix).

Usage

The above installation step copies elisp scripts to <prefix>/share/emacs/site-lisp/ and vim scripts to <prefix>/share/ocp-indent/vim/. You then need to load them in the editor of your choice to automatically use ocp-indent.

Installing OPAM package user-setup will trigger automatic configuration for popular editors (emacs and vim currently, but more are in the works). If you prefer to handle your configuration manually, read on.

Emacs

Run the following command to setup tuareg-mode or caml-mode to use ocp-indent for indentation:

echo '(load-file "'"$(opam config var share)"'/emacs/site-lisp/ocp-indent.el")' >>~/.emacs

The tab key should now reindent the current line using ocp-indent.

Vim

Use the following command to tell Vim to use ocp-indent to indent OCaml code:

echo 'set rtp^="'"$(opam config var ocp-indent:share)"'/vim"' >>~/.vimrc

Automatic indentation as you type should take place, depending on your configuration. Use == to reindent the current line, and =G to reindent until the end of buffer.

Other editors

As ocp-indent is a command-line tool, you can easily integrate it with other editors.

ocp-indent <src-file> > <dst-file>

You can also tell it to indent only a subsets of lines, and to output only the indentation level:

ocp-indent <src-file> --lines <l1>-<l2> --numeric

Configuration options

By default, ocp-indent comes with sensible default parameters. However, you can customize some of the indentation options using command-line arguments. For more details, see:

ocp-indent --help

Configuration file

The same parameters can be defined in a configuration file, allowing for user defaults and per-project parameters. The latter is particularly convenient to transparently ensure consistency in projects with many contributors, without requiring them to change their settings in any way (except that, obviously, they need to use ocp-indent !).

If a .ocp-indent file is found in the current directory or its ancestors, it overrides definitions from $XDG_CONFIG_HOME/ocp/ocp-indent.conf, ~/.ocp/ocp-indent.conf and the built-in default. The command-line can of course still be used to override parameters defined in the files.

Have a look at ocp-indent's own .ocp-indent file for an example.

In-file configuration

There is no built-in support for in-file configuration directives. Yet, some editors already provide that features, and with emacs, starting your file with a line like:

(* -*- ocp-indent-config: in=2 -*- *)

will enable you to have the indentation after in setup to 2 locally on this file.

How does it compare to tuareg ?

We've run some benchmarks on real code-bases and the result is quite conclusive. Keep in mind than most of existing source files are either indented manually or following tuareg standards. You can see the results here.

Moreover, as ocp-indent has a deep understanding of the OCaml syntax it shines on specific cases. See for instance the collection of unit-tests here. The currently failing tests can be seen here.

Testing

It's hard to deliver a great indenter without tests. We've built ocp-indent based on a growing collection of unit-tests. If you find an indentation bug, feel free to send us a code snippet that we will incorporate into our test suite.

The tests are organized as follows:

  • tests/passing contains tests that are properly indented and should be left unchanged by ocp-indent.
  • tests/failing contains tests for which ocp-indent currently returns the results in tests/failing-output, hence meld tests/failing{,-output} should give an overview of currently known bugs (also available online here).
  • tests/test.sh checks the current state against the reference state (checked into git).
  • tests/test.sh --[git-]update updates the current reference state.
  • See tests/test.sh --help for more

Please make sure tu run make && tests/test.sh --git-update before any commit, so that the repo always reflects the state of the program.

Old Readme ocp-indent is a simple tool and library to indent OCaml code. ocp-indent is part of TypeRex, developed and maintained by OCamlPro. Documentation to install and use this tool is available on http://www.typerex.org/ocp-indent.html It is released under LGPL v2.1 with linking exception.

ocp-indent's People

Contributors

acieroid avatar altgr avatar chaudhuri avatar dbuenzli avatar dsheets avatar et7f3 avatar hcarty avatar hhugo avatar hnrgrgr avatar ivg avatar julow avatar kit-ty-kate avatar klakplok avatar lefessan avatar let-def avatar m-plamann avatar mussf avatar nojb avatar polazarus avatar pszilagyi avatar raphael-proust avatar rgrinberg avatar samoht avatar sheepduke avatar skyskimmer avatar syohex avatar thomasblanc avatar tony avatar vbmithr avatar yminsky-janestreet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ocp-indent's Issues

questionable indentation for some comments

Some neatly aligned comments come out a bit mangled by ocp-indent:

type t = {
  a : int ;
    (** blablabla *)
  b : int ;
    (** blublublu *)

  c : int ;
    (** ccc *)
}

let _ =
  [ A ;
    (* A *)
    B ;
    (* B *)
  ]

gets indented as:

type t = {
  a : int ;
  (** blablabla *)
  b : int ;
(** blublublu *)

  c : int ;
(** ccc *)
}

let _ =
  [ A ;
    (* A *)
    B ;
  (* B *)
  ]

Also, what about an option to completely disable indenting of comments ?

Indentation level is reset when encountering 'v}'

The following code is not indented correctly by ocp-indent

  let f x v = function
    | 1 -> { x with s = v} (* a space between v and } works fine *)
| _ -> x

Commenting the following rules in approx_lexer.mll fixes the issue:

| '{' [ '[' 'v' ]
| [ ']' 'v' ] '}'

What are these rules for?

support for lwt

Currently lwt syntax extension is not well supported. I guess it could be nice to have a generic way to handle this kind of things (maybe a layer on top of the lexer) and simply hard-code few keyworkds (the most important being lwt).

ocp-indent-0.9.0 build fails on 3.12.1


[4.2] mv src/approx_common.cmi _obuild/ocp-indent-lexer/approx_common.cmi
[5.1] BEGIN '/usr/bin/ocamldep.opt' '-modules' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_tokens.ml' > '_obuild/ocp-indent-lexer/approx_tokens.mlmods'
[5.1]   END '/usr/bin/ocamldep.opt' '-modules' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_tokens.ml'
[8.1] BEGIN '/usr/bin/ocamlc.opt' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' '_obuild/8/approx_tokens.cmo' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_tokens.ml' 
[8.1]   END '/usr/bin/ocamlc.opt' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' '_obuild/8/approx_tokens.cmo' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_tokens.ml'
[8.2] mv _obuild/8/approx_tokens.cmi _obuild/ocp-indent-lexer/approx_tokens.cmi
Error moving _obuild/8/approx_tokens.cmi to _obuild/ocp-indent-lexer/approx_tokens.cmi: Sys_error("No such file or directory")
    Source file _obuild/8/approx_tokens.cmi does not exist
make: *** [ocp-build.root] Error 2
The compilation of ocp-indent.0.9.0 failed.
Uninstalling ocp-indent.0.9.0:
  ./configure --prefix /x/pkg_opro_remote_all/compiler_system-packages_ocp-indent/system
  make uninstall

'with_never' might not be enough

We see often match statements enclosed in begin ... end blocks (looks better than parentheses … a bit like Coq).
By default ocp-indent will indent the match cases:

let m =
  begin match x with
    | 0 -> 0
    | 1 -> 1
  end

It looks better with 'with_never':

$ printf "let m =\nbegin match x with\n    | 0 -> 0\n   | 1 -> 1\nend\n"  | ocp-indent --config with_never=true
let m =
  begin match x with
  | 0 -> 0
  | 1 -> 1
  end

But then we loose 'with' indentation in all the other good cases

 $ printf "let m = function\n    | 0 -> 0\n   | 1 -> 1\nend\n"  | ocp-indent --config with_never=true
let m = function
| 0 -> 0
| 1 -> 1
end

PS: ocp-indent already seems to do something special for lines starting with (match ...:

 $ printf "let m =\n(match x with\n    | 0 -> 0\n   | 1 -> 1)\n"  | ocp-indent 
let m =
  (match x with
   | 0 -> 0
   | 1 -> 1)

--lines doesn't seem to work at all

Contents of test1.ml

let (quot, _rem) =
let quot_rem n k =
let (d, m) = (n / k, n mod k) in
if d < 0 && m > 0 then (d+1, m-k)
else (d, m)
in
let quot n k = fst (quot_rem n k) in
let rem n k = snd (quot_rem n k) in

quot, rem

$ ocp-indent test1.ml --lines '1-3'

let (quot, _rem) =
let quot_rem n k =
let (d, m) = (n / k, n mod k) in
if d < 0 && m > 0 then (d+1, m-k)
else (d, m)
in
let quot n k = fst (quot_rem n k) in
let rem n k = snd (quot_rem n k) in
quot, rem

Pass tests and agree on the expected results

Have a clear current state of the passing tests so that it's easy to check against it.
Then it would be easier to agree on exactly what the test results should be ; tests provided by JS now pass with a few exceptions, that seem to make sense to me but should be discussed:
(NB: JS will probably want to export match_clause_indent=2 type_indent=0 ; promise, there will be a proper way to configure soon)

Most notably, in nested structures, ocp-indent sometimes over-indents compared to tuareg. This ensures good indentation whatever comes next, but may be annoying to people who know what they are doing:

f (a (b
      c))

which makes sense if you add:

f (a (b
      c)
    d)
  e

Please let me know of any annoyances or if you would prefer a different behaviour in some cases.

fail to compile on osx (ocaml 3.12.1)

OSX 10.7 + opam 0.9.1 + compiler "3.12.1+natdynlink-osx"

####### CONFIGURE

Chartreuse:ocp-indent hugo$ ./configure
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for ocamlc... ocamlc
OCaml version is 3.12.1
OCaml library path is /Users/hugo/.opam/3.12.1+natdynlink-osx/lib/ocaml
checking for ocamlopt... ocamlopt
checking for ocamlc.opt... ocamlc.opt
checking for ocamlopt.opt... ocamlopt.opt
checking for ocaml... ocaml
checking for ocamldep... ocamldep
checking for ocamlmktop... ocamlmktop
checking for ocamlmklib... ocamlmklib
checking for ocamldoc... ocamldoc
checking for ocamlbuild... ocamlbuild
configure: creating ./config.status
config.status: creating Makefile.config
config.status: creating version.ocp

Executables will be installed in /usr/local/bin

########### MAKE

Chartreuse:ocp-indent hugo$ make
ocp-build -init -scan
ocp-build: Entering directory `/Users/hugo/local/src/besport/ocp-indent'
Cache: 0 digests loaded
Updating ocp-build.root
Scanning installed .ocp files in "/Users/hugo/.opam/3.12.1+natdynlink-osx/lib/ocaml"
Warning: 6 incomplete projects:
ocaml-asmcomp-amd64 in /Users/hugo/.opam/3.12.1+natdynlink-osx/lib/ocaml (library,ocp)
ocaml-driver in /Users/hugo/.opam/3.12.1+natdynlink-osx/lib/ocaml (library,ocp)
ocaml-utils in /Users/hugo/.opam/3.12.1+natdynlink-osx/lib/ocaml (library,ocp)
ocaml-parsing in /Users/hugo/.opam/3.12.1+natdynlink-osx/lib/ocaml (library,ocp)
ocaml-typing in /Users/hugo/.opam/3.12.1+natdynlink-osx/lib/ocaml (library,ocp)
ocaml-bytecomp in /Users/hugo/.opam/3.12.1+natdynlink-osx/lib/ocaml (library,ocp)
ABSENT "ocamlbytecomp" missed by 2 projects
ocaml-driver in /Users/hugo/.opam/3.12.1+natdynlink-osx/lib/ocaml (library,ocp)
ocaml-bytecomp in /Users/hugo/.opam/3.12.1+natdynlink-osx/lib/ocaml (library,ocp)
ABSENT "ocamloptcomp" missed by 1 projects
ocaml-asmcomp-amd64 in /Users/hugo/.opam/3.12.1+natdynlink-osx/lib/ocaml (library,ocp)
ABSENT "ocamlcommon" missed by 3 projects
ocaml-utils in /Users/hugo/.opam/3.12.1+natdynlink-osx/lib/ocaml (library,ocp)
ocaml-parsing in /Users/hugo/.opam/3.12.1+natdynlink-osx/lib/ocaml (library,ocp)
ocaml-typing in /Users/hugo/.opam/3.12.1+natdynlink-osx/lib/ocaml (library,ocp)
create _obuild/_mutable_tree/src/indentVersion.ml [unexisting]
Building using 1 cores
[1.1] BEGIN '/Users/hugo/.opam/3.12.1+natdynlink-osx/bin/ocamldep.opt' '-modules' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_common.mli' > '_obuild/ocp-indent-lexer/approx_common.mlimods'
[1.1] END '/Users/hugo/.opam/3.12.1+natdynlink-osx/bin/ocamldep.opt' '-modules' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_common.mli'
[4.1] BEGIN '/Users/hugo/.opam/3.12.1+natdynlink-osx/bin/ocamlc.opt' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' 'src/approx_common.cmi' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_common.mli'
[4.1] END '/Users/hugo/.opam/3.12.1+natdynlink-osx/bin/ocamlc.opt' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' 'src/approx_common.cmi' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_common.mli'
[4.2] mv src/approx_common.cmi _obuild/ocp-indent-lexer/approx_common.cmi
[5.1] BEGIN '/Users/hugo/.opam/3.12.1+natdynlink-osx/bin/ocamldep.opt' '-modules' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_tokens.ml' > '_obuild/ocp-indent-lexer/approx_tokens.mlmods'
[5.1] END '/Users/hugo/.opam/3.12.1+natdynlink-osx/bin/ocamldep.opt' '-modules' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_tokens.ml'
[8.1] BEGIN '/Users/hugo/.opam/3.12.1+natdynlink-osx/bin/ocamlc.opt' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' '_obuild/8/approx_tokens.cmo' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_tokens.ml'
[8.1] END '/Users/hugo/.opam/3.12.1+natdynlink-osx/bin/ocamlc.opt' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' '_obuild/8/approx_tokens.cmo' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_tokens.ml'
[8.2] mv _obuild/8/approx_tokens.cmi _obuild/ocp-indent-lexer/approx_tokens.cmi
Error moving _obuild/8/approx_tokens.cmi to _obuild/ocp-indent-lexer/approx_tokens.cmi: Sys_error("No such file or directory")
Source file _obuild/8/approx_tokens.cmi does not exist
make: *** [ocp-build.root] Error 2

Config param for struct and object

Hi, and thanks for making a serious indenter for OCaml! Here's a request to cover more coding styles.

I usually do not indent struct and object in code like:

module Foo (* possibly long line *) =
struct
...
end

class blah (* possibly long line *) =
object
...
end

The current behavior of ocp-indent is to indent struct and object in such cases. Would you consider adding a config key to control that behavior?

--lines parser bug

The parsing of --lines command line arguments doesn't work

$ ocp-indent --lines "2-3" test1.ml
Fatal error: exception Failure("Wrong --lines specification: 2-3")
Raised at file "pervasives.ml", line 22, characters 22-33
Called from file "arg.ml", line 151, characters 12-33
Called from file "arg.ml", line 202, characters 8-27
Called from file "arg.ml", line 216, characters 4-32

The problem is an array index problem. Line 31 of main.ml should be
(String.sub s (pos+1) (String.length s - (pos + 1)));;

Handle >|= like >>=

>>= has special treatment to avoid extra indentation on the following line. Lwt also provides >|= as an alias for Lwt.map. It would be nice to have these operators handled in a consistent manner.

fail to compile on debian (ocaml 3.12.1)

. ocp-build -init -scan
. ocp-build: Entering directory `/home/www/.opam/system/build/ocp-indent.0.9.0'
. Scanning installed .ocp files in "/usr/lib/ocaml"

  • Cache: 0 digests loaded
  • Updating ocp-build.root
  • create _obuild/_mutable_tree/src/indentVersion.ml [unexisting]
  • Building using 9 cores
  • [1.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_common.mli' > '_obuild/ocp-indent-lexer/approx_common.mlimods'
  • [5.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_tokens.ml' > '_obuild/ocp-indent-lexer/approx_tokens.mlmods'
  • [10.1] BEGIN '/usr/bin/ocamllex' '-o' '_obuild/_mutable_tree/src/approx_lexer.ml' 'src/approx_lexer.mll'
  • [18.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/pos.ml' > '_obuild/ocp-indent-utils/pos.mlmods'
  • [21.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/pos.mli' > '_obuild/ocp-indent-utils/pos.mlimods'
  • [27.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/util.ml' > '_obuild/ocp-indent-utils/util.mlmods'
  • [32.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/reader.ml' > '_obuild/ocp-indent-utils/reader.mlmods'
  • [35.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/reader.mli' > '_obuild/ocp-indent-utils/reader.mlimods'
  • [41.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/nstream.ml' > '_obuild/ocp-indent-utils/nstream.mlmods'
  • [1.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_common.mli'
  • [4.1] BEGIN '/usr/bin/ocamlc' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' 'src/approx_common.cmi' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_common.mli'
  • [5.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_tokens.ml'
  • [44.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/nstream.mli' > '_obuild/ocp-indent-utils/nstream.mlimods'
  • [18.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/pos.ml'
  • [52.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-lib' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' 'src/indentConfig.ml' > '_obuild/ocp-indent-lib/indentConfig.mlmods'
  • [21.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/pos.mli'
  • [24.1] BEGIN '/usr/bin/ocamlc' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' 'src/pos.cmi' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/pos.mli'
  • [27.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/util.ml'
  • [30.1] BEGIN '/usr/bin/ocamlc' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' '_obuild/30/util.cmo' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/util.ml'
  • [32.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/reader.ml'
  • [55.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-lib' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' 'src/indentConfig.mli' > '_obuild/ocp-indent-lib/indentConfig.mlimods'
  • [35.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/reader.mli'
  • [61.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-lib' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' 'src/indentBlock.ml' > '_obuild/ocp-indent-lib/indentBlock.mlmods'
  • [44.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/nstream.mli'
  • [64.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-lib' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' 'src/indentBlock.mli' > '_obuild/ocp-indent-lib/indentBlock.mlimods'
  • [41.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/nstream.ml'
  • [72.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' '-I' './_obuild/ocp-indent-lib' '_obuild/_mutable_tree/src/indentVersion.ml' > '_obuild/ocp-indent/indentVersion.mlmods'
  • [52.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-lib' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' 'src/indentConfig.ml'
  • [77.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' '-I' './_obuild/ocp-indent-lib' 'src/indentArgs.ml' > '_obuild/ocp-indent/indentArgs.mlmods'
  • [55.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-lib' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' 'src/indentConfig.mli'
  • [58.1] BEGIN '/usr/bin/ocamlc' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' 'src/indentConfig.cmi' '-I' './_obuild/ocp-indent-lib' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' 'src/indentConfig.mli'
  • [64.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent-lib' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' 'src/indentBlock.mli'
  • [80.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' '-I' './_obuild/ocp-indent-lib' 'src/indentArgs.mli' > '_obuild/ocp-indent/indentArgs.mlimods'
  • [4.1] END '/usr/bin/ocamlc' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' 'src/approx_common.cmi' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_common.mli'
  • [4.2] mv src/approx_common.cmi _obuild/ocp-indent-lexer/approx_common.cmi
  • [8.1] BEGIN '/usr/bin/ocamlc' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' '_obuild/8/approx_tokens.cmo' '-I' './_obuild/ocp-indent-lexer' '-I' './src' 'src/approx_tokens.ml'
  • [72.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' '-I' './_obuild/ocp-indent-lib' '_obuild/_mutable_tree/src/indentVersion.ml'
  • [75.1] BEGIN '/usr/bin/ocamlc' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' '_obuild/75/indentVersion.cmo' '-I' './_obuild/ocp-indent' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' '-I' './_obuild/ocp-indent-lib' '_obuild/_mutable_tree/src/indentVersion.ml'
  • [77.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' '-I' './_obuild/ocp-indent-lib' 'src/indentArgs.ml'
  • [86.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' '-I' './_obuild/ocp-indent-lib' 'src/indentPrinter.ml' > '_obuild/ocp-indent/indentPrinter.mlmods'
  • [80.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' '-I' './_obuild/ocp-indent-lib' 'src/indentArgs.mli'
  • [91.1] BEGIN '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' '-I' './_obuild/ocp-indent-lib' 'src/indentMain.ml' > '_obuild/ocp-indent/indentMain.mlmods'
  • [24.1] END '/usr/bin/ocamlc' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' 'src/pos.cmi' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/pos.mli'
  • [24.2] mv src/pos.cmi _obuild/ocp-indent-utils/pos.cmi
  • [25.1] BEGIN '/usr/bin/ocamlc' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' '_obuild/25/pos.cmo' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/pos.ml'
  • [91.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' '-I' './_obuild/ocp-indent-lib' 'src/indentMain.ml'
  • [26.1] BEGIN '/usr/bin/ocamlopt' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' '_obuild/26/pos.cmx' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/pos.ml'
  • [58.1] END '/usr/bin/ocamlc' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' 'src/indentConfig.cmi' '-I' './_obuild/ocp-indent-lib' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' 'src/indentConfig.mli'
  • [58.2] mv src/indentConfig.cmi _obuild/ocp-indent-lib/indentConfig.cmi
  • [38.1] BEGIN '/usr/bin/ocamlc' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' 'src/reader.cmi' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/reader.mli'
  • [86.1] END '/usr/bin/ocamldep' '-modules' '-I' './_obuild/ocp-indent' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' '-I' './_obuild/ocp-indent-lib' 'src/indentPrinter.ml'
  • [83.1] BEGIN '/usr/bin/ocamlc' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' 'src/indentArgs.cmi' '-I' './_obuild/ocp-indent' '-I' './src' '-I' './_obuild/ocp-indent-lexer' '-I' './_obuild/ocp-indent-utils' '-I' './_obuild/ocp-indent-lib' 'src/indentArgs.mli'
  • [30.1] END '/usr/bin/ocamlc' '-g' '-w' '+A-4-9' '-warn-error' '-c' '-o' '_obuild/30/util.cmo' '-I' './_obuild/ocp-indent-utils' '-I' './src' '-I' './_obuild/ocp-indent-lexer' 'src/util.ml'
  • [30.2] mv _obuild/30/util.cmi _obuild/ocp-indent-utils/util.cmi
  • Error moving _obuild/30/util.cmi to _obuild/ocp-indent-utils/util.cmi: Sys_error("No such file or directory")
  • Source file _obuild/30/util.cmi does not exist
  • make: *** [ocp-build.root] Error 2

`monadic binds' should not be indented

code using the '>>=' operator should be "flat"

  some_call () >>= fun result ->
  some_other call result
  >>= fun () ->
  return result

right now all the 'fun' are indented one step more

(It's ocp-indent from opam:

 $ ocp-indent --version
ocp-indent version 0.1.0

which comes from samoth/ocp-indent )

How to generate src/indentVersion.ml?

I just pulled (ce990dd) after some
time and got the following build error:

[ocp-indent]$ ocp-build
ocp-build: Entering directory `/mnt/local/janevg-data/pszilagyi/jane-elisp/test/ocaml/contrib/ocp-indent'
Cache: 0 digests loaded
File "/mnt/local/janevg-data/pszilagyi/jane-elisp/test/ocaml/contrib/ocp-indent/src/ocp-indent.ocp", line 1, characters -1--1:
Error: in project "ocp-indent", the source filename
        "src/indentVersion.ml" does not exist
RULE 72 (state active)
                SOURCE src/indentVersion.ml(not available)
        /janelibs/ocaml-4.00.1+jane1+with-fp/bin/ocamldep.opt -modules -I ./_obuild/ocp-indent -I ./src -I ./_obuild/ocp-indent-lexer -I ./_obuild/ocp-indent-utils -I ./_obuild/ocp-indent-lib src/indentVersion.ml > _obuild/ocp-indent/indentVersion.mlmods
                TARGET _obuild/ocp-indent/indentVersion.mlmods
EXIT STATUS 2

I had reconfigured in a clean clone.

I noticed the following line in ocp-indent.ocp:

 "indentVersion.ml" (ocp2ml) (* auto-generated by ocp-build *)

I don't know what this means, but maybe it's obvious to one familiar
with ocp-build why it's not building indentVersion.ml?

It looks like I have the latest ocp-build from github
(chambart/ocp-build@f6baf18).

Thanks!

;; is indented incorrectly

This indentation is incorrect:

module M = struct
  let () = ()
;;
end

It should be

module M = struct
  let () = ()
  ;;
end

Respect manually defined indentation

This one may be a little bit controversial (or hard to implement depending on how ocp-indent is designed). But on the other hand it seems all automatic indenters I used for languages so far worked that way.

Sometimes there may be legitimate reasons to indent manually. In that case ocp-indent should respect the user's manual identation. That is, in interactive mode, if the line above the current one is indented to a non-standard indent, ocp-indent should indent it as the line above.

For example tabbing on the ``B` line below:

let () = match x with 
            | `A -> "A"
   | `B -> "B"

should result in

let () = match x with 
            | `A -> "A"
            | `B -> "B"

Instead of indenting the ``Bline to (ifwith_never` is `true`)

let () = match x with 
            | `A -> "A"
| `B -> "B"

as is currently done.

Emacs installation issues

Tried to install on emacs 24.2.1 on osx with caml-mode of 4.00.1.

First, the invocation:

echo '(load-file "$(opam config var prefix)/share/typerex/ocp-indent/ocp-indent.el")' >> ~/.emacs

doesn't work for me, I had to replace $(opam config var prefix) by its value otherwise the loading of .emacs fails because the $ expression is not expanded.

Second, for some reasons I had to put the full path to ocp-indent in my .emacs as follows:

(setq ocp-indent-path "~/.opam/4.00.1/bin/ocp-indent")

otherwise the tool is not found. Note that tool I'm able to invoke the tool in the minibuffer of compilation mode so it doesn't seem to be a $PATH issue.

Vim script seems a bit too minimal

The current vim script does not use ocp-indent in a way that is really useful: it only filters one or several lines through the tool. As a result, indenting a single line usually does not result in the desired indentation, since the context is ignored.

Also, it seems that the --numeric option would be more lightweight than replacing parts of the buffer by ocp-indent's output.

Indentation of struct..end and sig..end blocks

The current behaviour is to unindent struct..end and sig..end blocks so that they are aligned with the module keyword. Eg

module M:
sig
  val i: int
end

module M =
struct
  let i = 42
end

whereas I'm used to having these blocks indented like begin...end:

module M:
  sig
    val i: int
  end

module M =
  struct
    let i = 42
  end

Was this designed on purpose?
Would you consider switching to the other behaviour or at least make this configurable?

For the moment I patch indentBlock.ml to reflect this behaviour:

===================================================================
--- indentBlock.ml
+++ indentBlock.ml
@@ -615,7 +615,7 @@
            replace KFun L (unwind (function KFun -> true | _ -> false) p)
        | p -> append KFun L (fold_expr p))
   | STRUCT ->
-      append KStruct L  (Path.maptop (fun n -> {n with pad=0}) t.path)
+      append KStruct L  (Path.maptop (fun n -> {n with pad=2}) t.path)
   | WHEN ->
       append KWhen L ~pad:(config.i_base + if starts_line then 0 else 2)
         (unwind (function
@@ -623,7 +623,7 @@
            | _ -> false)
            t.path)
   | SIG ->
-      append KSig L (Path.maptop (fun n -> {n with pad=0}) t.path)
+      append KSig L (Path.maptop (fun n -> {n with pad=2}) t.path)

   | OPEN ->
       if last_token t = Some LET then

Indentation of try with

Is there a reason why try with behaves differently as a begin end block ?

Expected:

let f x = begin
  ()
end

let f x = try
  ()
with e -> raise e

ocp-indent's output:

let f x = begin
  ()
end

let f x = try
    ()
  with e -> raise e

use ocamlbuild instead of ocp-build

Hi,

I just ported ocp-indent to OpenBSD. And it was an easy, but still annoying business to replace ocp-build (which is not ported) by ocamlbuild.

Christopher

Vim binding

I'll be glad to include them if vim users can provide me the snippets they use.

objects seems broken

The following code:

let x =
  object
    inherit foo
    method bar = ..
  end

does no indent properly.

indentation of if predicates

Sometimes I do:

if foo
&& bar then
  xxx

this is not very well supported by ocp-indent currently. Note: as ocp-indent displays the following correctly, I now tend to the following style instead:

if foo &&
   bar then
  xxx

However, I guess it would be nice if the first option was working as well.

Better emacs script

  • limit the part of the file that is re-parsed
  • indent-line should indent the cursor when on an empty line

first bracket in match

'*' for spaces

let _ =
  match a with
    | b ->
      c [
      ****d [
            e
          ]
        ]
    | b' ->
      (c' [
       **d' [
           e'
         ]
       ])

line wrap

Can ocp-indent line wrap? It never seems to wrap long OCaml code for me.

Handle tabs in input files

The partial indentation on multiline function application is wrong. For example, on this piece of code :

let x =
  my_fun
     arg1
     arg2

when you indent only the last line, you get this result :

let x =
  my_fun
     arg1
  arg2

If you indent the whole region, you get the first result.

indentation of nested poly-variants types

After a polymorphic variant case whose type contains itself another pair of brackets, the next variant gets it's type not indented properly.

We get this:

type tt = [
  | `a of int
  | `blskdjf of
    float
  | `problem_cause of [ `more_brackets ]
  | `problematic_case of
  string
]

but the last case should be:

  | `problematic_case of
    string
]

I use:

 $ ocp-indent --version
ocp-indent version 0.6.1

Funky indent of comments in mli files.

For me mli file indentations seems entirely broken. The following compilable mli shouldn't change:

(** Starting bla doc *)
type bla = 
  | Hup (** The hup case *)
  | Hap (** The hap case *)
(** Ending bla doc *)

type hop
(** Hop's documentation *)

type mip = 
  { fup : int; (** fup field *) 
    fip : int; (** fip field *) }
(** Mip's documentation *)

type t = Hey | Ho
(** Let's go. *)

type tp = [ `Hey | `Ho ] 
(** Tp doc.  
    Second line. *)

(** Starting function f doc *)
val f : 'a -> 'b 
(** Ending function f doc. *)

val g : 'a -> t 
(** Function g doc. 
    Second line. *)

val g : 'a -> [`Hey | `Ho ]
(** Let's go 
    Second line. *)

Going through ocp-indent results in the following completely disorganized result:

(** Starting bla doc *)
type bla = 
  | Hup (** The hup case *)
  | Hap (** The hap case *)
  (** Ending bla doc *)

type hop
(** Hop's documentation *)

type mip = 
  { fup : int; (** fup field *) 
    fip : int; (** fip field *) }
  (** Mip's documentation *)

type t = Hey | Ho
         (** Let's go. *)

type tp = [ `Hey | `Ho ] 
          (** Tp doc.  
              Second line. *)

(** Starting function f doc *)
val f : 'a -> 'b 
  (** Ending function f doc. *)

val g : 'a -> t 
  (** Function g doc. 
      Second line. *)

val g : 'a -> [`Hey | `Ho ]
              (** Let's go 
                  Second line. *)

Bad indent of else expression

I'm testing ocp-indent on my codebase and I'm finding new things.

If the else expression is not on the same as the else, the expression should not be indented (guideline reference). That is the following should remain unchanged

if c1 then e1 else
if c2 then e2 else
e3

if c1 then e1 else
e2

Instead ocp-indent does:

if c1 then e1 else
if c2 then e2 else
  e3

if c1 then e1 else
  e2

Here's a parseable test case that should be left unchanged:

if false then () else
if false then () else
()
;;

if false then () else
()
;;

if false
then () else
()
;;

if false
then () 
else
()
;;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.