1
0
Fork 0
emacs-config/oni-java.el

86 lines
2.8 KiB
EmacsLisp
Raw Normal View History

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
;; Version: 2019.1016.231834
2019-06-23 18:33:15 +02:00
;; Package-Requires: (oni-fci oni-data-dir lsp-java company-lsp lsp-ui hydra)
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)
(require 'lsp-java)
(require 'oni-data-dir)
(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)
("r" lsp-rename "Rename object")
("m" lsp-java-extract-method "Extract method")
("i" lsp-java-add-import "Add import")
("t" lsp-java-add-throws "Add throws")
("m" lsp-java-add-unimplemented-methods "Add unimplemented methods"))
2019-06-23 18:33:15 +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/"))
(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)
(add-hook 'java-mode-hook 'auto-fill-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-02-22 08:43:45 +01:00
(add-hook 'java-mode-hook 'fci-mode)
(add-hook 'java-mode-hook 'lsp)
2019-02-22 08:43:45 +01:00
(add-to-list 'company-backends 'company-lsp)
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-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"
(indent-for-tab-command) _ "\n"
"}"))
2019-02-22 08:43:45 +01:00
;;;###autoload(with-eval-after-load 'cc-mode (require 'oni-java))
(provide 'oni-java)
;;; oni-java.el ends here