1
0
Fork 0
emacs-config/oni-java.el
Tom Willemse cfa0179053 Remove all self-loading autoload cookies
The big downside of usuing these cookies to inject my configuration into the
loading of a package is that it means that I can't load that package without my
configuration anymore. This means that when I start ‘emacs -Q’ and then call
‘package-initialize’ it'll load my configuration as well. This makes debugging
things very difficult.
2021-11-23 00:38:09 -08:00

95 lines
3.3 KiB
EmacsLisp

;;; oni-java.el --- Java configuration -*- lexical-binding: t; -*-
;; Copyright (C) 2019 Tom Willemse
;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: local
;; Version: 2021.1123.003434
;; 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 <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 '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"
"}"))
(provide 'oni-java)
;;; oni-java.el ends here