#+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. * Initial setup ** Doom Variables - Set the doom localleader to "," because it's faster - Using the font [[https://sourcefoundry.org/hack/][Hack]] #+BEGIN_SRC elisp (after! core-keybinds (map! :leader "," nil) (setq doom-localleader-key "SPC ,") (setq doom-theme 'doom-gruvbox) (setq doom-font (font-spec :family "Hack" :size 15))) #+END_SRC ** Other variables 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 #+BEGIN_SRC elisp (setq completion-ignore-case t) (setq truncate-lines t) (setq display-line-numbers-type t) (setq bookmark-default-file (expand-file-name (concat doom-private-dir "bookmarks"))) (setq-default frame-title-format '("%b - Emacs")) (add-to-list 'default-frame-alist '(alpha . 95)) (cl-pushnew '("Libgen" "http://gen.lib.rus.ec/search.php?req=%s") +lookup-provider-url-alist :key #'car :test 'string=) #+END_SRC ** HACK: Loading org mode For some reason, currently, the org mode keybinds aren't working. So reload the file again until the issue is fixed. #+BEGIN_SRC elisp (load "~/.emacs.d/modules/lang/org/config.el") #+END_SRC * 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 - *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 ** 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/SplashScreens/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) ("Jump to bookmark" :icon (all-the-icons-octicon "bookmark" :face 'font-lock-keyword-face) :action bookmark-jump) ("Open project" :icon (all-the-icons-material "folder" :face 'font-lock-keyword-face) :action projectile-switch-project))) #+END_SRC ** 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=) (setq projectile-tags-command "ctags -e -R --exclude=dist --exclude=.ccls --exclude=.ccls-cache")) #+END_SRC ** Prettify symbols Configuration for the module (pretty-code). *** Setup symbols Some symbols aren't present in the current doom version, or my fonts are screwing up, so I wrote them here. Maybe a bit of a bandage over broken glass, but at least it's something. #+BEGIN_SRC elisp (setq +pretty-code-symbols '(:name "»" :src_block "»" :src_block_end "«" :quote "“" :quote_end "”" :lambda "λ" :def "ƒ" :composition "∘" :map "↦" :null "∅" :true "𝕋" :false "𝔽" :int "ℤ" :float "ℝ" :str "𝕊" :bool "𝔹" :not "¬" :in "∈" :not-in "∉" :and "∧" :or "∨" :for "∀" :some "∃" :return "⟼" :yield "⟻" :tuple "⨂" :pipe "|" :dot "•")) #+END_SRC The 'x' symbol in the =+pretty-code-fira-code-font-ligatures= is annoying, and unneeded. So I remove it. #+BEGIN_SRC elisp (assoc-delete-all "x" +pretty-code-fira-code-font-ligatures #'string=) #+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 added support for it as well. #+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 ** Calc *** Configuration #+BEGIN_SRC elisp (use-package! calc :config (setq calc-angle-mode 'rad) (map! :leader :desc "Calc" ":" #'calc)) #+END_SRC ** Dired and ranger #+BEGIN_SRC elisp (after! ranger (setq ranger-cleanup-eagerly t) (setq ranger-show-hidden t)) #+END_SRC ** Compilation Add keybind to recompile (inside the buffer) #+BEGIN_SRC elisp (map! (:map 'compilation-mode-map :n "u" #'recompile)) #+END_SRC ** Company #+BEGIN_SRC elisp (add-hook 'company-mode-hook #'(lambda () (setq company-frontends '(company-preview-frontend company-pseudo-tooltip-frontend)))) #+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 . +)))) (setq c-default-style "user")) #+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 ** Org Org configuration to maximise org workflow. *** Org variables Setup the agenda-files and the org-directory. #+BEGIN_SRC elisp (after! org (add-hook 'org-mode-hook #'visual-line-mode) (add-hook 'org-mode-hook #'org-toggle-latex-fragment) (setq org-directory "~/Text" org-agenda-files '("~/Text/") org-src-window-setup 'split-window-right org-superstar-headline-bullets-list '("◉" "‣" "⧈" "⬠") org-log-repeat 'note)) #+END_SRC *** Fragtog #+BEGIN_SRC elisp (use-package! org-fragtog :config (add-hook 'org-mode-hook #'org-fragtog-mode)) #+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 *** Org keymap - I like using org-export often, so bind it to a primary bind. - 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) #+END_SRC ** Haskell #+BEGIN_SRC elisp (map! :after haskell-mode :map haskell-mode-map :localleader "l" #'haskell-process-load-file "r" #'haskell-process-reload "o" #'haskell-process-start) #+END_SRC ** Sxhkd Define a major-mode for sxhkd config files. #+BEGIN_SRC elisp (define-generic-mode sxhkd-mode '(?#) '("alt" "Escape" "super" "bspc" "ctrl" "space" "shift" "hyper" "XF86*") '("{" "}") '("sxhkdrc") nil "Simple mode for sxhkdrc files.") #+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 books" "b" #'(lambda () (interactive) (dired (concat org-directory "/Books"))); I like my books :desc "Convert auto-fill" "f" #'dx:org/fill-to-long-lines :desc "Change theme" "t" #'dx:themes/set-new-theme ; From my own collection :desc "Generate template" "g" #'+gentemplate/generate-template) ; From my own collection #+END_SRC ** Counsel - Counsel keybind config - Mostly just convenience stuff that happens to use counsel #+BEGIN_SRC elisp (map! :leader (: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 /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 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 - 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 "Compile" "c" #'compile :desc "Recompile" "C" #'recompile :desc "Compile via make" "m" #'+make/run :desc "Undo tree" "u" #'undo-tree-visualize :desc "Narrow to function" "n" #'+narrow/toggle-narrow (:after format-all :desc "Format code" "=" #'format-all-buffer) (:after lsp :desc "Format code lsp" "f" #'+default/lsp-format-region-or-buffer :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 < 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 ** Remaps Adding a new configuration option. Remapping functions that other modules set to default functions. #+BEGIN_SRC elisp (define-key! [remap compile] #'compile) #+END_SRC ** Other *** Leader Miscellaneous leader bindings that don't really fit into any particular item #+BEGIN_SRC elisp (map! :leader :desc "M-x" "SPC" #'execute-extended-command ; Redefine as M-x because of my muscle memory with spacemacs :desc "Shell command" "!" #'async-shell-command ; Better than M-! (:prefix ("b" . "buffers") :desc "Close buffer" "d" #'doom/kill-this-buffer-in-all-windows) (:prefix ("f" . "files") :desc "Recent files" "r" #'counsel-recentf :desc "Find in dotfiles" "p" #'(lambda () (interactive) (doom-project-find-file "~/Dotfiles"))) (:prefix ("n" . "notes") :desc "Open notes in dired" "-" #'(lambda () (interactive) (dired org-directory)))) #+END_SRC *** Non-leader Non-leader bindings for text-based commands. #+BEGIN_SRC elisp (map! :n "TAB" #'evil-jump-item :n "M-v" #'dx:newline :n "M-V" #'(lambda () (interactive) (dx:newline 1)) :v "M-c" #'count-words-region :n "M-s" #'occur) #+END_SRC