I have been trying during my free time to create a small Emacs package to automatically display the type of the element under the point after a small delay. You move the cursor on a word, wait 0.5s and it will do the same thing as M-x merlin-type-enclosing. The package is of coursed based on merlin.
This is inspired by what exist in the emacs-lisp mode (which displays information about the value at point in the message box), tide (which displays the type under the point) and what exist in other editors.
This is not very clean or nice. But it covers basic usage (I think). And I am now seeking for help.
What is necessary to make it really usable:
Make it a real mode. I don’t know how to do that exactly. I mostly copy/pasted this part, so it needs a refresh.
Stop the auto display when an action is going on. For example if the cursor is moved in a string, then execute C-h k RET C-c C-t, the help for the keybinding is not displayed. The action is interrupted.
Publish on melpa or something like this.
Nice improvements that I would like to have:
Highlight of all occurrences. The position of all occurrences can be taken from merlin-occurrences so it shouldn’t be too hard to too. But I don’t know yet how to handle highlighting of multiple values and how to remove the highlight later. I think I need to import more pieces from merlin--type-enclosing-after.
Cleanup the code to follow good emacs lisp practices.
If you know some emacs lisp and can give advice or if you can contribute a patch, it would be very cool.
The name of the package is not definitive. Ideas are welcomed for this too.
I hope this presentation is clear enough. Not a native english speaker. Please ask any question is something needs more details.
I recorded a short screencast to help understand what the tool is now doing:
In the list of features that I would like to add, there is also the display of documentation. If the type is one line long and the documentation is short too, it might be possible to display it in a nice way.
Thanks @Khady, this looks really neat! Kind of a nice alternative to VSCode’s hover feature.
I’m using Spacemacs, not too familiar with elisp too, so I’m currently not too sure of what to do with the script (perhaps dumping it to user-init or user-config would work?). I’ll give it a shot when I have time.
I don’t know how spacemacs works exactly. So I will try to provide something generic that should work with a plain emacs or spacemacs. If it doesn’t work with spacemacs I will try to setup one and try myself, but it might have to wait a few days.
First the file has to be loaded.
The easiest way to just try would be to open the file in emacs and execute M-x eval-buffer. The
The more definitive way would be to put the file in the load path. Something like ~/.emacs.d or ~/.emacs.d/site-lisp. Then a (require 'merlin-auto-hl) line should be added to init.el.
The second step is to enable to minor mode. This can be done with M-x merlin-hl-identifier-mode.
To enable to mode automatically, a hook can be added. Something like (add-hook 'tuareg-mode-hook 'merlin-hl-identifier-mode) to add in init.el.
I will try to come up with a Readme to summarize this kind of info.
The repository has been updated. There is a proper readme. Including installation and usage sections. It can be installed using quelpa, so there is no need to clone the repository by hand. Also some bugs have been fixed.
I think this is ready for usage now. And I will try to add features.
Possibly – although it would be nice to keep merlin out of the pecularities of each editor. I remember having a short discussion about a similar feature (type-on-hover) for vim on the merlin github page, but that soon devolved into dealing with vim-specific quirks and was then abandoned. I am wondering how merlin relates to the language-server concept, where different editors all use a common interface to enable language autocompletion etc?
I don’t mind trying to integrate this code in another project later. But for now I think it is easier to let it in an independent repository. It means less burden for the maintainers of the other projects. And it gives me more time to work on improvements and bug fixes. Some people reported me bad behaviors and changes to do on reddit for example.
Latest demo (without all the fixes, but with all the features):
I have been asked how it compares to what is provided by lsp-mode and lsp-ocaml. I find that merlin-eldoc is way more polished. For example it keeps the documentation as ocamldoc rather than markdown, it highlights the types, it can reformat type and doc to fit one line, … It also offers more configuration options. But they are not exclusive, it is possible to use lsp-ocaml + merlin-eldoc (+ merlin too if you miss commands like merlin-destruct).