Writing Emacs extensions in languages other than Lisp - emacs

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.

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!

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.

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.

Try PyMacs, which allows extending Emacs in Python.
edit: updated link.

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

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?

Related

Is it possible for Emacs to show Erlang functions arity in echo area like for Elisp functions?

I've installed and configured Erlang language in my Emacs dotfiles, mostly following this guide: https://erlang-ls.github.io/editors/emacs/
But I'm just starting in Erlang and I don't really know how a Erlang development environment looks like, so I'm not sure if things "missing" aren't part of the Erlang development environment or if it's something I have configured wrong.
This is my current configuration: https://github.com/jacksonbenete/.emacs.d/blob/main/lm-emacs/languages/erlang.el
I don't have functions completions, it asks for a "tags-table" and I don't know what it is or where I can find it.
Also, I don't receive any hints in the echo-area, this would be very useful and it's my main question since I can live without completion.
Just like I can start writing a function in Lisp and receive some hints of arity and parameters in the echo area/minibuffer, can I receive the same hints while writing Erlang?
Maybe my lsp-server isn't configured correctly?
Or this is not something implemented for Erlang-mode and Erlang-ls?
edts is the way to go with emacs, it has autocomplete and code navigation. Originally I was using distel, but after this presentation I switched to edts
I compiled it with erlang 23.0, but once it is compiled, I develop on other versions without problems, like currently I'm using erlang 24.0
For managing different erlang versions on my system, I'm using kerl
This is my personal emacs configuration, I got most of it from internet and then I did personal customizations
Other than that, I use the templates that came with the erlang mode a lot (tempo-template-erlang-*)

How do I do this in Emacs?

In the video the guy was able to insert functions and classes by pressing some buttons. How do I set up my Emacs to do that? Did he just use auto insert mode or something?
You can try yasnippet, skeletons or several other template mechanisms for Emacs.
As suvayu indicated, the guy in that video is mostly using various template mechanisms in Emacs (this is actually not that impressive). If you want your mind to really be blown, have a look at Marco Barringer's SLIME video. In it, he demos how to use the Common Lisp SLIME mode in Emacs. Along the way, he shows how an expert Emacs user effectively utilizes Emacs to write code. First, just watch the movie. Then, if you want to know more details about what he's doing, read Peter Christensen's transcript of the movie (I wrote a blog entry just after the movie came out with comments from a number of good lisp programmers who had seen the movie). Once you've seen the movie and can understand what is happening in it, attempt to adopt some of the techniques demonstrated in that video using your preferred programming language.
You can also look onto SRecode module in CEDET package - it allows to implement context-sensitive templates (for example, some are available only inside class, etc.), and there are some for elisp, c++, java, etc.

what are the code completetion systems available for emacs core (23.3 or 24)?

I use auto-completion mode which is not inbuilt. good but not the best IMO. So I was wondering is there inbuilt generic plugins for completion in emacs like you see in IDEs.
to name,
dabbrev
hippie expansion
I think these two are different from auto-completion mode kind which I am looking for.
EDIT:
I like to extend one of any completion system to support a scripting language which I use regularly for scientific data visualization.
There is CEDET package in GNU Emacs starting from version 23, but it slightly outdated, and it's better to use CEDET from its repository. I have an article on setting and use CEDET from repository.
Why don't you want to use external packages? With new packaging system in GNU Emacs (package.el) and with things, like el-get, it's very easy to install new packages into GNU Emacs...
CEDET's autocompletion is the only drop-down completion package provided in core Emacs. The core in-place completion packages are hippie-expand and dabbrev.
The primary non-core packages which provide drop-down completion are auto-complete and company; the former appears to be the most popular these days.
There's also anything, which is an interactive completion package. While it doesn't provide drop-down completion at the cursor position, the way it works is really rather nice, so it's worth investigating.
With a bit of tweaking, dabbrev and hippie-expand can be a lot more effective than you might expect, but if you want something more visual and interactive, my advice is to look beyond the core packages and go for auto-complete or perhaps anything.
(For what it's worth, I use both hippie-expand and auto-complete myself.)
As a C programmer I tried http://cx4a.org/software/gccsense.
I read an interview where the CEDET author said that this is actually better because it hooks directly into gcc. However its quite a hassle to install gccsense because I had to compile a modified gcc. Once this package is included in distributions I would use it.
You may also want to try out predictive mode. While not exactly a code completion package, it comes close to it by predicting your frequently used words, which in a coding platform is definitely a limited vocabulary.
http://www.dr-qubit.org/emacs.php
The emacs wiki has a good explanation too.
http://www.emacswiki.org/emacs/PredictiveMode

How can I best do source code browsing inside Emacs?

I have a workflow where I use grep and other tools in a shell for searching in different projects even though my main editor is emacs. I usually work on bug fixing and minor development of source code that is often unknown to me so searching the code is important. The langages I mostly work in are php, ruby, java, perl and sometimes python.
Is there some common IDE extension in emacs that would enable me to have functionality like "goto definition" from multiple files that span all these languages? Are there some other modules that could be useful, either code browsing or indexed search?
If you want to work with lots of different languages, ctags is pretty flexible. See the EmacsWiki for instructions on integration of ctags.
Code browsing can mean a bunch of different things. The mode you mention of using grep implies to me you are looking for function definitions, or perhaps looking for uses of a particular function.
While CEDET supports all the languages you list (some with the ctags parser), starting fresh in a new source code area is something CEDEt isn't too good at until it has indexed the entire project for those tasks you listed. You can, however, use GNU Global or idutils. I think idutils supports more languages.
In CEDET, the `semantic-symref' and related commands will do a grep-like operation with grep, or global, or idutils (depending on what type of tag table you created.) Unlike grep style output, the symref output buffer shows which functions are using the command in question. You can then execute macros on the hits of the symbol you care about to do large refactoring operations.
CEDET also supports a tags like jump to function, though if you are already using something like ctags that works fine too. CEDET is better when it comes to handling polymorphism in some cases.
With CEDET, you can also get structured browsing via imenu, speedbar, and ECB (the emacs code browser). ECB is particularly good in that the methods buffer allows you to quickly navigate to different parts of a class. Particularly handy for classes where the pieces are spread around, like in C++. CEDET can even create cute UML diagrams of class inheritance structures which are connected to your code.
CEDET does take some learning, and some of the languages you list are not fully supported for all the tools, though the basic browsing discussed above should be ok.
etags-select (which you can get from ELPA) makes browsing your TAGS file nicer, in my experience, if you bind M-. to etags-select-find-tag.
As well as etags/ctags try running grep with M-x grep rather than in a shell, to get clickable links in Emacs rather than having to manually find the file and line matching the grep output.
For code browsing, you can also use M-x imenu-tree
Tags browsing, with dynamic completion, filtering (substring, regexp, fuzzy), cycling:
http://www.emacswiki.org/emacs/Icicles_-_Emacs_Tags_Enhancements

Eclipse Style Function Completions in Emacs for C, C++ and JAVA?

How Do I Get Eclipse Style Function Completions in Emacs for C, C++ and JAVA?
I love the power of the Emacs text editor but the lack of an "intellisense" feature
leaves me using Eclipse.
M-/ is a quick and dirty autocomplete based on the contents of your current buffer. It won't give you everything you get in Eclipse but is surprisingly powerful.
I can only answer your question as one who has not used Eclipse much. But! What if there was a really nice fast heuristic analysis of everything you typed or looked at in your emacs buffers, and you got smart completion over all that everywhere, not just in code?
M-x load-library completion
M-x global-set-key C-RET complete RET
When I was doing java development I used to use the:
Java Development Environment for Emacs (JDEE)
The JDEE will provide method name completion when you explicitly invoke a jdee provided function. It has a keyboard binding for this functionality in the jdee-mode.
The CEDET package provides completion for C/C++ & Java (and for some other languages). To initial customization you can take my config that i use to work with C++ projects
Right now, I'm using Auto Complete for Emacs. As a current Visual Studio and ex-Eclipse user, I can say that it rivals both applications quite well. It's still not as good as Microsoft's IntelliSense for C#, but some would say that C++ is notoriously difficult to parse.
It leverages the power of (I believe) the Semantic package from Cedet, and I find it feels nicer to use when compared to Smart Complete. It completes C++ members, local variables, etc. It's pretty good. However, it falls down on not being able to complete overloaded methods (it only shows the function once with no parameters, but thats a limitation of Cedet I believe), and other various things. It may improve in future though!
By the way, I could be wrong here, but I think you need an EDE project set up for the class member completion to work (just like you would normally with Semantic). I've only ever used it while having an EDE project, so I assume this is true.
Searching the web I find http://www.emacswiki.org/cgi-bin/wiki/EmacsTags#toc7 describing complete-tab in etags. It is bound to M-Tab by default. This binding may be a problem for you
Also, etags has some limits, which may annoy you...
The link also points to CEDET as having better symbol completion support.
Have you tried the emacs plugin for eclipse?
http://people.csail.mit.edu/adonovan/hacks/eclipse-emacs.html
I've written a C++-specific package on top of CEDET that might provide
what you want. It provides an Eclipse-like function arguments hint.
Overloaded functions are supported both for function arguments hint
and for completion.
Package is located here:
https://github.com/abo-abo/function-args
Make sure to check out the nice screenshot:
https://raw.github.com/abo-abo/function-args/master/doc/screenshot-1.png
auto-complete-clang is what you want. Can't go wrong with using an actual C++ compiler for completions.
The only problem it has is there's no way to know what -I and -D flags to pass to the compiler. There are packages for emacs that let you declare projects and then you can use that.
Personally, I use CMake for all C and C++ work so I wrote some CMake code to pass that information to emacs through directory-local variables. It works, but I'm thinking of writing a package that calls cmake from emacs so there's less intrusion.