28

I'd like to take an existing application (written in OCaml) and create an Emacs "interface" for it (like, for example, the Emacs GDB mode). I would prefer to do this without writing a ton of Lisp code. In MVC terms, I'd like for the View to be Emacs, but for the Model and Controller to remain (primarily) OCaml.

Does anybody know of a way to write Emacs extensions in a language other than Lisp? This could either take the form of bindings to the Emacs extension API in some other language (e.g., making OCaml a first-class Emacs extension language) or an Emacs interaction mode where, for example, the extension has a pipe into which it can write Emacs Lisp expressions and read out result values.

Chris Conway
  • 55,321
  • 43
  • 129
  • 155
  • I recommend you take a look at how merlin does it, as suggested by Erik Allik, e.g. https://github.com/the-lambda-church/merlin/blob/master/emacs/merlin.el#L430 starts a process, and https://github.com/the-lambda-church/merlin/blob/master/emacs/merlin.el#L631 sends a command to the ocaml merlin process, with an async handler. – unhammer Feb 23 '15 at 11:33

6 Answers6

14

http://www.emacswiki.org/cgi-bin/emacs-en?CategoryExtensionLanguage is a list of all non-Elisp extension languages you can use.

It does appear to be dynamic language centric.

http://common-lisp.net/project/slime/ is missing from that list, as it is not quite an extension language, but an Elisp-Common Lisp bridge. Its source code would show how to communicate back and forth over sockets.

A similar IDE for Erlang is Distel, at http://fresh.homeunix.net/~luke/distel/ (currently down) and https://github.com/massemanet/distel.

Good luck!

Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111
Dwight Holman
  • 1,570
  • 14
  • 15
4

I don't know if this will work for your particular problem, but I have been doing something similar using the shell-command-to-string function:

(shell-command-to-string
    "bash -c \"script-to-exec args\"")

So for example, we have existing scripts written in python which will mangle a file, so the above lets me invoke the script via emacs lisp.

A quick google search found this page describing a system to write extensions in Python, so it seems feasible to do what you want... you will just have to see if anyone has written a similar framework for OCaml.

Mike Stone
  • 44,224
  • 30
  • 113
  • 140
3

Some Extension Api is now possible with the incoming emacs 25.1 and dynamic modules

A Library, emacs-ffi offer a foreign function interface based on libffi.

Check out complete documentation on the README.

AdrieanKhisbe
  • 3,899
  • 8
  • 37
  • 45
3

Try PyMacs, which allows extending Emacs in Python.

edit: updated link.

Nikolai Prokoschenko
  • 8,465
  • 11
  • 58
  • 97
2

From the statically typed languages side, there is something that looks quite performant and well featured for Haskell:

https://github.com/knupfer/haskell-emacs

there is also probably something useful for Scala to be reused from the Ensime project (has a bridge for both Emacs and Vim):

https://github.com/ensime/ensime-server

Furthermore, a quick google search revealed another potential candidate for extending Emacs with a classic FP language, OCaml; the project has a lot of .ml source files so there's got to be an Emacs-OCaml bridge somewhere:

https://github.com/the-lambda-church/merlin

Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111
0

There is no "Extension API". Emacs Lisp is way in there, and it ain't moving.

You can run Emacs commands from your other process. Have a look at Gnuserv.

There are plenty of applications where Emacs is the View for a Model/Controller in a separate process. The Emacs GDB interface is a good example. I'm not sure of a simpler example, maybe sql-postgresql?

jfm3
  • 36,964
  • 10
  • 32
  • 35