2020-02-19 23:07:30 +00:00
|
|
|
|
;;; funcs.el --- Java functions File for Spacemacs
|
2015-07-04 04:29:25 +00:00
|
|
|
|
;;
|
2020-09-16 21:34:40 +00:00
|
|
|
|
;; Copyright (c) 2012-2020 Sylvain Benner & Contributors
|
2015-07-04 04:29:25 +00:00
|
|
|
|
;;
|
|
|
|
|
;; Author: Lukasz Klich <klich.lukasz@gmail.com>
|
2016-01-12 02:40:54 +00:00
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
2015-07-04 04:29:25 +00:00
|
|
|
|
;;
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
;;
|
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
|
2019-09-30 04:49:44 +00:00
|
|
|
|
(defun spacemacs//java-backend ()
|
|
|
|
|
"Returns selected backend."
|
|
|
|
|
(if java-backend
|
|
|
|
|
java-backend
|
|
|
|
|
(cond
|
|
|
|
|
((configuration-layer/layer-used-p 'lsp) 'lsp)
|
|
|
|
|
(t 'meghanada))))
|
|
|
|
|
|
2017-02-09 22:22:38 +00:00
|
|
|
|
(defun spacemacs//java-setup-backend ()
|
|
|
|
|
"Conditionally setup java backend."
|
2019-09-30 04:49:44 +00:00
|
|
|
|
(pcase (spacemacs//java-backend)
|
2017-03-19 17:15:33 +00:00
|
|
|
|
(`meghanada (spacemacs//java-setup-meghanada))
|
2018-08-21 18:47:48 +00:00
|
|
|
|
(`lsp (spacemacs//java-setup-lsp))))
|
2017-02-09 22:22:38 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs//java-setup-company ()
|
|
|
|
|
"Conditionally setup company based on backend."
|
2019-09-30 04:49:44 +00:00
|
|
|
|
(pcase (spacemacs//java-backend)
|
2020-04-02 16:41:28 +00:00
|
|
|
|
(`meghanada (spacemacs//java-setup-meghanada-company))))
|
2017-02-09 22:22:38 +00:00
|
|
|
|
|
2019-09-30 01:30:53 +00:00
|
|
|
|
(defun spacemacs//java-setup-dap ()
|
|
|
|
|
"Conditionally setup elixir DAP integration."
|
|
|
|
|
;; currently DAP is only available using LSP
|
2019-09-30 04:49:44 +00:00
|
|
|
|
(pcase (spacemacs//java-backend)
|
2019-09-30 01:30:53 +00:00
|
|
|
|
(`lsp (spacemacs//java-setup-lsp-dap))))
|
|
|
|
|
|
2017-02-09 22:22:38 +00:00
|
|
|
|
(defun spacemacs//java-setup-flycheck ()
|
|
|
|
|
"Conditionally setup flycheck based on backend."
|
2019-09-30 04:49:44 +00:00
|
|
|
|
(pcase (spacemacs//java-backend)
|
2017-03-19 17:15:33 +00:00
|
|
|
|
(`meghanada (spacemacs//java-setup-meghanada-flycheck))
|
2018-08-21 18:47:48 +00:00
|
|
|
|
(`lsp (spacemacs//java-setup-lsp-flycheck))))
|
2017-02-09 22:22:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; meghanada
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//java-setup-meghanada ()
|
|
|
|
|
"Setup Meghanada."
|
|
|
|
|
(require 'meghanada)
|
|
|
|
|
;; jump handler
|
|
|
|
|
(add-to-list 'spacemacs-jump-handlers
|
|
|
|
|
'(meghanada-jump-declaration
|
|
|
|
|
:async spacemacs//java-meghanada-server-livep))
|
|
|
|
|
;; auto-install meghanada server
|
|
|
|
|
(let ((dest-jar (meghanada--locate-server-jar)))
|
|
|
|
|
(unless dest-jar
|
|
|
|
|
(meghanada-install-server)))
|
|
|
|
|
;; enable meghanada
|
|
|
|
|
(meghanada-mode))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//java-setup-meghanada-company ()
|
|
|
|
|
"Setup Meghanada auto-completion."
|
|
|
|
|
(meghanada-company-enable))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//java-setup-meghanada-flycheck ()
|
|
|
|
|
"Setup Meghanada syntax checking."
|
2018-05-14 02:39:17 +00:00
|
|
|
|
(when (spacemacs/enable-flycheck 'java-mode)
|
|
|
|
|
(require 'flycheck-meghanada)
|
|
|
|
|
(add-to-list 'flycheck-checkers 'meghanada)
|
|
|
|
|
(flycheck-mode)))
|
2017-02-09 22:22:38 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs//java-meghanada-server-livep ()
|
|
|
|
|
"Return non-nil if the Meghanada server is up."
|
|
|
|
|
(and meghanada--client-process (process-live-p meghanada--client-process)))
|
|
|
|
|
|
2017-02-09 21:45:27 +00:00
|
|
|
|
|
|
|
|
|
;; Maven
|
2015-07-19 09:50:50 +00:00
|
|
|
|
|
2017-12-17 23:39:55 +00:00
|
|
|
|
(defun spacemacs/mvn-clean-compile ()
|
|
|
|
|
"Recompile using maven."
|
2015-05-20 21:06:46 +00:00
|
|
|
|
(interactive)
|
2017-12-17 23:39:55 +00:00
|
|
|
|
(mvn-clean)
|
|
|
|
|
(mvn-compile))
|
2015-05-20 21:06:46 +00:00
|
|
|
|
|
2017-02-09 21:45:27 +00:00
|
|
|
|
|
|
|
|
|
;; Misc
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//java-delete-horizontal-space ()
|
|
|
|
|
(when (s-matches? (rx (+ (not space)))
|
|
|
|
|
(buffer-substring (line-beginning-position) (point)))
|
|
|
|
|
(delete-horizontal-space t)))
|
2018-08-21 18:47:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; LSP Java
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//java-setup-lsp ()
|
|
|
|
|
"Setup LSP Java."
|
|
|
|
|
(if (configuration-layer/layer-used-p 'lsp)
|
|
|
|
|
(progn
|
|
|
|
|
(require 'lsp-java)
|
2018-12-09 08:00:14 +00:00
|
|
|
|
(lsp))
|
2019-09-30 01:30:53 +00:00
|
|
|
|
(message "`lsp' layer is not installed, please add `lsp' layer to your dotfile.")))
|
2018-08-21 18:47:48 +00:00
|
|
|
|
|
2019-09-30 01:30:53 +00:00
|
|
|
|
(defun spacemacs//java-setup-lsp-dap ()
|
|
|
|
|
"Setup DAP integration."
|
2019-12-29 09:42:00 +00:00
|
|
|
|
(require 'dap-java)
|
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'java-mode
|
|
|
|
|
;; debug
|
|
|
|
|
"ddj" 'dap-java-debug
|
|
|
|
|
"dtt" 'dap-java-debug-test-method
|
|
|
|
|
"dtc" 'dap-java-debug-test-class
|
|
|
|
|
;; run
|
|
|
|
|
"tt" 'dap-java-run-test-method
|
|
|
|
|
"tc" 'dap-java-run-test-class))
|
2019-09-30 01:30:53 +00:00
|
|
|
|
|
2018-08-21 18:47:48 +00:00
|
|
|
|
(defun spacemacs//java-setup-lsp-flycheck ()
|
|
|
|
|
"Setup LSP Java syntax checking."
|
2020-07-03 16:19:38 +00:00
|
|
|
|
(unless (configuration-layer/layer-used-p 'lsp)
|
2018-08-21 18:47:48 +00:00
|
|
|
|
(message "`lsp' layer is not installed, please add `lsp' layer to your dotfile.")))
|