spacemacs/layers/+lang/racket/packages.el
Eivind Fonn 928983da47 Refactor jump to definition
This commit defines:

- spacemacs-default-jump-handlers: a list of functions that can jump to
  definition in ALL modes.

- spacemacs-jump-handlers-MODE: a list of functions that can jump to
  definition in MODE.

- spacemacs-jump-handlers: a buffer-local list of functions that can
  jump to definition. This is made up of the values of the two previous
  variables whenever a given major mode is activated.

- spacemacs/jump-to-definition: a function that tries each function in
  spacemacs-jump-handlers in order, and stops when one of them takes us
  somewhere new.

- spacemacs|define-jump-handlers: a macro that
  * defines spacemacs-jump-handlers-MODE, possibly filled with initial
    functions
  * defines a function that is added to the hook of the given MODE
  * binds “SPC m g g” of that MODE to spacemacs/jump-to-definition

This is an attempt to harmonize all the different approaches to jumping.
Specifically,

- Existing intelligent jump packages that work for only a single mode
  should go to the beginning of spacemacs-jump-handlers-MODE. E.g.
  anaconda for python, ensime for scala, etc.

- Packages like gtags that work for several modes (but potentially not
  all) and which is dumber than the intelligent jumpers should go the
  the END of spacemacs-jump-handlers-MODE.

- Packages like dumb-jump that work for all modes should go to
  spacemacs-default-jump-handlers.

In all cases the order of the jump handlers in each list should be from
most to least intelligent.

Fixes #6619
2016-08-22 15:08:25 +02:00

121 lines
4 KiB
EmacsLisp

(setq racket-packages
'(
company
company-quickhelp
ggtags
helm-gtags
racket-mode
))
(defun racket/post-init-company ()
;; this is the only thing to do to enable company in racket-mode
;; because racket-mode handle everything for us when company
;; is loaded.
(add-hook 'racket-mode-hook 'company-mode))
(defun racket/post-init-company-quickhelp ()
;; Bug exists in Racket company backend that opens docs in new window when
;; company-quickhelp calls it. Note hook is appendended for proper ordering.
(add-hook 'company-mode-hook
'(lambda ()
(when (and (equal major-mode 'racket-mode)
(bound-and-true-p company-quickhelp-mode))
(company-quickhelp-mode -1))) t))
(defun racket/post-init-ggtags ()
(add-hook 'racket-mode-hook #'spacemacs/ggtags-mode-enable))
(defun racket/post-init-helm-gtags ()
(spacemacs/helm-gtags-define-keys-for-mode 'racket-mode))
(defun racket/init-racket-mode ()
(use-package racket-mode
:defer t
:init
(progn
(spacemacs/register-repl 'racket-mode 'racket-repl "racket")
(spacemacs|define-jump-handlers racket-mode racket-visit-definition))
:config
(progn
;; smartparens configuration
(with-eval-after-load 'smartparens
(add-to-list 'sp--lisp-modes 'racket-mode)
(when (fboundp 'sp-local-pair)
(sp-local-pair 'racket-mode "'" nil :actions nil)
(sp-local-pair 'racket-mode "`" nil :actions nil)))
(defun spacemacs/racket-test-with-coverage ()
"Call `racket-test' with universal argument."
(interactive)
(racket-test t))
(defun spacemacs/racket-run-and-switch-to-repl ()
"Call `racket-run-and-switch-to-repl' and enable
`insert state'."
(interactive)
(racket-run-and-switch-to-repl)
(evil-insert-state))
(defun spacemacs/racket-send-last-sexp-focus ()
"Call `racket-send-last-sexp' and switch to REPL buffer in
`insert state'."
(interactive)
(racket-send-last-sexp)
(racket-repl)
(evil-insert-state))
(defun spacemacs/racket-send-definition-focus ()
"Call `racket-send-definition' and switch to REPL buffer in
`insert state'."
(interactive)
(racket-send-definition)
(racket-repl)
(evil-insert-state))
(defun spacemacs/racket-send-region-focus (start end)
"Call `racket-send-region' and switch to REPL buffer in
`insert state'."
(interactive "r")
(racket-send-region start end)
(racket-repl)
(evil-insert-state))
(dolist (prefix '(("mg" . "navigation")
("mh" . "doc")
("mi" . "insert")
("ms" . "repl")
("mt" . "tests")))
(spacemacs/declare-prefix-for-mode 'racket-mode (car prefix) (cdr prefix)))
(spacemacs/set-leader-keys-for-major-mode 'racket-mode
;; navigation
"g`" 'racket-unvisit
"gm" 'racket-visit-module
"gr" 'racket-open-require-path
;; doc
"hd" 'racket-describe
"hh" 'racket-doc
;; insert
"il" 'racket-insert-lambda
;; REPL
"'" 'racket-repl
"sb" 'racket-run
"sB" 'spacemacs/racket-run-and-switch-to-repl
"se" 'racket-send-last-sexp
"sE" 'spacemacs/racket-send-last-sexp-focus
"sf" 'racket-send-definition
"sF" 'spacemacs/racket-send-definition-focus
"si" 'racket-repl
"sr" 'racket-send-region
"sR" 'spacemacs/racket-send-region-focus
"ss" 'racket-repl
;; Tests
"tb" 'racket-test
"tB" 'spacemacs/racket-test-with-coverage)
(define-key racket-mode-map (kbd "H-r") 'racket-run)
;; remove racket auto-insert of closing delimiter
;; see https://github.com/greghendershott/racket-mode/issues/140
(define-key racket-mode-map ")" 'self-insert-command)
(define-key racket-mode-map "]" 'self-insert-command)
(define-key racket-mode-map "}" 'self-insert-command))))