Disable merlin automatically checking and highlighting matching types in emacs

I’m at a bit of a loss, but at some point Merlin started automatically checking the type of the expression under my cursor, and in the process highlighting all expressions with matching types. Unfortunately the highlighting is extremely distracting, especially when it highlights an entire match statement like in the second example image.

Does anyone know how to turn this off? I’m using spacemacs so I can’t completely rule it out from being a spacemacs issue, but the merlin-types buffer is open and updated in correspondence with the highlighting every time I move my cursor.

One curious thing I have noticed though is that the automatic types are the default OCaml types, whereas if I invoke merlin-type-enclosing directly it shows me the Jane Street base types since I’m using base.

For example, the auto types give me int -> char and manually invoking Merlin gives Base__Int.t -> Base.Char.t. I’m not sure if this is a clue, but I thought I’d include it.

Any ideas are much appreciated. This is driving me crazy!

Hi @evanm,

I think you’re observing merlin-eldoc, which is now included by default in spacemacs’ OCaml layer. I too find the highlighting distracting, and at some point disabled it with:

 '(merlin-eldoc-occurrences-face ((t nil))))

That’s not exactly correct. It highlights other occurrences of the same value, not everything with the same type. There’s an option to disable it. It is a bit different than what @CraigFe suggested as it will also skip some calls to merlin. Btw, there’s also a command to jump to the next or previous occurrence of the value under the point. I ended up using it all the time.

Merlin has a nice feature to follow type aliases when merlin-type-enclosing is called multiple times in a row over the same value. There is another configuration option to enable or disable this behavior in merlin-eldoc


Thank you both. @Khady this info is especially helpful. It’s funny, because the ability to hover over a value and get its type is something I’ve actually wanted for a long time, but when I finally got it I realized that I didn’t want it! Actually, that’s not true, this is a great feature that I really appreciate you implementing; all I needed to do was turn off the highlighting. Maybe I could even just change the typeface so that it bolds or underlines the value instead of highlighting it now that I know about merlin-eldoc.

As a side note, the main issue I have with the highlighting is actually screenshot two, where it highlights entire blocks of code. Do you know why that happens? I suppose that would still be a problem even if I replaced the highlight with bold or underline.

1 Like

For the second screenshot, the “problem” is within merlin. Because the point is on ->, merlin determines that the value for which you are asking the type is the whole pattern matching. It is complicated to determine that in this situation it would be better to do nothing.

Makes sense, thank you!

Maybe another configuration setting could be added, to disable highlighting of values that are taking more than X lines. It would remove a large share of the most annoying behavior.

1 Like