Skip to content

Commit

Permalink
fix: Apply review suggestions by @monnier
Browse files Browse the repository at this point in the history
  • Loading branch information
erikmd committed Jul 12, 2023
1 parent 7212437 commit 88533b8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ unreleased
behavior can be enabled permanently by customizing
`merlin-construct-with-local-values` (#1644)
- emacs: add support for opam-switch-mode (#1654, fixes #1591)
To fully benefit from `M-x opam-switch-mode`, the Merlin command
must be a filename, e.g., `(setq merlin-command "ocamlmerlin")`.

merlin 4.9
==========
Expand Down
49 changes: 20 additions & 29 deletions emacs/merlin.el
Original file line number Diff line number Diff line change
Expand Up @@ -612,41 +612,32 @@ argument (lookup appropriate binary, setup logging, pass global settings)"
(kill-local-variable 'merlin-erroneous-buffer)))))

(defcustom merlin-stop-server-on-opam-switch t
"If t, stop ocamlmerlin server before the opam switch changes.
If `(opam-switch-mode)' is loaded and the user changes the opam
switch using `opam-switch-set-switch' or an `\"OPSW\"' menu, this
option asks to stop the merlin server process, so that the next
merlin command starts a new server, typically with a different
merlin version from a different opam switch.
Based on the minor mode `opam-switch-mode', see:
https://github.com/ProofGeneral/opam-switch-mode
Note: `(opam-switch-mode)' expects `merlin-command' to be `\"ocamlmerlin\"'."
:group 'merlin :type 'boolean)

(defun merlin-stop-server-on-opam-switch ()
"Stop ocamlmerlin before the opam switch changes.
"If t, stop the Merlin server before the opam switch changes.
If the user changes the opam switch using `opam-switch-set-switch'
or an `\"OPSW\"' menu from `opam-switch-mode', this option asks to
stop the Merlin server process, so that the next Merlin command
starts a new server, typically with a different Merlin version
from a different opam switch.
See https://github.com/ProofGeneral/opam-switch-mode
Note: `opam-switch-mode' triggers automatic changes of `exec-path',
so to fully benefit from this feature, you should set `merlin-command'
to a basename, typically: `(setq merlin-command \"ocamlmerlin\")'."
:type 'boolean)

(defun merlin--stop-server-on-opam-switch ()
"Stop the Merlin server before the opam switch changes.
This function is for the `opam-switch-mode' hook
`opam-switch-before-change-opam-switch-hook', which runs just
before the user changes the opam switch through
`opam-switch-mode'.
If `merlin-stop-server-on-opam-switch' is t, then the merlin
server process is stopped, so that the next merlin command starts
a new server, typically with a different merlin version from a
different opam switch.
Based on the minor mode `opam-switch-mode', see:
https://github.com/ProofGeneral/opam-switch-mode
Note: `(opam-switch-mode)' expects `merlin-command' to be `\"ocamlmerlin\"'."
before the user changes the opam switch through `opam-switch-mode'."
(when (and merlin-mode merlin-stop-server-on-opam-switch)
(condition-case sig
(condition-case _sig
(merlin-stop-server)
(t (message "Info: (merlin-stop-server) failed in the previous opam switch")))))

(add-hook 'opam-switch-before-change-opam-switch-hook #'merlin-stop-server-on-opam-switch t)
(add-hook 'opam-switch-before-change-opam-switch-hook
#'merlin--stop-server-on-opam-switch t)

;;;;;;;;;;;;;;;;;;;;
;; FILE SWITCHING ;;
Expand Down

0 comments on commit 88533b8

Please sign in to comment.