tuareg
tuareg copied to clipboard
Emacs hangs during typing
When opening the first *.ml
file in a fresh Emacs session in Tuareg mode, during typing code, Emacs suddenly hangs. The whole user interface blocks for many seconds, showing the following message in the Emacs status line:
Scanning module /usr/lib/ocaml//pervasives.mli
There are multiple issue I see here. First, why does it suddenly need to scan pervasives.mli
and why does this take so long? Second, why does the whole user interface block, rather than doing this in the background? Third, why does it check the system's pervasives.mli
even though I'm in a local OPAM switch? (i.e. subdirectory _opam
exists)
It is related to “autocomplete” (part of caml-mode and bound to C-c TAB
in Tuareg). It should not be triggered unless you explicitly ask for it. For autocompletion, you should install Merlin.
Thanks for the insights. So please let me clarify the bug report:
First, this "autocomplete" mechanism is triggered by just typing code, without hitting C-c TAB
or any other keyboard shortcut. Second, it is blocking. I believe both points are bugs, even though fixing one of them would already remove the pain.
What should I do to further analyze this bug? What modifications should I try? What information do you need?
First, this "autocomplete" mechanism is triggered by just typing code, without hitting
C-c TAB
or any other keyboard shortcut.
I think autocomplete
here refers to the Emacs package by that name.
In that case, indeed by design it kicks in just "as you type" without
having to trigger it explicitly. But it's not distributed with Emacs,
so you have to install & enable it manually before this happens.
I see.
The "auto-complete" was innocent, but I had the "company" package installed and globally activated. That was the problem.
I turned "company" globally off, and the bug vanished. Thanks!
The "auto-complete" was innocent, but I had the "company" package installed and globally activated. That was the problem.
Indeed, company
is another package offering the same kind of
functionality as autocomplete
.
I turned "company" globally off, and the bug vanished. Thanks!
Good to know. This said, it would be good to make company-mode usable, or at least not force you to turn it off globally.
My suspicion is that the following happens:
- company-mode uses its company-capf backend which lets it take advantage of the completion-at-point-functions that the major-mode may have set.
- tuareg adds tuareg-completion-at-point to completion-at-point-functions.
- tuareg-completion-at-point uses caml-mode's ocaml-module-symbols to provide completion.
- probably ocaml-module-symbols (or ocaml-module-alist or ocaml-visible-modules) is the long-running function.
When the completion is triggered explicitly by a call to
completion-at-point
, this is probably good enough, but when
tuareg-completion-at-point is triggered by company-mode as a side-effect
of innocent typing this is not acceptable.
So while you've found a workaround, I think the problem still deserves to have its own issue and we should try and fix it.
Ok. One more detail that is perhaps relevant: With disabled company-mode, an explicit C-c TAB
makes the situation even worse: Not only pervasives.mli
is scanned, but all other *.mli
of stdlib as well, all blocking. I waited some time, but finally had to kill Emacs to be able to continue working. And this all happened with configured merlin and ocp-indent.