-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
178 lines (159 loc) · 5.56 KB
/
init.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
;; __ __ __ __
;; | \/ | ___| \/ | __ _ ___ ___
;; | |\/| |/ _ \ |\/| |/ _` |/ __/ __|
;; | | | | __/ | | | (_| | (__\__ \
;; |_| |_|\___|_| |_|\__,_|\___|___/
;;
;; Light Emacs Distribution
(defun ensure-package-is-installed (package)
"Installs the specified package if it is not installed"
(unless (package-installed-p package)
(package-refresh-contents)
(package-install package)))
(defun autocompile-init-file nil
"Check if buffer is the init file and compile it"
(interactive)
(require 'bytecomp)
(let ((dotemacs (file-truename user-init-file)))
(if (string= (buffer-file-name) (file-chase-links dotemacs))
(byte-compile-file dotemacs))))
(defun install-language-server-hooks ()
"Automatically start lsp for certain programming languages"
(use-package lsp-mode
:ensure t
:config
(add-hook 'php-mode-hook #'lsp)
(add-hook 'c-mode-hook #'lsp)
(add-hook 'c++-mode-hook #'lsp)
(add-hook 'js-mode-hook #'lsp)
)
)
(defun setup-editor-for-programming ()
"Prepare editor for programming"
(global-linum-mode 1)
(ido-mode 1)
(set-face-attribute 'default nil :height 150)
;; indentation
(setq-default indent-tabs-mode nil)
(setq-default tab-width 2)
(setq indent-line-function 'insert-tab)
)
(defun start-garbage-collector()
;; don't show gcmh as minor mode
(eval-after-load 'gcmh
'(setq minor-mode-alist (assq-delete-all 'gcmh-mode minor-mode-alist)))
;; enable garbage collection freeing unused memory
(ensure-package-is-installed 'gcmh)
(use-package gcmh
:ensure t
:config
(gcmh-mode 1)
)
)
(defun start-emacs-server ()
"start emacs server"
(ensure-package-is-installed 'server)
(use-package server
:config
(unless (server-running-p) ;; only start the server if it isn't already running
(server-start)))
)
(defun async-startup ()
"Run in the background asynchronously"
(start-garbage-collector)
(start-emacs-server)
)
(require 'package) ; load package managment
;; add sources to load our packages from
(add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/"))
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize) ; load and activate the installed packages
(ensure-package-is-installed 'use-package)
;; remove toolbar and menu bar
(tool-bar-mode -1)
(menu-bar-mode -1)
(setup-editor-for-programming)
;; move save files to a central space
;; avoiding cluttering project directories
(setq backup-directory-alist
`((".*" . "~/.saves")))
(setq auto-save-file-name-transforms
`((".*" "~/.saves" t)))
;; Dashboard Configuration
(ensure-package-is-installed 'dashboard)
(use-package dashboard
:ensure t
:config
(dashboard-setup-startup-hook)
(setq dashboard-set-footer nil)
(setq dashboard-startup-banner "~/.emacs.d/logo.svg")
(setq dashboard-banner-logo-title "MeMacs")
(setq dashboard-init-info "Keep things light"))
(install-language-server-hooks)
;; Go Support
(ensure-package-is-installed 'go-mode)
(use-package go-mode
:ensure t
:config
(add-hook 'go-mode-hook #'lsp-deferred)
(add-hook 'before-save-hook #'lsp-format-buffer))
;; Terraform OpenTofu Support
(ensure-package-is-installed 'terraform-mode)
(use-package terraform-mode
:ensure t
:config
(add-hook 'terraform-mode-hook #'terraform-format-on-save-mode)
(add-to-list 'auto-mode-alist '("\\.tf\\'" . terraform-mode)))
;; Builder Mode
(defun no-electric-indent ()
(setq-local electric-indent-functions '(lambda (char) 'no-indent)))
(define-derived-mode builder-mode fundamental-mode "Builder Mode"
"Major mode for Builder scripts."
(setq font-lock-defaults '((builder-font-lock-keywords))))
(defvar builder-font-lock-keywords
'(("^\\(builder-mode\\|step\\|setUser\\|setupHost\\|setHost\\|setTargetUser\\|pushFile\\|executable\\|ensureExecutable\\|ensureService\\|listPackages\\|dumpPackages\\|ensurePackage\\|executeAndPrint\\)\\s-+\\(.*\\)$"
(1 font-lock-keyword-face)
(2 font-lock-string-face))
("//.*$"
(0 font-lock-comment-face)
)))
(add-hook 'builder-mode-hook 'turn-on-font-lock)
(add-hook 'builder-mode-hook 'no-electric-indent)
(add-to-list 'auto-mode-alist '("\\.bld\\'" . builder-mode))
;; Setup Theme
(ensure-package-is-installed 'doom-themes)
(use-package doom-themes
:ensure t
:config
(setq doom-themes-enable-bold t
doom-themes-enable-italic t)
(load-theme 'doom-one t)
(doom-themes-visual-bell-config)
(doom-themes-neotree-config)
(setq doom-themes-treemacs-theme "doom-atom")
(doom-themes-treemacs-config)
(doom-themes-org-config))
;; don't show undo-tree as minor mode
(eval-after-load 'undo-tree
'(setq minor-mode-alist (assq-delete-all 'undo-tree-mode minor-mode-alist)))
;; globaly enable undo tree
(ensure-package-is-installed 'undo-tree)
(use-package undo-tree
:config
(global-undo-tree-mode)
)
(add-hook 'after-save-hook 'autocompile-init-file)
(run-with-idle-timer 0 nil #'async-startup)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(package-selected-packages
'(terraform-mode go-mode cmake-mode use-package-el-get undo-tree php-mode nerd-icons gcmh doom-themes dashboard dap-mode company all-the-icons)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)