From 50b324b683558afaf417eb674b8a8171bd1b0c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Tue, 16 Oct 2018 23:30:47 +0100 Subject: [PATCH 1/4] lang/ocaml: always initialize merlin, but wait for a .merlin file for flycheck MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Edwin Török --- modules/lang/ocaml/config.el | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/lang/ocaml/config.el b/modules/lang/ocaml/config.el index 302c083a0..e25a7ff13 100644 --- a/modules/lang/ocaml/config.el +++ b/modules/lang/ocaml/config.el @@ -21,10 +21,8 @@ :defer t :init (defun +ocaml|init-merlin () - "Activate `merlin-mode' if the ocamlmerlin executable exists and the -current project possesses a .merlin file." - (when (and (projectile-locate-dominating-file default-directory ".merlin") - (executable-find "ocamlmerlin")) + "Activate `merlin-mode' if the ocamlmerlin executable exists." + (when (executable-find "ocamlmerlin") (merlin-mode))) (add-hook 'tuareg-mode-hook #'+ocaml|init-merlin) @@ -44,12 +42,15 @@ current project possesses a .merlin file." (def-package! flycheck-ocaml :when (featurep! :feature syntax-checker) - :after merlin - :config - ;; Disable Merlin's own error checking - (setq merlin-error-after-save nil) - ;; Enable Flycheck checker - (flycheck-ocaml-setup)) + :init + (defun +ocaml|init-flycheck () + "Activate `flycheck-ocaml` if the current project possesses a .merlin file." + (when (projectile-locate-dominating-file default-directory ".merlin") + ;; Disable Merlin's own error checking + (setq merlin-error-after-save nil) + ;; Enable Flycheck checker + (flycheck-ocaml-setup))) + (add-hook 'merlin-mode-hook #'+ocaml|init-flycheck)) (def-package! utop From cdd39b20a5742ae975cbb57b2877a0aa7e8f74d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Tue, 16 Oct 2018 23:35:52 +0100 Subject: [PATCH 2/4] lang/ocaml: add merlin-eldoc type and doc on hover display MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This displays the type and documentation of thing under point and highlights occurrences automatically when idle. Could be achieved by appropriate use of keyboard shortcuts already set up by this module. However `merlin-eldoc` can also display the expected type of function call parameters, which merlin itself wouldn't. Signed-off-by: Edwin Török --- modules/lang/ocaml/config.el | 4 ++++ modules/lang/ocaml/packages.el | 1 + 2 files changed, 5 insertions(+) diff --git a/modules/lang/ocaml/config.el b/modules/lang/ocaml/config.el index e25a7ff13..243ec5858 100644 --- a/modules/lang/ocaml/config.el +++ b/modules/lang/ocaml/config.el @@ -53,6 +53,10 @@ (add-hook 'merlin-mode-hook #'+ocaml|init-flycheck)) + (def-package! merlin-eldoc + :hook (merlin-mode . merlin-eldoc-setup)) + + (def-package! utop :when (featurep! :feature eval) :defer t ; loaded by hook below diff --git a/modules/lang/ocaml/packages.el b/modules/lang/ocaml/packages.el index 27af6197d..71128923f 100644 --- a/modules/lang/ocaml/packages.el +++ b/modules/lang/ocaml/packages.el @@ -3,6 +3,7 @@ (package! tuareg) (package! merlin) +(package! merlin-eldoc) (package! ocp-indent) (when (featurep! :feature syntax-checker) From a4a42d3141c445cf5a15cdbe8c83117d67870f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Wed, 17 Oct 2018 00:02:14 +0100 Subject: [PATCH 3/4] lang/ocaml: enable merlin-imenu and merlin-iedit (part of merlin) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit merlin-imenu works nicely with `SPC / i`. merlin-iedit is a refactoring tool that locates all occurences of an identifier in scope and you can use multiple cursors to edit. integration with evil-multiedit could be better. There is also a merlin-xref backend, but since we got the individual def/lookup/etc. already bound not sure if it is worth using it. Signed-off-by: Edwin Török --- modules/lang/ocaml/config.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/lang/ocaml/config.el b/modules/lang/ocaml/config.el index 243ec5858..f44e2f1b2 100644 --- a/modules/lang/ocaml/config.el +++ b/modules/lang/ocaml/config.el @@ -57,6 +57,19 @@ :hook (merlin-mode . merlin-eldoc-setup)) + (def-package! merlin-iedit + :when (featurep! :editor multiple-cursors) + :hook (merlin-mode . merlin-use-merlin-imenu) + :config + (map! :map tuareg-mode-map + :v "R" #'merlin-iedit-occurrences)) + + + (def-package! merlin-imenu + :when (featurep! :emacs imenu) + :hook (merlin-mode . merlin-use-merlin-imenu)) + + (def-package! utop :when (featurep! :feature eval) :defer t ; loaded by hook below From a1ca5b2850248f6bd4c1f90464163f448ae2c277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Wed, 17 Oct 2018 00:13:20 +0100 Subject: [PATCH 4/4] lang/ocaml: update README MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Edwin Török --- modules/lang/ocaml/README.org | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/modules/lang/ocaml/README.org b/modules/lang/ocaml/README.org index 53fa6db12..9154077b8 100644 --- a/modules/lang/ocaml/README.org +++ b/modules/lang/ocaml/README.org @@ -2,7 +2,8 @@ This module adds [[https://ocaml.org/][OCaml]] support, powered by [[https://github.com/ocaml/tuareg][tuareg-mode]]. -+ Code completion, look up documentation, and code navigation ([[https://github.com/ocaml/merlin/wiki/emacs-from-scratch][merlin]]) ++ Code completion, documentation look-up, code navigation and refactoring ([[https://github.com/ocaml/merlin/wiki/emacs-from-scratch][merlin]]) ++ Type, documentation and function argument display on idle ([[https://github.com/Khady/merlin-eldoc][merlin-eldoc]]) + REPL ([[https://github.com/ocaml-community/utop][utop]]) + Syntax-checking (~merlin~ with [[https://github.com/flycheck/flycheck-ocaml][flycheck-ocaml]]) + Auto-indentation ([[https://github.com/OCamlPro/ocp-indent][ocp-indent]]) @@ -52,25 +53,32 @@ opam install merlin utop ocp-indent dune ocamlformat + when =:feature syntax-checker= is enabled then =flycheck-ocaml= is activated to do on-the-fly syntax/type checking via =merlin=, otherwise this is only done when the file is saved. -+ spell checking is activated in comments if =:feature spellcheck= is actived -+ a REPL is provided if =utop= is installed and =:feature eval= is actived ++ spell checking is activated in comments if =:feature spellcheck= is active ++ a REPL is provided if =utop= is installed and =:feature eval= is active + if =:editor format= is enabled, the =ocamlformat= executable is available and there is an =.ocamlformat= file present then =format-all-buffer= is bound to =ocamlformat=, otherwise to =ocp-indent= ++ if =:editor multiple-cursors= is enabled then identifiers can be refactored + with =v R= and multiple cursors (this correctly matches identifier occurrences + according to scope, it is not purely a textual match) ++ if =:emacs imenu= is enabled then top level symbols (modules, type, functions, etc.) can + be looked up using =SPC / i= Run =make install= to install all packages, and =make doctor= to diagnose missing tools. * Appendix ** Commands - | command | key / ex command | description | - |------------------------------+------------------+------------------------------------| - | =merlin-type-enclosing= | =SPC m t= | display type under point | - | =tuareg-find-alternate-file= | =SPC m a= | switch between =.ml= and =.mli= | - | =merlin-locate= | =gd= | lookup definition | - | =merlin-occurences= | =SPC c D= | lookup references | - | =merlin-document= | =K= | lookup documentation | - | =utop= | =SPC o r= | open =utop= as REPL | - | =utop-eval-region= | =SPC c e= | evaluate selected region in =utop= | + | command | key / ex command | description | + |------------------------------+------------------+-----------------------------------------------------------| + | =merlin-type-enclosing= | =SPC m t= | display type under point | + | =tuareg-find-alternate-file= | =SPC m a= | switch between =.ml= and =.mli= | + | =merlin-locate= | =gd= | lookup definition | + | =merlin-occurences= | =SPC c D= | lookup references | + | =merlin-document= | =K= | lookup documentation | + | =merlin-imenu= | =SPC / i= | symbol lookup in file | + | =merlin-iedit-occurrences= | =v R= | visual refactor identifier under point (multiple cursors) | + | =utop= | =SPC o r= | open =utop= as REPL | + | =utop-eval-region= | =SPC c e= | evaluate selected region in =utop= | ** Hacks + =set-pretty-symbols!= is called with the full tuareg prettify symbol list, this