Skip to content

Commit

Permalink
fix(merlin.el): Fix and improve emacs bindings
Browse files Browse the repository at this point in the history
(following the discussion in ocaml#1386)
  • Loading branch information
erikmd committed Sep 19, 2023
1 parent 753fcfb commit 5abcfbb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
10 changes: 8 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ unreleased
+ merlin binary
- Improve error messages for missing configuration reader (#1669)
- Fix regression causing crash when using ppxes under Windows (#1673)


+ editor modes
- emacs: fix/improve keybindings (#1668, fixes #1386):
Unbind <kbd>C-c C-r</kbd> (to avoid shadowing `tuareg-eval-region`)
and bind <kbd>C-c C-v</kbd> instead to `merlin-error-check`;
rebind <kbd>C-c C-d</kbd> to `merlin-document`
and bind <kbd>C-c M-d</kbd> and <kbd>C-c |</kbd> instead to `merlin-destruct`;
bind <kbd>C-u C-c C-t</kbd> to `merlin-type-expr`.
See also <https://github.com/ocaml/merlin/issues/1386#issuecomment-1701567716>

merlin 4.10
==========
Expand Down
25 changes: 15 additions & 10 deletions emacs/merlin.el
Original file line number Diff line number Diff line change
Expand Up @@ -1316,15 +1316,18 @@ If QUIET is non nil, then an overlay and the merlin types can be used."
(set-temporary-overlay-map merlin-type-enclosing-map t
'merlin--type-enclosing-reset))))

(defun merlin-type-enclosing ()
(defun merlin-type-enclosing (&optional manual)
"Print the type of the expression under point (or of the region, if it exists).
If called repeatedly, increase the verbosity of the type shown."
(interactive)
(if (region-active-p)
(merlin--type-region)
(when (merlin--type-enclosing-query)
(merlin-type-enclosing-go-up)
(merlin--type-enclosing-after))))
If called repeatedly, increase the verbosity of the type shown.
With prefix argument MANUAL, call `merlin-type-expr' interactively."
(interactive "P")
(if manual
(call-interactively #'merlin-type-expr)
(if (region-active-p)
(merlin--type-region)
(when (merlin--type-enclosing-query)
(merlin-type-enclosing-go-up)
(merlin--type-enclosing-after)))))

(defun merlin--find-extents (list low high)
"Return the smallest extent in LIST that LOW and HIGH fit
Expand Down Expand Up @@ -1979,9 +1982,11 @@ Empty string defaults to jumping to all these."
(define-key merlin-map (kbd "C-c C-x") #'merlin-error-next)
(define-key merlin-map (kbd "C-c C-l") #'merlin-locate)
(define-key merlin-map (kbd "C-c &" ) #'merlin-pop-stack)
(define-key merlin-map (kbd "C-c C-r") #'merlin-error-check)
(define-key merlin-map (kbd "C-c C-v") #'merlin-error-check)
(define-key merlin-map (kbd "C-c C-t") #'merlin-type-enclosing)
(define-key merlin-map (kbd "C-c C-d") #'merlin-destruct)
(define-key merlin-map (kbd "C-c C-d") #'merlin-document)
(define-key merlin-map (kbd "C-c M-d") #'merlin-destruct)
(define-key merlin-map (kbd "C-c |") #'merlin-destruct)
(define-key merlin-map (kbd "C-c C-n") #'merlin-phrase-next)
(define-key merlin-map (kbd "C-c C-p") #'merlin-phrase-prev)
(define-key merlin-menu-map [customize]
Expand Down

0 comments on commit 5abcfbb

Please sign in to comment.