forked from SystemCrafters/crafted-emacs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrafted-ide.el
57 lines (43 loc) · 1.73 KB
/
crafted-ide.el
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
;; crafted-ide.el -*- lexical-binding: t; -*-
;; Copyright (C) 2022
;; SPDX-License-Identifier: MIT
;; Author: System Crafters Community
;; Commentary
;; Eglot configuration.
;; Suggested additional keybindings
;; (with-eval-after-load "prog-mode"
;; (define-key prog-mode-map (kbd "C-c e n") #'flymake-goto-next-error)
;; (define-key prog-mode-map (kbd "C-c e p") #'flymake-goto-prev-error))
;;; Code:
;; Install dependencies
(crafted-package-install-package 'eglot)
;;; hooks
(defun crafted-ide--add-eglot-hooks (mode-list)
"Iterates over MODE-LIST recursively to add eglot-ensure to
existing mode hooks.
The mode must be loaded, ie. found with `fboundp'. A mode which
is not loaded will not have a hook added, in which case add it
manually with something like this:
`(add-hook 'some-mode-hook #'eglot-ensure)'
"
(dolist (mode-def mode-list)
(let ((mode (if (listp mode-def) (car mode-def) mode-def)))
(cond
((listp mode) (crafted-ide--add-eglot-hooks mode))
(t
(when (and (fboundp mode)
(not (eq 'clojure-mode mode)) ; prefer cider
(not (eq 'lisp-mode mode)) ; prefer sly/slime
(not (eq 'scheme-mode mode)) ; prefer geiser
)
(let ((hook-name (concat (symbol-name mode) "-hook")))
(message (concat "adding eglot to " hook-name))
(add-hook (intern hook-name) #'eglot-ensure))))))))
;; add eglot to existing programming modes when eglot is loaded.
(with-eval-after-load "eglot"
(crafted-ide--add-eglot-hooks eglot-server-programs))
;;; customization
;; Shutdown server when last managed buffer is killed
(customize-set-variable 'eglot-autoshutdown t)
(provide 'crafted-ide)
;;; crafted-ide.el ends here