Acme plumbing rules for OCaml

I am sure that the intersection of OCaml users and Acme users is small, but I have reason to believe it is a non-zero set :slight_smile: . For those of you using this spartan editor, here are some plumbing rules that I use that allow me to right-click on error messages returned by the OCaml compilers, and jump to the referenced location in acme:

# example: in file "foo/bar.ml", line 155, characters 30-62
type	is	text
data	matches	'.*[Ff]ile "([^"]+)", line ([0-9]+), characters ([0-9]+)-([0-9]+).*'$nl'?'
arg	isfile	$1
data	set	$file
attr	add	addr=$2-#0+#$3,$2-#0+#$4
plumb	to	edit
plumb	client	$editor

# example: File "tests/dune", line 2, characters 7-22:
type	is	text
data	matches	'.*[Ff]ile "([^"]+)", lines ([0-9]+)-([0-9]+).*'$nl'?'
arg	isfile	$1
data	set	$file
attr	add	addr=$2,$3
plumb	to	edit
plumb	client	$editor

It could probably be extended to search ~/.opam so you could plumb errors in files outside of your project, but I do not use opam, so I haven’t needed to do it.

Here is a short demo of its use: Plumb OCaml error messages from acme - YouTube

It’s not in OCaml, but I also wrote https://github.com/droyo/acme-autoformat and put an OcamlFmt script in acme’s $PATH like so:

#!/bin/sh
exec /usr/local/bin/acme-autoformat -r '\.mli?$' \
	-- ocamlformat --name='{{.Basename}}' --enable-outside-detected-project -

This calls ocamlformat whenever I Put an .ml[i] file. This is probably obviated by combining acme-lsp and ocaml-lsp, but these two bits work well enough that I haven’t felt a need to pursue it.

4 Likes

What’s your setup re: lsp/merlin? Is it just “out of the box”?
I haven’t used acme in a while but I’d give it another go if I can get good language support.

I do not use merlin or LSP. In general I find auto-completion distracting and try to avoid languages or coding styles where it is necessary.

I usually have an acme window running dune test -w, which is enough to give me feedback on typos and the like.

I would like a better way to view documentation for a function or jump to the definition of a symbol outside of my project, though. Currently i just view odig odoc output in a browser.

I’d would like to make this easier via odig doc too.

It is on my very long todo list to integrate the new odoc html-url command in odig to make it easy to jump to the docs of a given identifier.

1 Like

Nice! thanks for the rules!. I had a set up using the LSP and acme (with acme-lsp):

Not sure if it still works, as acme-lsp has changed. I’ll post it here for anyone interested.

1 Like