2019-02-22 08:43:45 +01:00
|
|
|
;;; oni-java.el --- Java configuration -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
;; Copyright (C) 2019 Tom Willemse
|
|
|
|
|
|
|
|
;; Author: Tom Willemse <tom@ryuslash.org>
|
|
|
|
;; Keywords: local
|
2021-11-23 09:38:09 +01:00
|
|
|
;; Version: 2021.1123.003434
|
2021-06-23 07:19:53 +02:00
|
|
|
;; Package-Requires: (oni-data-dir oni-lsp oni-hydra lsp-java rainbow-delimiters)
|
2019-02-22 08:43:45 +01:00
|
|
|
|
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; Java configuration.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2019-07-24 07:53:51 +02:00
|
|
|
(require 'autoinsert)
|
2019-06-23 18:33:15 +02:00
|
|
|
(require 'hydra)
|
2019-05-28 16:57:27 +02:00
|
|
|
(require 'lsp-java)
|
|
|
|
(require 'oni-data-dir)
|
2019-10-21 09:41:19 +02:00
|
|
|
(require 'oni-lsp)
|
2019-04-22 10:00:53 +02:00
|
|
|
|
|
|
|
(defun oni-java-enable-buffer-formatting ()
|
|
|
|
"Format the buffer before save."
|
|
|
|
(add-hook 'before-save-hook 'lsp-format-buffer nil :local))
|
2019-02-22 08:43:45 +01:00
|
|
|
|
2019-06-11 17:12:01 +02:00
|
|
|
(defun oni-java-only-fill-comments ()
|
|
|
|
"Set `comment-auto-fill-only-comments' to true locally."
|
|
|
|
(setq-local comment-auto-fill-only-comments t))
|
|
|
|
|
2019-06-23 18:33:15 +02:00
|
|
|
(defhydra java-refactor-hydra (:color blue)
|
2019-07-10 16:58:22 +02:00
|
|
|
("r" lsp-rename "Rename object")
|
2019-10-01 07:17:23 +02:00
|
|
|
("m" lsp-java-extract-method "Extract method")
|
2019-10-17 08:27:07 +02:00
|
|
|
("M" lsp-java-organize-imports)
|
2019-10-01 07:17:23 +02:00
|
|
|
("i" lsp-java-add-import "Add import")
|
|
|
|
("t" lsp-java-add-throws "Add throws")
|
2019-10-17 08:27:07 +02:00
|
|
|
("u" lsp-java-add-unimplemented-methods "Add unimplemented methods")
|
|
|
|
("c" lsp-java-extract-to-constant "Extract to constant")
|
|
|
|
("p" lsp-java-create-parameter "Create parameter")
|
|
|
|
("l" lsp-java-create-local "Create local"))
|
2019-06-23 18:33:15 +02:00
|
|
|
|
2019-10-21 09:41:19 +02:00
|
|
|
(defhydra java-documentation-hydra (:color blue)
|
|
|
|
("d" oni-lsp-show-doc "Show documentation"))
|
|
|
|
|
2019-05-28 16:57:27 +02:00
|
|
|
(setq lsp-java-server-install-dir
|
|
|
|
(oni-data-dir-locate "lsp-java/server/"))
|
|
|
|
|
|
|
|
(setq lsp-java-workspace-dir
|
|
|
|
(oni-data-dir-locate "lsp-java/workspace/"))
|
|
|
|
|
|
|
|
(setq lsp-java-workspace-cache-dir
|
|
|
|
(oni-data-dir-locate "lsp-java/workspace/cache/"))
|
|
|
|
|
2019-10-17 08:26:11 +02:00
|
|
|
(setq lsp-java-references-code-lens-enabled t)
|
|
|
|
(setq lsp-java-implementations-code-lens-enabled t)
|
|
|
|
(setq lsp-java-save-actions-organize-imports t)
|
|
|
|
|
2019-06-11 17:12:01 +02:00
|
|
|
(add-hook 'java-mode-hook #'oni-java-enable-buffer-formatting)
|
|
|
|
(add-hook 'java-mode-hook #'oni-java-only-fill-comments)
|
2020-12-11 05:52:52 +01:00
|
|
|
(add-hook 'java-mode-hook 'abbrev-mode)
|
2019-06-11 17:12:01 +02:00
|
|
|
(add-hook 'java-mode-hook 'auto-fill-mode)
|
2021-06-23 07:19:53 +02:00
|
|
|
(add-hook 'java-mode-hook 'display-fill-column-indicator-mode)
|
2019-02-22 08:43:45 +01:00
|
|
|
(add-hook 'java-mode-hook 'electric-indent-local-mode)
|
2019-06-11 17:12:01 +02:00
|
|
|
(add-hook 'java-mode-hook 'electric-pair-local-mode)
|
2019-04-22 10:00:53 +02:00
|
|
|
(add-hook 'java-mode-hook 'lsp)
|
2021-04-26 02:36:32 +02:00
|
|
|
(add-hook 'java-mode-hook 'rainbow-delimiters-mode)
|
2019-02-22 08:43:45 +01:00
|
|
|
|
2019-06-23 18:33:15 +02:00
|
|
|
(define-key java-mode-map (kbd "C-c r") 'java-refactor-hydra/body)
|
2019-10-21 09:41:19 +02:00
|
|
|
(define-key java-mode-map (kbd "C-c d") 'java-documentation-hydra/body)
|
2019-06-23 18:33:15 +02:00
|
|
|
|
2020-12-13 07:10:43 +01:00
|
|
|
(define-abbrev java-mode-abbrev-table "and" "&&" nil :system t)
|
|
|
|
(define-abbrev java-mode-abbrev-table "or" "||" nil :system t)
|
2020-12-11 05:52:52 +01:00
|
|
|
|
2019-07-24 07:53:51 +02:00
|
|
|
(add-to-list 'auto-insert-alist
|
|
|
|
'("\\.java\\'"
|
|
|
|
() "public class "
|
|
|
|
(file-name-sans-extension
|
|
|
|
(file-name-nondirectory (buffer-file-name))) " {\n"
|
2019-10-21 09:41:19 +02:00
|
|
|
(indent-for-tab-command) _ "\n"
|
|
|
|
"}"))
|
2019-07-24 07:53:51 +02:00
|
|
|
|
2019-02-22 08:43:45 +01:00
|
|
|
(provide 'oni-java)
|
|
|
|
;;; oni-java.el ends here
|