summaryrefslogtreecommitdiffstats
path: root/init.el
blob: 277f86eb80c9d00eeea557151698002027502ebf (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
;; ----------------------------------------------------------------------------

;; Improve start-up time by tweaking the garbage collector settings.
;; Reference:
;;   - https://emacs.stackexchange.com/a/34367
(defvar gc-cons-threshold-original gc-cons-threshold)
(setq gc-cons-threshold (* 1024 1024 50))
(defvar file-name-handler-alist-original file-name-handler-alist)
(setq file-name-handler-alist nil)

(run-with-idle-timer
 5 nil
 (lambda ()
   (setq gc-cons-threshold gc-cons-threshold-original)
   (setq file-name-handler-alist file-name-handler-alist-original)
   (makunbound 'gc-cons-threshold-original)
   (makunbound 'file-name-handler-alist-original)
   (message "gc-cons-threshold and file-name-handler-alist restored")))

;; ----------------------------------------------------------------------------

;; Uncomment this to enable statistics.  Once Emacs is ready, you can
;; use the `use-package-report' to gather data on startup timing.
;; (setq use-package-compute-statistics t)

;; ----------------------------------------------------------------------------

;; Bootstrap straight.el per README instructions
;; Reference:
;;   - https://github.com/raxod502/straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
	(url-retrieve-synchronously
	 "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
	 'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

;; ----------------------------------------------------------------------------

;; Install and configure use-package
;; Reference:
;;    - https://github.com/nasseralkmim/.emacs.d/blob/master/init.el

(straight-use-package 'use-package)

(setq use-package-verbose nil
      use-package-compute-statistics t
      use-package-expand-minimally t
      use-package-always-defer t)

(setq straight-use-package-by-default t)

;; ----------------------------------------------------------------------------

;; Control minor-mode indication in the mode-line
;; Useful to prevent minor mode to clutter the modline.

(use-package diminish :demand)

;; ----------------------------------------------------------------------------

;; Minimizes GC interferecen with user activity

(use-package gcmh
  :diminish gcmh-mode
  :init
  (setq gcmh-idle-delay 0.5
	gcmh-high-cons-threshold (* 16 1024 1024))
  (gcmh-mode 1))

;; ----------------------------------------------------------------------------

;; better default
(use-package emacs
  :hook
  ((before-save . delete-trailing-whitespace))
  :init
  ;; Backup and auto-save in /tmp.
  (setq backup-directory-alist `((".*" . ,temporary-file-directory)))
  (setq auto-save-file-name-transforms `((".*" ,temporary-file-directory t)))
  ;; Use space instead of tabs.
  (setq-default indent-tabs-mode nil)
  ;; Do not wait for highlighting search matches
  (setq lazy-highlight-initial-delay 0)
  ;; Zoom in and out using <C-+> and <C-->
  (global-set-key (kbd "C-+") 'text-scale-increase)
  (global-set-key (kbd "C--") 'text-scale-decrease)
  ;; UTF-8 encoding
  (prefer-coding-system 'utf-8)
  (set-default-coding-systems 'utf-8)
  (set-terminal-coding-system 'utf-8)
  (set-keyboard-coding-system 'utf-8)
  ;; native-comp
  (setq native-comp-async-report-warnings-errors nil))

;; ----------------------------------------------------------------------------

;; Configure the UI look and feel

(use-package +ui
  :straight nil
  :load-path "~/.emacs.d/core"
  :demand)

;; ----------------------------------------------------------------------------

(use-package +theme
  :straight nil
  :load-path "~/.emacs.d/core"
  :hook (after-init . load-theme-and-reset-ui)
  :demand)

(use-package vertico
  ;; :straight (:files (:defaults "extensions/*"))
  :demand
  :custom
  (vertico-cycle t)
  :config
  (vertico-mode))

(use-package savehist
  :init
  (savehist-mode))

;; Projectile
(use-package projectile
  :demand
  :init
  (defun use-projectile-root ()
    (if (and (projectile-project-p)
	     (projectile-project-root))
	(setq default-directory (projectile-project-root))))
  :config
  (projectile-mode)
  :hook
  (find-file . use-projectile-root))

;; Provide a backend for redo.
;; Will not be necessary once Emacs 28 is released
(use-package undo-fu)

;; Interact with the clipboard
(defun copy-to-clipboard ()
  "Copy the selection to clipboard."
  (interactive)
  (if (display-graphic-p)
      (progn
        (message "Yanked region to x-clipboard!")
        (call-interactively 'clipboard-kill-ring-save)
        )
    (if (region-active-p)
        (progn
          (shell-command-on-region (region-beginning) (region-end) "xsel -i -b")
          (message "Yanked region to clipboard!")
          (deactivate-mark))
      (message "No region active; can't yank to clipboard!"))))

(defun paste-from-clipboard ()
  "Paste the clipboard content into the buffer at cursor."
  (interactive)
  (setq select-enable-clipboard t)
  (yank)
  (setq select-enable-clipboard nil))

(use-package +evil
  :straight nil
  :load-path "~/.emacs.d/core"
  :demand)

(defvar-local menu-major-mode/body (lambda () (interactive) nil))

(defun set-menu-major-mode (m)
  (lambda ()
    (setq-local menu-major-mode/body m)))

;; Source: http://www.emacswiki.org/emacs-en/download/misc-cmds.el
(defun revert-buffer-no-confirm ()
    "Revert buffer without confirmation."
    (interactive)
    (revert-buffer :ignore-auto :noconfirm))

(defun print-file-name ()
  "Print the path of the current buffer."
  (interactive)
  (message (buffer-file-name)))

;; Hydra
(use-package hydra
  :demand
  :after (+evil projectile +theme)
  :config
  (defhydra menu-program (:exit t :columns 4)
    ("e" eldoc-mode "Toggle eldoc")
    ("f" flycheck-mode "Toggle flycheck"))
  (+menu-themes)
  (defhydra menu-org-notes (:exit t :columns 4)
    "Organize your life in plain text (or so I’ve been told)"
    ("n" (org-capture nil "n") "Start working on a new task")
    ("i" (find-file org-default-notes-file) "Visit the inbox")
    ("ci" (org-capture nil "i") "Add an entry in the inbox")
    ("I" (find-file +org-idea-file) "Visit the ideas box")
    ("cI" (org-capture nil "I") "I have an idea")
    ("t" (find-file +org-today-file) "Visit today’s file")
    ("ct" (org-capture nil "t") "Add an entry in today’s file")
    ("y" (find-file +org-yesterday-file) "Visit yesterday’s file")
    ("a" org-agenda "Visit org agenda"))
  (defhydra menu-home (:exit t :columns 4)
    "Where everything start"
    ("." projectile-find-file "Find file")
    (":" execute-extended-command "M-x")
    ("b" switch-to-buffer "Switch to buffer")
    ("à" projectile-switch-project "Switch to project")
    ("p" menu-program/body "Program stuff")
    ("o" menu-org-notes/body "Org")
    ("t" menu-themes/body "Theming")
    ("m" (call-interactively menu-major-mode/body) "Major mode")
    ("x" kill-this-buffer "Kill buffer")
    ("q" delete-window "Delete window")
    ("c" comment-dwim "Toggle comment")
    ("s" stgit "Stacked Git")
    ("r" revert-buffer-no-confirm "Reload file")
    ("f" flyspell-buffer "Spellcheck"))
  :bind
  (:map
   evil-normal-state-map
   ("SPC" . menu-home/body)
   :map
   evil-insert-state-map
   ("M-SPC" . menu-home/body)
   :map
   evil-visual-state-map
   ("SPC" . menu-home/body)))

(use-package +prog
  :straight nil
  :load-path "~/.emacs.d/core"
  :demand)

(use-package +git
  :straight nil
  :load-path "~/.emacs.d/core"
  :demand)

(use-package +ocaml
  :straight nil
  :after +prog
  :load-path "~/.emacs.d/lang"
  :demand)

(use-package +coq
  :straight nil
  :after +prog
  :load-path "~/.emacs.d/lang"
  :demand)

(use-package +elisp
  :straight nil
  :after +prog
  :load-path "~/.emacs.d/lang"
  :demand)

(use-package +org
  :straight nil
  :after +prog
  :load-path "~/.emacs.d/lang"
  :demand)

(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.
 '(current-theme 'ancientless))
(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.
 )