blob: 51ff942997b1c4f341443abd7b9865d2db2a5166 (
plain)
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
;;; Code:
;; Backup files
(setq backup-directory-alist
`((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
`((".*" ,temporary-file-directory t)))
(setq backup-by-copying t)
(setq delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t)
;; Initial major mode
(setq initial-major-mode 'text-mode)
;; Auto revert mode to reload disk
(global-auto-revert-mode 1)
;; menu bars
(menu-bar-mode -1)
(toggle-scroll-bar -1)
(tool-bar-mode -1)
(setq mac-shift-modifier 'meta)
;; Reload user init file
(defun reload-init-file ()
(interactive)
(load-file user-init-file))
(global-set-key (kbd "C-c C-l") 'reload-init-file)
;; Tab mode
(global-tab-line-mode t)
;; Ability to fold regions
(add-hook 'javascript-mode-hook (lambda () (hs-minor-mode 1)))
(add-hook 'typescript-mode-hook (lambda () (hs-minor-mode 1)))
(add-hook 'c-mode-hook (lambda () (hs-minor-mode 1)))
(add-hook 'python-mode-hook (lambda () (hs-minor-mode 1)))
(add-hook 'emacs-lisp-mode-hook (lambda () (hs-minor-mode 1)))
;; Default Values
(setq-default indent-tabs-mode nil) ; use spaces only if nil
(setq-default tab-width 2) ; Assuming you want your tabs to be four spaces wide
(set-face-attribute 'default nil :font "Source Code Pro-10")
(set-fontset-font t '(?😊 . ?😎) "Segoe UI Emoji")
;;(set-face-attribute 'default nil :height 110 :family "Consolas")
(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8)
;; Cursor
(setq-default cursor-type 'bar)
(blink-cursor-mode 1)
;; Line numbers
(global-display-line-numbers-mode 1)
;; Show number of matches
(setq isearch-lazy-highlight t)
(setq isearch-lazy-count t)
;; Fringe
(setq-default left-fringe-width 20)
(setq-default right-fringe-width 20)
;; Initialization screen
(setq inhibit-splash-screen t)
(setq initial-scratch-message "* Scratch")
(setq initial-major-mode 'org-mode)
;; Highlight todos
(use-package hl-todo
:config
(global-hl-todo-mode 1)
)
;; Delete highlighted selection
(delete-selection-mode 1)
;; I am using the helm package, of course
(use-package helm)
;; Projectile for project navigation
(use-package projectile)
(require 'projectile)
(projectile-mode +1)
(use-package helm-projectile
:config
(helm-projectile-on)
)
(define-key projectile-mode-map (kbd "s-F") 'helm-projectile-grep)
(define-key projectile-mode-map [?\s-o] 'helm-projectile-switch-project)
(define-key projectile-mode-map [?\s-p] 'helm-projectile-find-file)
;(setq projectile-indexing-method 'alien)
(setq projectile-indexing-method 'native)
(setq projectile-enable-caching t)
(add-to-list 'projectile-globally-ignored-directories "node_modules")
;; Don't ask to kill when we have an open line number
(setq-default confirm-kill-processes nil)
;; Highlight indentation lines
(use-package highlight-indent-guides
:config
(add-hook 'prog-mode-hook 'highlight-indent-guides-mode)
(setq highlight-indent-guides-method 'character)
)
;; Tree
(require 'neotree)
(setq neo-smart-open t)
(setq projectile-switch-project-action 'neotree-projectile-action)
(setq neo-theme (if (display-graphic-p) 'icons 'arrow))
;; (evil-define-key 'normal neotree-mode-map (kbd "TAB") 'neotree-enter)
;; (evil-define-key 'normal neotree-mode-map (kbd "SPC") 'neotree-quick-look)
;; (evil-define-key 'normal neotree-mode-map (kbd "q") 'neotree-hide)
;; (evil-define-key 'normal neotree-mode-map (kbd "RET") 'neotree-enter)
;; (evil-define-key 'normal neotree-mode-map (kbd "g") 'neotree-refresh)
;; (evil-define-key 'normal neotree-mode-map (kbd "n") 'neotree-next-line)
;; (evil-define-key 'normal neotree-mode-map (kbd "p") 'neotree-previous-line)
;; (evil-define-key 'normal neotree-mode-map (kbd "A") 'neotree-stretch-toggle)
;; (evil-define-key 'normal neotree-mode-map (kbd "H") 'neotree-hidden-file-toggle)
(defun my-neotree-mode-hook()
"Set the colors of neotree to match my personal taste."
(setq left-fringe-width 0)
(setq right-fringe-width 0)
)
(add-hook 'neotree-mode-hook 'my-neotree-mode-hook)
(setq neo-window-width 36)
;; Line highlighting
(global-hl-line-mode 1)
(set-face-background 'hl-line "unspecified")
(set-face-attribute 'hl-line nil
:box '(:line-width -1
:color "gray35"
:style nil))
;; Git
(use-package git-gutter
:ensure t
:hook (prog-mode . git-gutter-mode)
:config
(setq git-gutter:update-interval 0.02)
(setq git-gutter:window-width 1)
(set-face-background 'git-gutter:modified "dark magenta")
(set-face-background 'git-gutter:deleted "tomato")
(set-face-background 'git-gutter:added "forest green"))
(custom-set-variables
'(git-gutter:modified-sign " ")
'(git-gutter:added-sign "++")
'(git-gutter:deleted-sign "--"))
(use-package git-gutter-fringe
:ensure t)
;; Emojis
(use-package emojify
:config
(when (member "Segoe UI Emoji" (font-family-list))
(set-fontset-font
t 'symbol (font-spec :family "Segoe UI Emoji") nil 'prepend))
(setq emojify-display-style 'unicode)
(setq emojify-emoji-styles '(unicode))
(bind-key* (kbd "C-c e") #'emojify-insert-emoji)) ; override binding in any mode
;; Global key binds
(require 'eglot)
(bind-key* (kbd "<f2>") #'eglot-rename)
(bind-key* (kbd "C-x C-f") 'counsel-find-file)
(bind-key* (kbd "M-x") 'counsel-M-x)
(bind-key* (kbd "C-;") 'neotree-toggle)
(bind-key* (kbd "M-.") 'xref-find-definitions)
(bind-key* (kbd "C-x k") 'kill-this-buffer)
(bind-key* (kbd "C-x b") 'electric-buffer-list)
(defun my-create-file (filename)
"Create a file and refresh neotree. FILENAME File to create."
(interactive (list (read-file-name "Enter your file name: " nil nil nil (file-name-nondirectory ""))))
(make-empty-file filename)
(find-file filename)
(neotree-show)
(neotree-refresh)
(other-window -1))
(bind-key* (kbd "M-n") 'my-create-file)
(defun my-create-directory ()
"Create a directory and refresh neotree."
(interactive)
(call-interactively #'make-directory)
(neotree-show)
(neotree-refresh)
(other-window -1))
(bind-key* (kbd "M-N") 'my-create-directory)
(defun my-delete-file ()
"Delete a file and refresh neotree."
(interactive)
(call-interactively #'delete-file)
(neotree-show)
(neotree-refresh)
(other-window -1))
(bind-key* (kbd "M-d") 'my-delete-file)
(defun my-delete-directory ()
"Delete a file and refresh neotree."
(interactive)
(call-interactively #'delete-directory)
(neotree-show)
(neotree-refresh)
(other-window -1))
(bind-key* (kbd "M-D") 'my-delete-directory)
;; source: http://steve.yegge.googlepages.com/my-dot-emacs-file
(defun my-rename-file (new-name)
"Renames both current buffer and file it's visiting to NEW-NAME."
(interactive "sNew name: ")
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not filename)
(message "Buffer '%s' is not visiting a file!" name)
(if (get-buffer new-name)
(message "A buffer named '%s' already exists!" new-name)
(progn
(rename-file filename new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil)
(neotree-show)
(neotree-refresh)
(other-window -1))))))
(bind-key* (kbd "M-r") 'my-rename-file)
;; Company mode for code completion
(use-package company
:ensure t
:defer t
:init (add-hook 'after-init-hook 'global-company-mode)
:config
(setq company-idle-delay 0.3
company-minimum-prefix-length 2
company-show-quick-access t
company-tooltip-limit 20
company-dabbrev-downcase nil
company-backends '((company-capf company-gtags company-elisp company-css))
)
)
(use-package company-quickhelp
:ensure t
:defer t
:init (company-quickhelp-mode 1)
:config
(setq company-quickhelp-delay 0
)
)
;; Eglot
(use-package eglot
:custom
(eglot-autoshutdown t)
:ensure t)
(set-face-underline 'eglot-highlight-symbol-face t)
(use-package eldoc-box
:ensure t
:defer t)
(add-hook 'emacs-lisp-mode-hook #'eldoc-box-hover-at-point-mode t)
(add-hook 'css-mode-hook #'eldoc-box-hover-at-point-mode t)
(add-hook 'eglot-managed-mode-hook #'eldoc-box-hover-at-point-mode t)
(use-package tree-sitter
:ensure t
:defer t
:config
;; use treesitter when possible
(global-tree-sitter-mode)
;; overwrite the default syntax-highlighting (from major modes)
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)
:hook
(prog-mode . tree-sitter-mode))
(use-package tree-sitter-langs
:ensure t
:defer t)
;; Highlight similar text
(use-package highlight-thing
:config
(setq highlight-thing-what-thing 'region)
(setq highlight-thing-what-thing 'word)
(setq highlight-thing-exclude-thing-under-point t)
(global-highlight-thing-mode)
(setq highlight-thing-delay-seconds 1.0))
;; Vterm
(require 'vterm)
(require 'vterm-toggle)
(setq vterm-toggle-fullscreen-p nil)
(add-to-list 'display-buffer-alist
'((lambda (buffer-or-name _)
(let ((buffer (get-buffer buffer-or-name)))
(with-current-buffer buffer
(or (equal major-mode 'vterm-mode)
(string-prefix-p vterm-buffer-name (buffer-name buffer))))))
(display-buffer-reuse-window display-buffer-at-bottom)
;;(display-buffer-reuse-window display-buffer-in-direction)
;;display-buffer-in-direction/direction/dedicated is added in emacs27
;;(direction . bottom)
;;(dedicated . t) ;dedicated is supported in emacs27
(reusable-frames . visible)
(window-height . 0.2)))
(bind-key* (kbd "M-t") 'vterm-toggle)
(defun my-vterm-mode-set-colors()
"Set the colors of vterm to match my personal taste."
(setq-local global-hl-line-mode nil)
;(turn-off-evil-mode)
(display-line-numbers-mode -1)
(setq left-fringe-width 0)
(setq right-fringe-width 0)
(set-window-fringes (selected-window) 0 0 nil)
(face-remap-add-relative 'default '(:background "#232627"))
(face-remap-add-relative 'default '(:foreground"#fcfcfc"))
)
(add-hook 'vterm-mode-hook 'my-vterm-mode-set-colors)
;; Line movement
(require 'drag-stuff)
(drag-stuff-global-mode)
(drag-stuff-define-keys)
;; Copy the entire buffer.
(defun my-copy-all ()
"Copy entire buffer to clipboard."
(interactive)
(clipboard-kill-ring-save (point-min) (point-max)))
(use-package flycheck
:config
(setq flycheck-check-syntax-automatically '(save mode-enable))
'(flycheck-idle-change-delay 1))
(provide 'general)
;;; general.el ends here
|