This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
333 lines (279 loc) · 9.42 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
;; Switch caps-lock and right ctrl
(global-set-key "\C-x\C-m" 'execute-extended-command)
(global-set-key "\C-c\C-m" 'execute-extended-command)
(global-set-key (kbd "C-c TAB") 'indent-buffer-fn)
;; Some quit shortcut keys
(global-set-key (kbd "C-M-g") 'keyboard-quit)
(global-set-key (kbd "C-x C-g") 'keyboard-quit)
;; Indent the buffer
;; http://stackoverflow.com/questions/4090793/emacs-reindenting-entire-c-buffer
(defun indent-buffer-fn ()
"Indent an entire buffer using the default intenting scheme."
(interactive)
(save-excursion
(delete-trailing-whitespace)
(indent-region (point-min) (point-max) nil)
(untabify (point-min) (point-max))))
;; [HACK]
;; Open init file for re-eval indent function.
;; Call at the end of init
(defun fix-indent-eval ()
(find-file "~/.emacs.d/init.el")
(goto-char 194)
(end-of-line))
;; Set the default directory to work with
(setq default-directory "~/Projects") ;; Linux
;; Recentf
;; https://www.emacswiki.org/emacs/RecentFiles
;; I want to keep only latest only 50 items
(recentf-mode t)
(setq recentf-max-menu-items 50)
(setq recentf-max-saved-items 50)
;; Transient Mark Mode
;; https://www.emacswiki.org/emacs/TransientMarkMode
(transient-mark-mode t)
;; Line Numbers and Indentations
;; Turn line numbers on
(global-display-line-numbers-mode t)
;; 4 character and a space for line numbers
(setq linum-format "%4d ")
;; Always use 4 spaces to indentation
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
;; Life is boring with backup files
(setq make-backup-files nil)
;; Search for strings
(setq search-highlight t)
(setq query-replace-highlight t)
;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Font-Lock.html
(setq font-lock-maximum-decoration t)
;;https://www.gnu.org/software/emacs/manual/html_node/emacs/Customize-Save.html
(setq require-final-newline t)
;; I want to have text-mode as default
;; https://www.gnu.org/software/emacs/manual/html_node/eintr/Text-and-Auto_002dfill.html
(setq major-mode 'text-mode)
(add-hook 'text-mode-hook 'turn-on-auto-fill)
;; Turn on paren matching
;; https://www.emacswiki.org/emacs/ShowParenMode
;; https://emacs-fu.blogspot.com/2009/01/balancing-your-parentheses.html
(show-paren-mode t)
(setq show-paren-style 'expression)
;; Prompts and startups
;; https://www.masteringemacs.org/article/disabling-prompts-emacs
;; Get rid of the startup screen
(setq inhibit-startup-screen t)
(setq inhibit-startup-message t
inhibit-startup-echo-area-message t)
(setq initial-scratch-message nil)
;; https://www.emacswiki.org/emacs/YesOrNoP
(fset 'yes-or-no-p 'y-or-n-p)
;; Get back font antialiasing
(setq font-lock-maximum-decoration t)
;; Sets a 80 character line width
;; http://mixandgo.com/blog/how-i-ve-convinced-emacs-to-dance-with-ruby
(setq-default fill-column 80)
;; Enable copy/past-ing from clipboard
(setq x-select-enable-clipboard t)
;; Always reload the file if it changed on disk
(global-auto-revert-mode 1)
;; A nice line height
(setq-default line-spacing 1)
;; Treat the CMD key like meta on OSX
(setq mac-command-modifier 'meta)
;; Turn off tool-bar and menu-bar
(tool-bar-mode 0)
(menu-bar-mode 1)
;; Set some defaults
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/") t)
(package-initialize)
;; Projectile
;; https://projectile.mx
(projectile-mode 1)
(global-set-key (kbd "C-c a") 'projectile-command-map)
(global-set-key (kbd "C-c f") 'projectile-find-file)
(global-set-key (kbd "C-c g") 'projectile-grep)
;; Ido Mode
;; https://www.masteringemacs.org/article/introduction-to-ido-mode
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(ido-mode 1)
;; Company Mode
;; https://company-mode.github.io/
(add-hook 'after-init-hook 'global-company-mode)
;; Make company-mode fast to react
(setq company-minimum-prefix-length 2)
(setq company-show-numbers t)
(setq company-idle-delay
(lambda () (if (company-in-string-or-comment) nil 0.3)))
;; Whitespace
;; limit line length
(setq whitespace-line-column 80)
(setq whitespace-style '(spaces tabs newline space-mark tab-mark newline-mark face lines-tail))
(setq whitespace-display-mappings
;; all numbers are Unicode codepoint in decimal. e.g. (insert-char 182 1)
'(
;;(space-mark nil) ; 32 SPACE, 183 MIDDLE DOT
;;(newline-mark 10 [172 10]) ; 10 LINE FEED
(tab-mark 9 [183 9] [92 9]) ; 9 TAB, MIDDLE DOT
))
(setq whitespace-global-modes '(not org-mode web-mode "Web" emacs-lisp-mode))
(global-whitespace-mode)
;; remove trailing whitespaces
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; Narrow To Region Mode
(put 'narrow-to-region 'disabled nil)
;; Anzu
;; https://github.com/emacsorphanage/anzu
(use-package anzu
:config
(global-anzu-mode t)
(global-set-key [remap query-replace] 'anzu-query-replace)
(global-set-key [remap query-replace-regexp] 'anzu-query-replace-regexp))
;; Dashboard
;; https://github.com/emacs-dashboard/emacs-dashboard
(use-package dashboard
:ensure t
:config
(dashboard-setup-startup-hook)
(setq dashboard-banner-logo-title "It's coding time")
(setq dashboard-startup-banner 'logo)
(setq dashboard-center-content t)
)
;; Start emacs and go to init tab function above
(fix-indent-eval)
;; Load Material theme
(load-theme 'material t)
;; Enable upcase and downcase
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
;; Direx
;; https://github.com/emacsorphanage/direx
(use-package direx
:bind (("C-x C-j" . direx:jump-to-directory)))
;; Enable highlight changes
;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Highlight-Interactively.html
(global-hi-lock-mode)
;; exec-path-from-shell
;; For merging emacs and user's $PATH
;; Note : Use ~/.bash_profile instead of ~/.bashrc
(use-package exec-path-from-shell
:config (exec-path-from-shell-initialize))
;; beacon
;; https://github.com/Malabarba/beacon
(use-package beacon
:config (beacon-mode 1))
;; yasnippet
;; https://github.com/joaotavora/yasnippet
;; Turn this per buffer basis
(use-package yasnippet
:init
(add-hook 'python-mode-hook 'yas-minor-mode)
(add-hook 'web-mode-hook 'yas-minor-mode)
(add-hook 'json-mode-hook 'yas-minor-mode)
(add-hook 'js-mode-hook 'yas-minor-mode)
(add-hook 'js2-mode-hook 'yas-minor-mode)
(add-hook 'typescript-mode-hook 'yas-minor-mode))
;; Flymake
(add-hook 'python-mode-hook 'flymake-mode)
(add-hook 'web-mode-hook 'flymake-mode)
(add-hook 'json-mode-hook 'flymake-mode)
(add-hook 'js-mode-hook 'flymake-mode)
(add-hook 'js2-mode-hook 'flymake-mode)
(add-hook 'typescript-mode-hook 'flymake-mode)
;; paredit
(add-hook 'emacs-lisp-mode-hook 'enable-paredit-mode)
;; jinx
;; https://github.com/minad/jinx
(use-package jinx
:hook (emacs-startup . global-jinx-mode)
:bind (("M-$" . jinx-correct)
("C-M-$" . jinx-languages)))
;; [PYTHON]
;; virtualenvwrapper
;; https://github.com/porterjamesj/virtualenvwrapper.el
(use-package virtualenvwrapper
:init
(setq venv-location "~/.pyenv/versions")
:config
(venv-initialize-interactive-shells)
(venv-initialize-eshell))
;; blacken
;; https://github.com/pythonic-emacs/blacken
(use-package blacken
:init
(add-hook 'python-mode-hook 'blacken-mode))
;; [WEB]
;; web-mode
;; https://web-mode.org/
(use-package web-mode
:init
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.svelte?\\'" . web-mode))
(setq web-mode-markup-indent-offset 4)
(setq web-mode-css-indent-offset 4)
(setq web-mode-code-indent-offset 4))
;; [JAVASCRIPT]
;; js2-mode
;; https://github.com/mooz/js2-mode
(use-package js2-mode
:init
(add-hook 'js-mode-hook 'js2-minor-mode)
(setq-default js4-basic-offset 4)
(setq-default js-indent-level 4))
;; [JSON]
;; json-reformat
;; https://github.com/gongo/json-reformat
(use-package json-reformat
:init
(setq-default json-reformat:indent-width 4))
;; [TYPESCRIPT]
;; tide
;; https://github.com/ananthakumaran/tide
(defun setup-tide-mode ()
(interactive)
(tide-setup)
(flycheck-mode +1)
(setq flycheck-check-syntax-automatically '(save mode-enabled))
(eldoc-mode +1)
(tide-hl-identifier-mode +1)
;; company is an optional dependency. You have to
;; install it separately via package-install
;; `M-x package-install [ret] company`
(company-mode +1))
;; aligns annotation to the right hand side
(setq company-tooltip-align-annotations t)
;; formats the buffer before saving
(add-hook 'before-save-hook 'tide-format-before-save)
;; if you use typescript-mode
(add-hook 'typescript-mode-hook #'setup-tide-mode)
(setq tide-format-options '(:insertSpaceAfterFunctionKeywordForAnonymousFunctions t :placeOpenBraceOnNewLineForFunctions nil))
(add-to-list 'auto-mode-alist '("\\.ts?\\'" . tide-mode))
;; [TYPESCRIPT]
;; typescript-mode. NOTE - stopped development
;; https://github.com/emacs-typescript/
(use-package typescript-mode
:init
(add-to-list 'auto-mode-alist '("\\.ts?\\'" . typescript-mode)))
;; [AI]
;; Tabnine
;; https://github.com/TommyX12/company-tabnine
;; (require 'company-tabnine)
(use-package company-tabnine :ensure t)
(add-to-list 'company-backends #'company-tabnine)
;; chatgpt-shell
(use-package chatgpt-shell
:ensure t)
(require 'subr-x)
(with-temp-buffer
(insert-file-contents "./openai-key.txt")
(setq chatgpt-shell-openai-key (string-trim (buffer-string)))
(setq dall-e-shell-openai-key (string-trim (buffer-string))))
(print "OpenAi key successfully loaded")
;; [TERRAFORM]
(use-package terraform-mode
:custom (terraform-indent-level 4)
)
;; [CLOJURE]
(print "Emacs initialized!!")