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
|
#+TITLE: Oreodave's Emacs configuration
#+AUTHOR: Oreodave
#+DESCRIPTION: My Doom Emacs configuration!
* Preclude
- This is my [[https://github.com/hlissner/doom-emacs][Doom Emacs]] configuration.
- Use it for most of my code editing and development needs.
- Incredibly versatile tool in my inventory.
* Variables and Bootstrap config
Bootstrap via literate and setting up basic variables.
** Bootstrap
Load the literate.el file to start parsing.
#+BEGIN_SRC elisp
(load (expand-file-name (concat doom-private-dir "bin/literate.el")))
#+END_SRC
** Doom Variables
#+BEGIN_SRC elisp
(after! core-keybinds
(setq doom-localleader-key ",")
(setq doom-theme 'doom-molokai)
(setq doom-font (font-spec :family "Hack" :size 17)))
#+END_SRC
- Set the doom localleader to "," because it's faster
- Using the font [[https://sourcefoundry.org/hack/][Hack]]
** Other variables
#+BEGIN_SRC elisp
(setq completion-ignore-case t)
(setq truncate-lines t)
(setq display-line-numbers-type nil)
(setq bookmark-default-file (expand-file-name (concat doom-private-dir "bookmarks")))
(setq-default frame-title-format '("%b - Emacs"))
(cl-pushnew '("Libgen" "http://gen.lib.rus.ec/search.php?req=%s") +lookup-provider-url-alist :key #'car :test 'string=)
#+END_SRC
Some quality of life things and others that I couldn't really put in one category
- Using line-numbers that are relative now instead of nothing.
- Set org directory
- Add libgen to search providers
* Package Config
Config for or based heavily around specific packages that I find very important
** DAP
*** Function
First to setup is a routine for setting up all the dap-panes for debugging.
Easier to do than just running all those functions manually
- Routine sets up the panes that I like to use, instead of M-x'ing it
- *<SPC>cD* starts up the routine
#+BEGIN_SRC elisp
(after! dap-mode
(defun dx:debug ()
(interactive)
(dap-ui-mode)
(dap-ui-locals)
(dap-ui-sessions)))
#+END_SRC
*** Keybind
#+BEGIN_SRC elisp
(map!
:after dap-mode
:leader
:desc "Start debugging setup" "cD" #'dx:debug)
#+END_SRC
** Elfeed
Custom functions to work with elfeed, generating new feeds on demand and adding
a keybind to help with that.
*** Feeds
Feeds for elfeed to download from.
#+BEGIN_SRC elisp
(setq elfeed-feeds
'(("http://feeds.bbci.co.uk/news/rss.xml" news)
("http://www.technologyreview.com/rss")
("https://news.ycombinator.com/rss" news compsci)))
#+END_SRC
*** Keybinds
Keybinds for elfeed locally and for the leader.
#+BEGIN_SRC elisp
(map!
(:map elfeed-search-mode-map
:localleader
:desc "Update feeds" "u" #'elfeed-update)
(:leader
:prefix "o"
:desc "Open RSS" "f" #'=rss))
#+END_SRC
** Dashboard
My very own dashboard config using doom dashboard, with these features:
- Custom load message
- Custom splash image and dashboard buffer name
- Custom dashboard sections for myself
*** Benchmark display
Redo the display-benchmark function to display a different message
#+BEGIN_SRC elisp
(defun doom-display-benchmark-h (&optional return-p)
"Display a benchmark, showing number of packages and modules, and how quickly
they were loaded at startup.
If RETURN-P, return the message as a string instead of displaying it."
(funcall (if return-p #'format #'message)
"εmacs loaded %d packages, %d modules in %.03fs"
(- (length load-path) (length doom--initial-load-path))
(if doom-modules (hash-table-count doom-modules) 0)
(or doom-init-time
(setq doom-init-time
(float-time (time-subtract (current-time) before-init-time))))))
#+END_SRC
*** Image and buffer name
Set the splash-image and dashboard buffer name
Space image comes from [[https://flaticon.com][website]]
#+BEGIN_SRC elisp
(setq fancy-splash-image "~/Pictures/space2.png") ; splash image
(setq +doom-dashboard-name "*dashboard*")
#+END_SRC
*** Dashboard items
Set the dashboard functions (segments in overall buffer), set the sections of
the interactive menu as well.
#+BEGIN_SRC elisp
(setq +doom-dashboard-functions ; limit the dashboard items
'(doom-dashboard-widget-banner
doom-dashboard-widget-loaded
doom-dashboard-widget-shortmenu))
(setq +doom-dashboard-menu-sections ; Set a specific amount of items
'(("Open org-agenda"
:icon (all-the-icons-octicon "calendar" :face 'font-lock-keyword-face)
:when (fboundp 'org-agenda)
:action org-agenda)
("Check the weather"
:icon (all-the-icons-wicon "rain" :face 'font-lock-keyword-face)
:action dx:weather)
("Jump to bookmark"
:icon (all-the-icons-octicon "bookmark" :face 'font-lock-keyword-face)
:action bookmark-jump)))
#+END_SRC
** Thesaurus
Powerthesaurus installation, added a keybind in org-mode for looking up words.
#+BEGIN_SRC elisp
(use-package! powerthesaurus
:after-call (org-mode)
:defer-incrementally (org)
:config
(map!
:localleader
:map org-mode-map
:prefix "w"
:desc "Thesaurus" "t" #'powerthesaurus-lookup-word-at-point))
#+END_SRC
Powerthesaurus for thesaurus on writer files
** Spelling checker
Keybinds to org-mode for flyspell package
#+BEGIN_SRC elisp
(map!
:after (flyspell org)
:localleader
:map org-mode-map
:prefix "w"
:desc "Correct current word" "c" #'flyspell-correct-at-point
:desc "Autocorrect word" "a" #'flyspell-auto-correct-word
:desc "Goto next error" "w" #'flyspell-goto-next-error)
#+END_SRC
** Projectile
Add CMakeLists.txt to projectile-project-roots.
#+BEGIN_SRC elisp
(after! projectile
(cl-pushnew "CMakeLists.txt" projectile-project-root-files :test 'string=))
#+END_SRC
* Language Config
Configuration for various languages which I feel can be useful
** C-style languages
Configuration for C and C++.
*** User c-style
Emacs doesn't have the full range of styles that I want, so lemme just do it myself.
#+BEGIN_SRC elisp
(after! cc-mode
(c-add-style
"user"
'((c-basic-offset . 2)
(c-comment-only-line-offset . 0)
(c-hanging-braces-alist (brace-list-open)
(brace-entry-open)
(substatement-open after)
(block-close . c-snug-do-while)
(arglist-cont-nonempty))
(c-cleanup-list brace-else-brace)
(c-offsets-alist
(statement-block-intro . +)
(knr-argdecl-intro . 0)
(substatement-open . 0)
(substatement-label . 0)
(access-label . 0)
(label . 0)
(statement-cont . +)))))
#+END_SRC
*** Pretty symbols
Setup pretty symbols specifically for C++. I import the string type via `using
std::string` which isn't supported in standard doom. So I add support for it.
#+BEGIN_SRC elisp
(after! cc-mode
(set-pretty-symbols!
'(c-mode c++-mode)
:return "return"
:or "||"
:and "&&"
:not "!"
:bool "bool"
:str "string"
:str "std::string"
:float "float"
:int "int"
:false "false"
:true "true"
:null "nullptr"))
#+END_SRC
** LSP
Add lsp-ui-doc-mode to lsp-ui-mode: allows you to see documentation in a little
VSCode style web-kit window.
#+BEGIN_SRC elisp
(after! lsp-ui
(add-hook 'lsp-ui-hook #'lsp-ui-doc-mode)
(setq lsp-ui-doc-position 'top))
#+END_SRC
** CSharp
- I have custom installed the omnisharp roslyn executable, so I'd rather use
that
#+BEGIN_SRC elisp
(after! csharp-mode
(setq omnisharp-server-executable-path "~/Bin/repos/omnisharp-roslyn/run"))
#+END_SRC
*** Unit test over whole projects
- Implemented my own function which piggy backs counsel etags to globally search
tags for test specific context, then goes to it and uses an omnisharp test
command to unit test it. Basically global test search in C# projects. To use
this, just make sure you have tags compiled and that all your tests are
written as some public void *name* _Test (i.e. they are appended with _Test so
that the pattern can be matched)
#+BEGIN_SRC elisp
(after! (csharp-mode counsel-etags)
(defun dx:csharp/get-unit-test-in-project ()
"Unit test anywhere using CTags or ETags and C#"
(interactive)
(let* ((tags-file (counsel-etags-locate-tags-file))
(cands (counsel-etags-collect-cands "void.*Test" t buffer-file-name)))
(ivy-read
"Choose test: "
cands
:action
(lambda (item)
;; From the counsel-etags file-open-api function
(when (string-match "\\`\\(.*?\\):\\([0-9]+\\):\\(.*\\)\\'" item)
(let*
((file (match-string-no-properties 1 item))
(linenum (match-string-no-properties 2 item))
;; always calculate path relative to TAGS
(default-directory (counsel-etags-tags-file-directory)))
(counsel-etags-push-marker-stack (point-marker))
(find-file file)
(counsel-etags-forward-line linenum)
(omnisharp-unit-test-at-point))))
:caller 'dx:csharp/get-unit-tests-in-project))))
#+END_SRC
*** Redo omnisharp-emit-results
- Reimplemented omnisharp-emit-results to emit stdout regardless of whether the
test failed or not
#+BEGIN_SRC elisp
(after! (csharp-mode omnisharp)
(defun omnisharp--unit-test-emit-results (passed results)
"Emits unit test results as returned by the server to the unit test result buffer.
PASSED is t if all of the results have passed. RESULTS is a vector of status data for
each of the unit tests ran."
; we want to clean output buffer for result if things have passed otherwise
; compilation & test run output is to be cleared and results shown only for brevity
(omnisharp--unit-test-message "")
(seq-doseq (result results)
(-let* (((&alist 'MethodName method-name
'Outcome outcome
'ErrorMessage error-message
'ErrorStackTrace error-stack-trace
'StandardOutput stdout
'StanderError stderr) result)
(outcome-is-passed (string-equal "passed" outcome)))
(omnisharp--unit-test-message
(format "[%s] %s "
(propertize
(upcase outcome)
'font-lock-face (if outcome-is-passed
'(:foreground "green" :weight bold)
'(:foreground "red" :weight bold)))
(omnisharp--truncate-symbol-name method-name 76)))
(if error-stack-trace
(omnisharp--unit-test-message error-stack-trace))
(unless (= (seq-length stdout) 0)
(omnisharp--unit-test-message "Standard output:")
(seq-doseq (stdout-line stdout)
(omnisharp--unit-test-message stdout-line)))
(unless (= (seq-length stderr) 0)
(omnisharp--unit-test-message "Standard error:")
(seq-doseq (stderr-line stderr)
(omnisharp--unit-test-message stderr-line)))
))
(omnisharp--unit-test-message "")
(if (eq passed :json-false)
(omnisharp--unit-test-message
(propertize "*** UNIT TEST RUN HAS FAILED ***"
'font-lock-face '(:foreground "red" :weight bold)))
(omnisharp--unit-test-message
(propertize "*** UNIT TEST RUN HAS SUCCEEDED ***"
'font-lock-face '(:foreground "green" :weight bold)))
)
nil))
#+END_SRC
*** Map for C# mode
#+BEGIN_SRC elisp
(after! csharp-mode
(map! ; CSharp Keybinds
:map csharp-mode-map
:localleader
:desc "Format buffer" "=" #'omnisharp-code-format-entire-file
(:prefix "t"
:desc "Select Test in Project" "t" #'dx:csharp/get-unit-test-in-project)))
#+END_SRC
** Python
- I do python development for Python3, so I need to set the flycheck python checker, as well as the interpreter, to be Python3
- Most of my python work is in scripts or ideas, so I don't need extensive testing utilities or anything like that
- I run my python code a LOT and thus need commands for sending bits or whole scripts into the REPL
#+BEGIN_SRC elisp
(after! python
(setq python-version-checked t)
(setq python-python-command "python3")
(setq python-shell-interpreter "python3")
(setq flycheck-python-pycompile-executable "python3")
(map! ; Python keybinds
:map python-mode-map
:localleader
:desc "Start python minor" "c" #'run-python
:desc "Format buffer" "=" #'py-yapf-buffer
(:prefix "s"
:desc "Send region REPL" "r" #'python-shell-send-region
:desc "Send buffer" "b" #'python-shell-send-buffer
:desc "Send function" "f" #'python-shell-send-defun)))
#+END_SRC
** TypeScript
- Typescript (in my opinion) should be indented by 2
- Setup the LSP server on the lsp-language-id-config in case it hasn't already
#+BEGIN_SRC elisp
(after! typescript-mode
(setq typescript-indent-level 2)
(setq tide-format-options '(:indentSize 2 :tabSize 2))
(after! lsp
(cl-pushnew '(typescript-mode . "typescript") lsp-language-id-configuration :key #'car)
(lsp-register-client
(make-lsp-client
:new-connection (lsp-stdio-connection "typescript-language-server --stdio")
:major-modes '(typescript-mode)
:server-id 'typescript))))
#+END_SRC
** Haskell
#+BEGIN_SRC elisp
(after! (haskell-mode dante)
(setq dante-repl-command-line '("stack" "ghci")))
#+END_SRC
** FSharp
#+BEGIN_SRC elisp
(after! fsharp
(setq inferior-fsharp-program "dotnet fsi --readline"))
#+END_SRC
** Org
Org configuration to maximise org workflow.
*** Org variables
Setup the agenda-files and the org-directory.
#+BEGIN_SRC elisp
(after! org
(setq org-directory "~/Text"
org-agenda-files '("~/Text/")))
#+END_SRC
*** Org keymap
- I like using org-export often, so bind it to a primary bind.
- Narrowing is important and I use it often, so bind that to a prefix
- Loading latex fragments is nice
#+BEGIN_SRC elisp
(map! ; Org keybinds
:after org
:map org-mode-map
:localleader
:desc "Org dispatch" "e" #'org-export-dispatch
:desc "Org LaTeX" "E" #'org-latex-export-as-latex
:desc "Load fragments" "L" #'org-latex-preview
(:prefix ("N" . "narrow")
:desc "Narrow to subtree" "n" #'org-narrow-to-subtree
:desc "Go out of narrow" "o" #'widen))
#+END_SRC
* Key-map
General keymap
** Personal
- Prefix "SPC m" (rebound from local-leader) that will hold personal keybinds
for functions that I like using
- Mostly opening directories I use a lot or doing custom stuff that I can't
really put in anything in particular
#+BEGIN_SRC elisp
(map!
:leader
:prefix ("m" . "personal") ; Personal
:desc "Open Reviews" "a" #'(lambda () (interactive) (doom-project-find-file "~/Text/Reviews"))
:desc "Open books" "b" #'(lambda () (interactive) (dired (concat org-directory "/Books"))); I like my books
:desc "Open school dir" "s" #'(lambda () (interactive) (dired (expand-file-name "~/School")))
:desc "Open notes" "n" #'(lambda () (interactive) (dired org-directory))
:desc "Open code" "c" #'(lambda () (interactive) (dired (expand-file-name "~/Code")))
:desc "Open weather" "w" #'dx:weather
:desc "Change theme" "t" #'dx:themes/set-new-theme ; From my own collection
:desc "Generate template" "g" #'+gentemplate/generate-template ; From my own collection
(:after pdf-view
:desc "Goto page on pdf" "p" #'pdf-view-goto-page)
:desc "Reload emacs" "r" #'dx:reload) ; Reload is necessary
#+END_SRC
** Counsel
- Counsel keybind config
- Mostly just convenience stuff that happens to use counsel
#+BEGIN_SRC elisp
(map!
:leader
:after counsel ; Counsel or ivy
:desc "M-x" "<SPC>" #'counsel-M-x ; Redefine as M-x because of my muscle memory with spacemacs
(:prefix ("s" . "search")
:desc "RipGrep!" "r" #'counsel-rg ; Ripgrep is faster than Ag in most cases and makes me feel cool
:desc "Search Tags" "t" #'counsel-etags-find-tag)); is quicker to do than <SPC>/b, for something that is done so often
#+END_SRC
** Window
- Keybinds to do with windows
- SPC wc < SPC wd
- Some ace-window config in the window keybind prefix
#+BEGIN_SRC elisp
(map!
:leader
:prefix ("w" . "window") ; Windows
:desc "Close window" "d" #'+workspace/close-window-or-workspace ; is slightly closer together than <SPC>wc
:desc "Switch window" "W" #'ace-window ; is also used in spacemacs so I'd rather use this
:desc "Swap windows" "S" #'ace-swap-window) ; allows me to switch windows more efficiently than before, better than just motions
#+END_SRC
** Code
*** Narrow handlers
- Toggles narrow to function by checking a variable
#+BEGIN_SRC elisp
(setq dx:narrow/narrow-state 0)
(defun dx:narrow/toggle-narrow-state ()
(if (= dx:narrow/narrow-state 1)
(setq dx:narrow/narrow-state 0)
(setq dx:narrow/narrow-state 1)))
(add-hook 'post-command-hook #'dx:narrow/toggle-narrow-state)
(defun dx:narrow/toggle-narrow ()
(interactive)
(if (= dx:narrow/narrow-state 1)
(narrow-to-defun)
(widen)))
#+END_SRC
*** Keybinds
- Some keybinds for the code prefix which help me with coding or working with
code, particularly LSP
#+BEGIN_SRC elisp
(map!
:leader
:prefix ("c" . "code") ; Code
:desc "Fold all in level" "f" #'hs-hide-level
:desc "Compile via make" "C" #'+make/run
:desc "Undo tree" "u" #'undo-tree-visualize
:desc "Narrow to function" "n" #'dx:narrow/toggle-narrow
(:after format-all
:desc "Format code" "=" #'format-all-buffer)
(:after lsp
:desc "Execute action" "a" #'lsp-execute-code-action)
(:after dap-mode
:desc "Debug hydra" "h" #'dap-hydra))
#+END_SRC
** Projectile
- Projectile config, for leader and for project prefix
#+BEGIN_SRC elisp
(map!
:leader
:after projectile
:desc "Switch to p-buffer" ">" #'projectile-switch-to-buffer ; Opposing <SPC>< which counsel's all buffers
(:prefix ("p" . "project")
:desc "Regen tags" "g" #'projectile-regenerate-tags
:desc "Open project files" "f" #'projectile-find-file))
#+END_SRC
** Fonts
- Fonts keybinds (prefix "z") for messing with fonts temp on a buffer
- Really useful when I need to zoom into something for whatever reason
#+BEGIN_SRC elisp
(map!
:leader
:prefix ("z" . "font") ; Fonts
:desc "Increase font" "+" #'doom/increase-font-size
:desc "Decrease font" "-" #'doom/decrease-font-size
:desc "Adjust font" "z" #'text-scale-adjust)
#+END_SRC
** Frames
- Keybinds for frame manipulation:
- Generate new frames from current buffer
- Generate new frames from a specific buffer
- Delete frames
- Switch frames
#+BEGIN_SRC elisp
(map!
:leader
:prefix ("F" . "frame") ; Frames
:desc "Kill frame" "d" #'delete-frame
:desc "Current buffer frame" "m" #'make-frame
:desc "Choose Buffer frame" "n" #'display-buffer-other-frame
:desc "Switch frames" "o" #'other-frame)
#+END_SRC
** Other
*** Leader
- Miscellaneous leader bindings that don't really fit into any particular item
#+BEGIN_SRC elisp
(map!
:leader
:desc "Shell command" "!" #'async-shell-command ; Better than M-!
(:prefix ("b" . "buffers") ; Buffers
:desc "Close buffer" "d" #'doom/kill-this-buffer-in-all-windows)
(:prefix ("f" . "files")
:desc "Open dotfiles" "p" #'(lambda () (interactive) (doom-project-find-file "~/Dotfiles")))
(:prefix ("o" . "open")
:after org
:desc "Calendar" "c" #'=calendar)
(:prefix ("n" . "notes")
:desc "Open notes in dired" "-" #'(lambda () (interactive) (dired org-directory))))
#+END_SRC
*** Non-leader
#+BEGIN_SRC elisp
(map!
:n "gk" #'evil-backward-section-begin
:n "gK" #'evil-backward-section-end
:n "gj" #'evil-forward-section-begin
:n "gJ" #'evil-forward-section-end)
#+END_SRC
|