tuareg
tuareg copied to clipboard
Completion in the *OCaml* buffer
Configuration: OCaml 4.14.0 - Emacs 29.0.50 - Tuareg (v20220929.1327) - Merlin - Linux Box x86_64
By default, I have no completion in the *OCaml* buffer. Now, if I run 'M-x merlin-mode' I get the message 'Merlin mode disabled in current buffer' and ,oh surprise, the completion appears (in this *OCaml* buffer).
So,three questions:
- Why this (strange) behavior? Is it specific to my Emacs setup?
- Would it be possible to have a completion by default in the OCaml REPL?
Note: The emacs mode of Merlin provides 3 ways to achieve completion:
- auto-complete (not tested).
- company-mode : tested OK.
- completion-at-point : tested OK.
Eventually, this third way (being the native completion engine of Emacs) seems a good candidate to use.
There's no way for Merlin to provide completion candidates directly for the top-level, as it operates on source files. utop.el
uses utop's completion API to provide completion within the top-level and plays nicely with tuareg-mode
.
Small experiment: (same configuration except for Tuareg now v3.0.1)
Using a very basic init.el (with tuareg, merlin, company, and NOTHING else) I get the same behavior.
e.g. with this ugly code (idem with eval-region & eval-buffer):
(defun my-tuareg-eval-phrase ()
(interactive)
(tuareg-eval-phrase)
(set-buffer "*OCaml*")
(merlin-mode))
I have the completion in the OCaml REPL. (completion-at-point alone works too).
So I guess it must be possible to properly incorporate a completion in the Tuareg's interactive mode.
I'll have to take a closer look at where Merlin pulls the candidates from exactly, but I can't imagine how exactly something like this will work. E.g. do completion candidates update after you load stuff in the toplevel or reload the code there? I'm also puzzled by the command you've shared - you first eval something in a source file (I presume), then set the current buffer to the REPL and you enable merlin-mode
there? If merlin-mode
works in the toplevel buffer you can just enable it there and be done with it.