blob: ec622056a44f0a2a6b4d6b800e55df3af34018e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
;;; oni-java.el --- Java configuration -*- lexical-binding: t; -*-
;; Copyright (C) 2019 Tom Willemse
;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: local
;; Version: 2020.1030.182339
;; Package-Requires: (oni-fci oni-data-dir oni-lsp oni-hydra lsp-java)
;; 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:
(require 'autoinsert)
(require 'hydra)
(require 'lsp-java)
(require 'oni-data-dir)
(require 'oni-lsp)
(defun oni-java-enable-buffer-formatting ()
"Format the buffer before save."
(add-hook 'before-save-hook 'lsp-format-buffer nil :local))
(defun oni-java-only-fill-comments ()
"Set `comment-auto-fill-only-comments' to true locally."
(setq-local comment-auto-fill-only-comments t))
(defhydra java-refactor-hydra (:color blue)
("r" lsp-rename "Rename object")
("m" lsp-java-extract-method "Extract method")
("M" lsp-java-organize-imports)
("i" lsp-java-add-import "Add import")
("t" lsp-java-add-throws "Add throws")
("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"))
(defhydra java-documentation-hydra (:color blue)
("d" oni-lsp-show-doc "Show documentation"))
(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/"))
(setq lsp-java-references-code-lens-enabled t)
(setq lsp-java-implementations-code-lens-enabled t)
(setq lsp-java-save-actions-organize-imports t)
(add-hook 'java-mode-hook #'oni-java-enable-buffer-formatting)
(add-hook 'java-mode-hook #'oni-java-only-fill-comments)
(add-hook 'java-mode-hook 'auto-fill-mode)
(add-hook 'java-mode-hook 'electric-indent-local-mode)
(add-hook 'java-mode-hook 'electric-pair-local-mode)
(add-hook 'java-mode-hook 'lsp)
(add-hook 'java-mode-hook
(if (fboundp 'display-fill-column-indicator-mode)
'display-fill-column-indicator-mode
'fci-mode))
(define-key java-mode-map (kbd "C-c r") 'java-refactor-hydra/body)
(define-key java-mode-map (kbd "C-c d") 'java-documentation-hydra/body)
(add-to-list 'auto-insert-alist
'("\\.java\\'"
() "public class "
(file-name-sans-extension
(file-name-nondirectory (buffer-file-name))) " {\n"
(indent-for-tab-command) _ "\n"
"}"))
;;;###autoload(with-eval-after-load 'cc-mode (require 'oni-java))
(provide 'oni-java)
;;; oni-java.el ends here
|