summaryrefslogtreecommitdiff
path: root/.config/emacs/settings.org
blob: d89566d498ca2da62746d3d026b43fae2da845d7 (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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
* Initialization
** Garbage Collection Improvement
#+BEGIN_SRC emacs-lisp

(defun my-minibuffer-setup-hook ()
  (setq gc-cons-threshold most-positive-fixnum))

(defun my-minibuffer-exit-hook ()
  (setq gc-cons-threshold 800000000))

(add-hook 'minibuffer-setup-hook #'my-minibuffer-setup-hook)
(add-hook 'minibuffer-exit-hook #'my-minibuffer-exit-hook)

(defun gc-idle-timer ()
  "Trigger garbage collection when Emacs is idle for 0.5 seconds."
  (run-with-idle-timer 1.2 t 'garbage-collect))

(gc-idle-timer)

#+END_SRC

** List of packages to install
#+BEGIN_SRC emacs-lisp

(setq my-package-list '( use-package
			 no-littering
			 rainbow-delimiters
			 ansi-color
			 expand-region
			 mwim
			 delsel
			 multiple-cursors
			 evil-nerd-commenter
			 dired-subtree
			 dracula-theme
			 nerd-icons
			 nerd-icons-dired
			 nerd-icons-completion
			 nerd-icons-corfu
			 vertico
			 marginalia
			 orderless
			 consult
			 magit
			 lsp-mode
			 lsp-ui
			 corfu
			 yasnippet
			 yasnippet-snippets))
#+END_SRC
** Packages
#+BEGIN_SRC emacs-lisp
(require 'package) ;; Emacs builtin

;; set package.el repositories
(setq package-archives
      '(
    	("org" . "https://orgmode.org/elpa/")
    	("gnu" . "https://elpa.gnu.org/packages/")
    	("melpa" . "https://melpa.org/packages/")
    	))

;; initialize built-in package management
(package-initialize)

;; update packages list if we are on a new install
(unless package-archive-contents
  (package-refresh-contents))

;; programmatically install/ensure installed
;; pkgs in your personal list
(dolist (package my-package-list)
  (unless (package-installed-p package)
    (package-install package)))

#+END_SRC
** Customize in different file
#+BEGIN_SRC emacs-lisp
  (setq custom-file (expand-file-name "customs.el" user-emacs-directory))
  (load custom-file :no-error-if-file-is-missing)
#+END_SRC
* Basic changes
** Behaviour
#+BEGIN_SRC emacs-lisp

(use-package no-littering)

(setq make-backup-files nil
      create-lockfiles nil
      erc-join-buffer 'window
      confirm-kill-processes nil)

(setq inhibit-startup-message t
      backup-inhibited t)

(setq vc-follow-symlinks t)

(use-package saveplace
  :init
  (save-place-mode))

#+END_SRC
** Org Mode
#+BEGIN_SRC emacs-lisp

  (setq org-startup-folded t
	org-src-preserve-indentation t
	org-src-tab-acts-natively t
	org-edit-src-content-indentation t)

#+END_SRC
** UI
#+BEGIN_SRC emacs-lisp

(scroll-bar-mode -1)
(tool-bar-mode -1)
(tooltip-mode -1)
(menu-bar-mode -1)

(column-number-mode +1)
(setq-default fill-column 80)
(global-display-line-numbers-mode t)
(setq display-line-numbers-width-start t
	  display-line-numbers-type t)

(use-package rainbow-delimiters
  :hook (prog-mode . rainbow-delimiters-mode))

(use-package ansi-color
  :hook (compilation-filter . ansi-color-compilation-filter))

#+END_SRC
** Text Editing
#+BEGIN_SRC emacs-lisp

;; tab width
(setq-default tab-width 4)
(setq backward-delete-char-untabify-method "hungry")

;; scrolling
(setq scroll-up-aggressively nil
      scroll-down-aggressively nil
      scroll-conservatively 101)
(setq scroll-step 1)
(setq scroll-margin 8)

;; electric pair
(electric-pair-mode +1)

;; improved C-g dwim
(defun prot/keyboard-quit-dwim ()
  (interactive)
  (cond
   ((region-active-p)
    (keyboard-quit))
   ((derived-mode-p 'completion-list-mode)
    (delete-completion-window))
   ((> (minibuffer-depth) 0)
    (abort-recursive-edit))
   (t
    (keyboard-quit))))
(define-key global-map (kbd "C-g") #'prot/keyboard-quit-dwim)

;; expand keybind
(use-package expand-region
  :bind("C-=" . er/expand-region))

;; better move beginning and end
(use-package mwim
  :bind (("C-a" . mwim-beginning)
	 ("C-e" . mwim-end-of-line)))

;; selected marked text when typing start
(use-package delsel
  :ensure nil ; no need to install it as it is built-in
  :hook (after-init . delete-selection-mode))

(use-package multiple-cursors
  :bind (:map global-map
	      ("C->" . 'mc/mark-next-like-this)
	      ("C-<" . 'mc/mark-previous-like-this)
	      ("C-c C->" . 'mc/mark-all-like-this)
	      :map mc/keymap
	      ("<return>" . nil)))

;; better commenting
(use-package evil-nerd-commenter
  :bind ("M-;" . evilnc-comment-or-uncomment-lines))

#+END_SRC

** Dired
#+BEGIN_SRC emacs-lisp
(use-package dired
  :ensure nil
  :commands (dired)
  :hook
  ((dired-mode . dired-hide-details-mode)
   (dired-mode . hl-line-mode))
  :config
  (setq dired-recursive-copies 'always)
  (setq dired-recursive-deletes 'always)
  (setq dired-dwim-target t)
  (setq dired-kill-when-opening-new-dired-buffer t)
  (setq dired-listing-switches "-alh --group-directories-first"))

(use-package dired-subtree
  :after dired
  :bind
  ( :map dired-mode-map
    ("<tab>" . dired-subtree-toggle)
    ("TAB" . dired-subtree-toggle)
    ("<backtab>" . dired-subtree-remove)
    ("S-TAB" . dired-subtree-remove))
  :config
  (setq dired-subtree-use-backgrounds nil))

#+END_SRC
* Style
#+BEGIN_SRC emacs-lisp

(use-package dracula-theme)
(load-theme 'dracula)

(set-face-attribute 'show-paren-match nil :background "dark violet" :foreground "black")

#+END_SRC

*** Icons
#+BEGIN_SRC emacs-lisp

(use-package nerd-icons)

(use-package nerd-icons-dired
  :ensure t
  :hook
  (dired-mode . nerd-icons-dired-mode))

(use-package nerd-icons-completion
  :ensure t
  :after marginalia
  :config
  (add-hook 'marginalia-mode-hook #'nerd-icons-completion-marginalia-setup))

(use-package nerd-icons-corfu
  :ensure t
  :after corfu
  :config
  (add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter))

#+END_SRC

* Minibuffer completion
#+BEGIN_SRC emacs-lisp
(use-package vertico
  :ensure nil
  :custom
  (vertico-count 15)
  :diminish vertico-mode
  :bind (:map vertico-map
		("C-n" . vertico-next)
		("C-p" . vertico-previous))
  :init
  (vertico-mode t))

(use-package vertico-directory
  :after vertico
  :ensure nil

  ;; More convenient directory navigation commands
  :bind (:map vertico-map
		("RET" . vertico-directory-enter)
		("DEL" . vertico-directory-delete-char)
		("M-DEL" . vertico-directory-delete-word)))

(use-package marginalia
  :after vertico
  :custom
  (marginalia-annotators '(marginalia-annotators-heavy marginalia-annotators-light nil))
  :config
  (marginalia-mode))

(use-package orderless
  :config
  (setq completion-styles '(orderless partial-completion basic)
	  completion-category-defaults nil
	  completion-category-overrides '((file (styles . (partial-completion))))))

(use-package savehist
  :ensure nil ; it is built-in
  :hook (after-init . savehist-mode))

#+END_SRC

* Misc Binds
#+BEGIN_SRC emacs-lisp

;; shortcuts
(use-package consult
  :custom
  ;; Disable preview
  (consult-preview-key nil)
  :bind
  (("C-x b" . 'consult-buffer)    ;; Switch buffer, including recentf and bookmarks
   ("M-l"   . 'consult-git-grep)  ;; Search inside a project
   ("M-y"   . 'consult-yank-pop)  ;; Paste by selecting the kill-ring
   ("M-s"   . 'consult-line)      ;; Search current buffer, like swiper
   ("C-c i" . 'consult-imenu)     ;; Search the imenu
   ))

(global-set-key (kbd "C-c f") 'ff-find-other-file)

#+END_SRC
* Development
** Magit
#+BEGIN_SRC emacs-lisp
(use-package transient)

(use-package magit
  :bind (("C-x g" . magit-status))
  :custom
  (magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1))

#+END_SRC
** LSP
*** lsp-mode
#+BEGIN_SRC emacs-lisp
(use-package lsp-mode
  :init
  (setq lsp-keymap-prefix "C-c l"
		lsp-headerline-breadcrumb-enable nil
		lsp-completion-enable-additional-text-edit nil
		lsp-completion-provider :none
		lsp-idle-delay 0.05)
  :hook (;; automatic lsp
         (c++-mode . lsp))
  :commands lsp)

;; ui
(use-package lsp-ui
  :commands lsp-ui-mode
  :hook (lsp-mode . lsp-ui-mode)
  :bind (
	     ("C-c r" . lsp-ui-peek-find-references)
	     ("C-c d" . lsp-ui-peek-find-definitions) 
	     ))

#+END_SRC

*** lsp-mode performance
#+BEGIN_SRC emacs-lisp

(setq read-process-output-max (* 1024 1024)) ;; 1mb

#+END_SRC

** Text Completion
#+BEGIN_SRC emacs-lisp

;; corfu (fancy completion)
(use-package corfu
  :bind (:map corfu-map
			  ("C-g" . corfu-quit))
  :init
  (global-corfu-mode)
  (corfu-history-mode))

;; completion preview (ghost text)
(global-completion-preview-mode)
(global-set-key (kbd "M-n") 'completion-preview-next-candidate)
(global-set-key (kbd "M-p") 'completion-preview-prev-candidate)

#+END_SRC
** Snippets
#+BEGIN_SRC emacs-lisp

(use-package yasnippet
  :config
  (yas-global-mode t)
  :diminish yas-minor-mode)

(use-package yasnippet-snippets)

#+END_SRC