-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
546 lines (459 loc) · 18.6 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
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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
;;; init.el --- Emacs configuration
;; Note that you'll need to run M-x package-refresh-contents
;; or M-x package-list-packages to ensure that Emacs has
;; fetched the MELPA package list before you can install
;; packages with M-x package-install or similar.
;;; This is not necessary anymore, was used to install node
;;; Adding path to packages included in the git repo,
;;; typically these are the ones not available from MELPA
;;; (add-to-list 'load-path "~/.emacs.d/nomelpa/")
;; You will most likely need to adjust this font size for your system!
(defvar efs/default-font-size 90)
(defvar efs/default-variable-font-size 90)
;; Make frame transparency overridable
(defvar efs/frame-transparency '(90 . 90))
;; The default is 800 kilobytes. Measured in bytes.
(setq gc-cons-threshold (* 50 1000 1000))
(defun efs/display-startup-time ()
(message "Emacs loaded in %s with %d garbage collections."
(format "%.2f seconds"
(float-time
(time-subtract after-init-time before-init-time)))
gcs-done))
(add-hook 'emacs-startup-hook #'efs/display-startup-time)
;; Initialize package sources
(require 'package)
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("org" . "https://orgmode.org/elpa/")
("elpa" . "https://elpa.gnu.org/packages/")))
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
;; Initialize use-package on non-Linux platforms
(unless (package-installed-p 'use-package)
(package-install 'use-package))
(require 'use-package)
(setq use-package-always-ensure t)
(use-package auto-package-update
:custom
(auto-package-update-interval 7)
(auto-package-update-prompt-before-update t)
(auto-package-update-hide-results t)
:config
(auto-package-update-maybe)
(auto-package-update-at-time "09:00"))
(defvar myPackages
'(better-defaults
;;material-theme ; old theme
;; elpy
yaml-mode
markdown-mode
impatient-mode
;; flycheck
ace-window
irony
pytest
magit
use-package))
(mapc #'(lambda (package)
(unless (package-installed-p package)
(package-install package)))
myPackages)
;;; END INSTALL PACKAGES
;;; BEGIN BASIC CUSTOMIZATION
(setq inhibit-startup-message t) ;; hide the startup message
(scroll-bar-mode -1) ; Disable visible scrollbar
(tool-bar-mode -1) ; Disable the toolbar
(tooltip-mode -1) ; Disable tooltips
(set-fringe-mode 10) ; Give some breathing room
(menu-bar-mode -1) ; Disable the menu bar
;; Set up the visible bell
(setq visible-bell t)
(column-number-mode) ;; showing lines and columns
(global-display-line-numbers-mode t) ;; enable line numbers globally
;; Set frame transparency
(set-frame-parameter (selected-frame) 'alpha efs/frame-transparency)
(add-to-list 'default-frame-alist `(alpha . ,efs/frame-transparency))
(set-frame-parameter (selected-frame) 'fullscreen 'maximized)
(add-to-list 'default-frame-alist '(fullscreen . maximized))
;; Disable line numbers for some modes
(dolist (mode '(org-mode-hook
term-mode-hook
shell-mode-hook
treemacs-mode-hook
eshell-mode-hook
vterm-mode-hook))
(add-hook mode (lambda () (display-line-numbers-mode 0))))
(set-face-attribute 'default nil :font "Fira Code Retina" :height efs/default-font-size)
;; Set the fixed pitch face
(set-face-attribute 'fixed-pitch nil :font "Fira Code Retina" :height efs/default-font-size)
;; Set the variable pitch face
(set-face-attribute 'variable-pitch nil :font "Cantarell" :height efs/default-variable-font-size :weight 'regular)
;; Make ESC quit prompts
(global-set-key (kbd "<escape>") 'keyboard-escape-quit)
;; (use-package general
;; :after evil
;; :config
;; (general-create-definer efs/leader-keys
;; :keymaps '(normal insert visual emacs)
;; :prefix "SPC"
;; :global-prefix "C-SPC")
;; (efs/leader-keys
;; "t" '(:ignore t :which-key "toggles")
;; "tt" '(counsel-load-theme :which-key "choose theme")))
(use-package doom-themes
:init (load-theme 'doom-palenight t))
;; NOTE: The first time you load your configuration on a new machine, you’ll need
;; to run `M-x all-the-icons-install-fonts` so that mode line icons display correctly.
(use-package all-the-icons)
(use-package doom-modeline
:init (doom-modeline-mode 1)
:custom ((doom-modeline-height 15)))
;; offer completion for prefixes
(use-package which-key
:defer 0
:diminish which-key-mode
:config
(which-key-mode)
(setq which-key-idle-delay 1))
(use-package ivy
:diminish
:bind (("C-s" . swiper)
:map ivy-minibuffer-map
("TAB" . ivy-alt-done)
("C-l" . ivy-alt-done)
("C-j" . ivy-next-line)
("C-k" . ivy-previous-line)
:map ivy-switch-buffer-map
("C-k" . ivy-previous-line)
("C-l" . ivy-done)
("C-d" . ivy-switch-buffer-kill)
:map ivy-reverse-i-search-map
("C-k" . ivy-previous-line)
("C-d" . ivy-reverse-i-search-kill))
:config
(ivy-mode 1))
(use-package ivy-rich
:after ivy
:init
(ivy-rich-mode 1))
(use-package counsel
:bind (("C-M-j" . 'counsel-switch-buffer)
:map minibuffer-local-map
("C-r" . 'counsel-minibuffer-history))
:custom
(counsel-linux-app-format-function #'counsel-linux-app-format-function-name-only)
:config
(counsel-mode 1))
(use-package ivy-prescient
:after counsel
:custom
(ivy-prescient-enable-filtering nil)
:config
;; Uncomment the following line to have sorting remembered across sessions!
(prescient-persist-mode 1)
(ivy-prescient-mode 1))
(use-package helpful
:commands (helpful-callable helpful-variable helpful-command helpful-key)
:custom
(counsel-describe-function-function #'helpful-callable)
(counsel-describe-variable-function #'helpful-variable)
:bind
([remap describe-function] . counsel-describe-function)
([remap describe-command] . helpful-command)
([remap describe-variable] . counsel-describe-variable)
([remap describe-key] . helpful-key))
(use-package projectile
:diminish projectile-mode
:config (projectile-mode)
:custom ((projectile-completion-system 'ivy))
:bind-keymap
("C-c p" . projectile-command-map)
:init
;; NOTE: Set this to the folder where you keep your Git repos!
(when (file-directory-p "~/github")
(setq projectile-project-search-path '("~/github")))
(setq projectile-switch-project-action #'projectile-dired))
(use-package counsel-projectile
:after projectile
:config (counsel-projectile-mode))
(use-package vterm
:commands vterm
:config
(setq term-prompt-regexp "^[^#$%>\n]*[#$%>] *") ;; Set this to match your custom shell prompt
;;(setq vterm-shell "zsh") ;; Set this to customize the shell to launch
(setq vterm-max-scrollback 10000))
(when (eq system-type 'windows-nt)
(setq explicit-shell-file-name "powershell.exe")
(setq explicit-powershell.exe-args '()))
(use-package pyvenv
:after python-mode
:config
(pyvenv-mode 1))
;; Configuration below is not from daviwil/emacs-from-scratch
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Not sure if this is required
;; Save registers between sessions
;; Move customization variables to a separate file and load it
(setq custom-file (locate-user-emacs-file "custom-vars.el"))
(load custom-file 'noerror 'nomessage)
(desktop-save-mode)
;; https://github.com/pashinin/workgroups2
(use-package workgroups2
:config
(setq wg-session-file "~/.emacs.d/.emacs_workgroups")
(workgroups-mode 1)
)
;; Remove, replaced by workgroups2
;; don't use desktop mode for terminal
;; (when (display-graphic-p)
;; (desktop-save-mode);; is x window
;; ())
;; ;; Add variables to desktop saving
;; (add-to-list 'desktop-globals-to-save 'register-alist)
;;Old theme configuration
;;(load-theme 'material t) ;; load material theme
;; https://stackoverflow.com/questions/11700934/emacs-set-and-toggle-show-trailing-whitespace
(setq-default show-trailing-whitespace t) ;; showing trailing whitespace
;; https://stackoverflow.com/questions/19174302/emacs-only-delete-trailing-whitespace-while-saving-in-programming-mode
;;(add-hook 'write-file-hooks 'delete-trailing-whitespace) ;; remove trailing whitespace when saving
(add-hook 'before-save-hook 'my-prog-nuke-trailing-whitespace)
(defun my-prog-nuke-trailing-whitespace ()
(when (derived-mode-p 'prog-mode)
(delete-trailing-whitespace)))
(setq-default indent-tabs-mode nil) ;; no tabs
;; Compilation output
;; https://stackoverflow.com/questions/4657142/how-do-i-encourage-emacs-to-follow-the-compilation-buffer
(setq compilation-scroll-output t)
;;(setq compilation-scroll-output t)
;;; END BASIC CUSTOMIZATION
;;
;; Key-bindings
;;
(global-set-key "\C-x\C-g" 'goto-line)
(global-set-key "\C-x\C-d" 'insert-date)
(global-set-key "\C-x\C-t" 'insert-timestamp)
(global-set-key [f1] '(lambda () (interactive) (manual-entry (current-word))))
(global-set-key [f2] 'ecb-toggle-ecb-windows)
(global-set-key [f3] 'ecb-activate)
(global-set-key [f4] 'query-replace)
(global-set-key [f5] 'compile)
(global-set-key [f6] 'next-error)
(global-set-key [f8] 'ispell-buffer)
(global-set-key [f9] 'gdb)
;; f10 goes to menu
(global-set-key [f11] 'add-change-log-entry-other-window)
(global-set-key [f12] 'next-multiframe-window)
(global-set-key "\C-z" 'undo)
;; toggle cpp/hpp files
(global-set-key "\C-t" 'ff-find-other-file)
;; set title of frame
(setq-default frame-title-format
(list '((buffer-file-name " %f" (dired-directory
dired-directory
(revert-buffer-function " %b"
("%b - Dir: " default-directory) ))))))
;; yank over selection
;; https://stackoverflow.com/questions/2627289/how-to-replace-a-region-in-emacs-with-yank-buffer-contents
(delete-selection-mode 1)
;; toggle to previous window
;; https://emacs.stackexchange.com/questions/7409/is-there-a-generic-toggle-previous-window-function
(defun switch-to-last-window ()
(interactive)
(let ((win (get-mru-window t t t)))
(unless win (error "Last window not found."))
(let ((frame (window-frame win)))
(raise-frame frame)
(select-frame frame)
(select-window win))))
;; elpy
;; Elpy creates its own ve under ~/.emacs.d/elpy/rpc-venv. It seems to update
;; this ve when required. I'm currently using flycheck to code check.
(use-package elpy
:ensure t
:init
(elpy-enable))
;; flycheck
(use-package flycheck
:ensure t
:init (global-flycheck-mode))
;; Enable flycheck for elpy
(when (require 'flycheck nil t)
(setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
(add-hook 'elpy-mode-hook 'flycheck-mode))
;; Enable flycheck
;; http://code.litomisky.com/2014/10/24/getting-with-pylint-in-emacs/
(add-hook 'after-init-hook #'global-flycheck-mode)
;; pylint as default python checker
(add-hook 'python-mode-hook #'(lambda () (setq flycheck-checker 'python-pylint)))
;; gcc as default C++ checker
(add-hook 'c++-mode-hook #'(lambda () (setq flycheck-checker 'c/c++-gcc)))
;; python-pytest
;; https://github.com/wbolster/emacs-python-pytest
(use-package python-pytest
:config
;; --runslow custom option
(transient-append-suffix
'python-pytest-dispatch
'(-2)
["My custom options"
("--rs" "Run slow tests" "--runslow")]))
(global-set-key (kbd "C-x j") 'python-pytest-dispatch)
;; markdown & friends
(use-package markdown-mode
:ensure t
:commands (markdown-mode gfm-mode)
:mode (("README\\.md\\'" . gfm-mode)
("\\.md\\'" . markdown-mode)
("\\.markdown\\'" . markdown-mode))
:init (setq markdown-command "multimarkdown"))
;;https://stackoverflow.com/questions/36183071/how-can-i-preview-markdown-in-emacs-in-real-time
;; (defun markdown-html (buffer)
;; (princ (with-current-buffer buffer
;; (format "<!DOCTYPE html><html><title>Impatient Markdown</title><xmp theme=\"united\" style=\"display:none;\"> %s </xmp><script src=\"http://strapdownjs.com/v/0.2/strapdown.js\"></script></html>" (buffer-substring-no-properties (point-min) (point-max))))
;; (current-buffer)))
;; https://stackoverflow.com/a/51860126/1259982
(defun markdown-html (buffer)
(princ (with-current-buffer buffer
(format "<!DOCTYPE html><html><title>Impatient Markdown</title><xmp theme=\"united\" style=\"display:none;\"> %s </xmp><script src=\"http://ndossougbe.github.io/strapdown/dist/strapdown.js\"></script></html>" (buffer-substring-no-properties (point-min) (point-max))))
(current-buffer)))
(defun markdown-html-option (buffer)
(princ (with-current-buffer buffer
(format "<!DOCTYPE html><html><script src=\"https://cdnjs.cloudflare.com/ajax/libs/he/1.1.1/he.js\"></script><link rel=\"stylesheet\" href=\"https://assets-cdn.github.com/assets/github-e6bb18b320358b77abe040d2eb46b547.css\"><link rel=\"stylesheet\" href=\"https://assets-cdn.github.com/assets/frameworks-95aff0b550d3fe338b645a4deebdcb1b.css\"><title>Impatient Markdown</title><div id=\"markdown-content\" style=\"display:none\">%s</div><div class=\"markdown-body\" style=\"max-width:968px;margin:0 auto;\"></div><script>fetch('https://api.github.com/markdown', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ \"text\": document.getElementById('markdown-content').innerHTML, \"mode\": \"gfm\", \"context\": \"knit-pk/homepage-nuxtjs\"}) }).then(response => response.text()).then(response => {document.querySelector('.markdown-body').innerHTML = he.decode(response)}).then(() => { fetch(\"https://gist.githubusercontent.com/FieryCod/b6938b29531b6ec72de25c76fa978b2c/raw/\").then(response => response.text()).then(eval)});</script></html>"
(buffer-substring-no-properties (point-min) (point-max))))
(current-buffer)))
(defun markdown-preview-like-god ()
(interactive)
(impatient-mode 1)
(setq imp-user-filter #'markdown-html)
(cl-incf imp-last-state)
(imp--notify-clients))
;; https://stackoverflow.com/questions/1587972/how-to-display-indentation-guides-in-emacs/4459159#4459159
(defun aj-toggle-fold ()
"Toggle fold all lines larger than indentation on current line"
(interactive)
(let ((col 1))
(save-excursion
(back-to-indentation)
(setq col (+ 1 (current-column)))
(set-selective-display
(if selective-display nil (or col 1))))))
(global-set-key [(M C i)] 'aj-toggle-fold)
;; ace window
;; was orignally using M-p but this conflicts with 'previous error' for *compiling*
;; and *nose*
(global-set-key (kbd "M-o") 'ace-window)
;; disable C-x C-c
;; (global-unset-key (kbd "C-x C-c"))
;; irony, company-irony
;; does not work on CentOS6, requires update CMake
;; https://github.com/Sarcasm/irony-mode
;; https://github.com/Sarcasm/company-irony
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
;; Windows performance tweaks
(when (boundp 'w32-pipe-read-delay)
(setq w32-pipe-read-delay 0))
;; Set the buffer size to 64K on Windows (from the original 4K)
(when (boundp 'w32-pipe-buffer-size)
(setq irony-server-w32-pipe-buffer-size (* 64 1024)))
;; Electric (auto pair close)
(electric-pair-mode 1)
(defun electric-pair ()
"If at end of line, insert character pair without surrounding spaces.
Otherwise, just insert the typed character."
(interactive)
(if (eolp) (let (parens-require-spaces) (insert-pair))
(self-insert-command 1)))
;; Python configuration
(add-hook 'python-mode-hook
(lambda ()
(define-key python-mode-map "\"" 'electric-pair)
(define-key python-mode-map "\'" 'electric-pair)
(define-key python-mode-map "(" 'electric-pair)
(define-key python-mode-map "[" 'electric-pair)
(define-key python-mode-map "{" 'electric-pair)))
;; Pytest
(use-package pytest)
;; Javascript configuration
;; https://www.draketo.de/software/emacs-javascript.html
(use-package js2-mode :ensure t :defer 20
:mode
(("\\.js\\'" . js2-mode))
:custom
(js2-include-node-externs t)
(js2-global-externs '("customElements"))
(js2-highlight-level 3)
(js2r-prefer-let-over-var t)
(js2r-prefered-quote-type 2)
(js-indent-align-list-continuation t)
(global-auto-highlight-symbol-mode t)
:config
(setq js-indent-level 2)
;; patch in basic private field support
(advice-add #'js2-identifier-start-p
:after-until
(lambda (c) (eq c ?#))))
(use-package js2-refactor :ensure t :defer 30
:config
(add-hook 'js2-mode-hook #'js2-refactor-mode)
(js2r-add-keybindings-with-prefix "C-c C-m"))
;; context menu for keybindings
(use-package discover :ensure t :defer 30
:config
(global-discover-mode 1))
;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
;; (add-hook 'js2-mode-hook #'js2-imenu-extras-mode)
;; (add-hook 'js2-mode-hook #'js2-refactor-mode)
;; (js2r-add-keybindings-with-prefix "C-c C-r")
;; (define-key js2-mode-map (kbd "C-k") #'js2r-kill)
;; ;; js-mode (which js2 is based on) binds "M-." which conflicts with xref, so
;; ;; unbind it.
;; (define-key js-mode-map (kbd "M-.") nil)
;; (add-hook 'js2-mode-hook (lambda ()
;; (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t)))
;; magit
(global-set-key (kbd "C-x g") 'magit-status)
(global-set-key (kbd "C-x M-g") 'magit-dispatch)
;; hideshow
(defun my-hide-all()
(interactive)
(hs-minor-mode)
(hs-hide-all))
(add-hook 'prog-mode-hook 'my-hide-all)
;;hiding block of code
(global-set-key (kbd "C-c h") (kbd "C-c @ C-h"))
;;show block of code
(global-set-key (kbd "C-c s") (kbd "C-c @ C-s"))
;; tools to reload .dir-locals.el from
;; https://emacs.stackexchange.com/a/13096/31354
(defun my-reload-dir-locals-for-current-buffer ()
"reload dir locals for the current buffer"
(interactive)
(let ((enable-local-variables :all))
(hack-dir-local-variables-non-file-buffer)))
(defun my-reload-dir-locals-for-all-buffer-in-this-directory ()
"For every buffer with the same `default-directory` as the current buffer's, reload dir-locals."
(interactive)
(let ((dir default-directory))
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (equal default-directory dir)
(my-reload-dir-locals-for-current-buffer))))))
;; activating recentf-mode
(recentf-mode 1)
;; remember and restore the last cursor location of opened files
(save-place-mode 1)
;; don't use pop up UI dialogs when prompting
(setq use-dialog-box nil)
;; revert buffers when the underlying file name has changed
(global-auto-revert-mode 1)
;; revert Dired and other buffers
(setq global-auto-revert-non-file-buffers t)
;; Turn debug on to check sentinel peculiar errors
;; (setq debug-on-error t)
(setq debug-on-error nil)
(provide 'init)
;;; init.el ends here