;;; oni-java.el --- Java configuration -*- lexical-binding: t; -*- ;; Copyright (C) 2019 Tom Willemse ;; Author: Tom Willemse ;; Keywords: local ;; Version: 2021.0622.221131 ;; Package-Requires: (oni-data-dir oni-lsp oni-hydra lsp-java rainbow-delimiters) ;; 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 . ;;; 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 'abbrev-mode) (add-hook 'java-mode-hook 'auto-fill-mode) (add-hook 'java-mode-hook 'display-fill-column-indicator-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 'rainbow-delimiters-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) (define-abbrev java-mode-abbrev-table "and" "&&" nil :system t) (define-abbrev java-mode-abbrev-table "or" "||" nil :system t) (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