Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/michaelneuper/doom

My literate doom emacs config
https://github.com/michaelneuper/doom

doom-emacs emacs

Last synced: 27 days ago
JSON representation

My literate doom emacs config

Awesome Lists containing this project

README

        

#+title: Doom Emacs Config
#+author: Michael Neuper

This is my literate doom emacs config.
[[Basic]] sets up some basic emacs and doom configurations.
[[Doom Modules]] contains the configuration for doom's modules ordered by the same order as in =init.el=.
This section also contains configuration for other packages in =packages.el= under headings that seem appropriate.

* Contents :toc:
- [[#basic][Basic]]
- [[#defaults][Defaults]]
- [[#visual-enchancements][Visual Enchancements]]
- [[#doom-modules][Doom Modules]]
- [[#completion][:completion]]
- [[#ui][:ui]]
- [[#emacs][:emacs]]
- [[#tools][:tools]]
- [[#lang][:lang]]

* Basic
** Defaults
*** Speed
Make emacs faster.
#+begin_src emacs-lisp
(use-package! gcmh
:init
(setq gcmh-idle-delay 5
gcmh-high-cons-threshold (* 256 1024 1024)) ; 256MB during idle
:config
(gcmh-mode 1))

(setq gc-cons-threshold 200000000) ; previous 33554432
#+end_src
*** Basic
#+begin_src emacs-lisp
;; credentials
(setq user-full-name "Michael Neuper"
user-mail-address "[email protected]")

;; autosave and backup
(setq auto-save-default t
make-backup-files t)

;; kill emacs without confiming
(setq confirm-kill-emacs nil)

;; remap from SPC m to SPC l
(setq doom-localleader-key "SPC l"
doom-localleader-alt-key "M-SPC l")
#+end_src
*** macOS
Set the modifier keys for macos:
- =command=: =meta=
- =right option=: =super=
#+begin_src emacs-lisp
(if (featurep :system 'macos)
(setq mac-command-modifier 'meta
mac-option-modifier 'none
mac-right-option-modifier 'super))
#+end_src
** Visual Enchancements
*** Theme & Fonts
#+begin_src emacs-lisp
(setq doom-theme 'doom-gruvbox)

(setq doom-font (font-spec :family "SF Mono" :size 15.5)
doom-serif-font (font-spec :family "ETBembo" :size 15.5)
doom-variable-pitch-font (font-spec :family "ETBembo" :size 20)
doom-emoji-font (font-spec :family "Apple Color Emoji" :size 15.5)
doom-symbol-font (font-spec :family "Cascadia Code" :size 15.5))
#+end_src
*** Lines
Enable relative line numbers and make their slant normal (not italic).
#+begin_src emacs-lisp
(setq display-line-numbers-type 'relative) ;; TODO change to 'visual in org-mode

(add-hook! display-line-numbers-mode
(custom-set-faces!
'(line-number :slant normal)
'(line-number-current-line :slant normal)))
#+end_src

Disable highlighting of the current line.
#+begin_src emacs-lisp
(setq global-hl-line-modes nil)
#+end_src

Display a fill indicator at 80 characters in =prog-mode=.
#+begin_src emacs-lisp
(setq display-fill-column-indicator-column 80)
(add-hook 'prog-mode-hook #'display-fill-column-indicator-mode)
#+end_src

Smooth scrolling.
Run ~(package-vc-install '(ultra-scroll :vc-backend Git :url "https://github.com/jdtsmith/ultra-scroll"))~ in =*scratch*= buffer.
#+begin_src emacs-lisp
(use-package! ultra-scroll
:init
(setq scroll-conservatively 101 ; important!
scroll-margin 0)
:config
(ultra-scroll-mode 1))
#+end_src
*** Window
Start emacs in a 100x40 window.
#+begin_src emacs-lisp
(add-to-list 'default-frame-alist '(width . 100))
(add-to-list 'default-frame-alist '(height . 40))
#+end_src

Format the title.
Copied from [[https://hieuphay.com/doom-emacs-config/#some-good-defaults][https://hieuphay.com/doom-emacs-config/#some-good-defaults]].
#+begin_src emacs-lisp
(setq frame-title-format
'(""
(:eval
(if (s-contains-p org-roam-directory (or buffer-file-name ""))
(replace-regexp-in-string
".*/[0-9]*-?" "☰ "
(subst-char-in-string ?_ ? buffer-file-name))
"%b"))
(:eval
(let ((project-name (projectile-project-name)))
(unless (string= "-" project-name)
(format (if (buffer-modified-p) " ◉ %s" "  ●  %s") project-name))))))
#+end_src
* Doom Modules
** :completion
*** corfu
Disable corfu's auto-popups and preselect the first candidate.
#+begin_src emacs-lisp
(after! corfu
(setq corfu-auto nil
corfu-preselect 'first
+corfu-want-tab-prefer-expand-snippets t))
#+end_src
*** other
**** copilot
Add keybindings for [[https:https://github.com/copilot-emacs/copilot.el][copilot]] and [[https://github.com/chep/copilot-chat.el][copilot-chat]] with [[kbd:][ e]] prefix.
#+begin_src emacs-lisp
(after! (evil copilot)
(evil-define-key 'insert 'global (kbd "") 'copilot-accept-completion))

(map! :leader
(:prefix ("e" . "copilot")
:desc "Enable Copilot Mode"
"c" #'copilot-mode
:desc "Display Chat Window"
"d" #'copilot-chat-display
:desc "Explain Selected Code"
"e" #'copilot-chat-explain
:desc "Review Selected Code"
"r" #'copilot-chat-review
:desc "Fix Selected Code"
"f" #'copilot-chat-fix
:desc "Optimize Selected Code"
"o" #'copilot-chat-optimize
:desc "Write Test for Code"
"t" #'copilot-chat-test
:desc "Add Current Buffer"
"a" #'copilot-chat-add-current-buffer
:desc "Document Selected Code"
"D" #'copilot-chat-doc
:desc "Reset Chat History"
"R" #'copilot-chat-reset
:desc "Remove Current Buffer"
"x" #'copilot-chat-del-current-buffer))
#+end_src
** :ui
*** doom-dashboard
Customise the dashboard.
Copied from [[https://discourse.doomemacs.org/t/how-to-change-your-splash-screen/57][https://discourse.doomemacs.org/t/how-to-change-your-splash-screen/57]].
#+begin_src emacs-lisp
(remove-hook '+doom-dashboard-functions #'doom-dashboard-widget-shortmenu)

(add-hook! '+doom-dashboard-functions :append
(insert "\n" (+doom-dashboard--center +doom-dashboard--width "Welcome back to Emacs!"))
(setq mode-line-format nil)
(hl-line-mode 0)
(read-only-mode +1))

(setq-hook! '+doom-dashboard-mode-hook evil-normal-state-cursor (list nil))

(defun my-weebery-is-always-greater ()
(let* ((banner '("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀"
"⢸⠉⣹⠋⠉⢉⡟⢩⢋⠋⣽⡻⠭⢽⢉⠯⠭⠭⠭⢽⡍⢹⡍⠙⣯⠉⠉⠉⠉⠉⣿⢫⠉⠉⠉⢉⡟⠉⢿⢹⠉⢉⣉⢿⡝⡉⢩⢿⣻⢍⠉⠉⠩⢹⣟⡏⠉⠹⡉⢻⡍⡇"
"⢸⢠⢹⠀⠀⢸⠁⣼⠀⣼⡝⠀⠀⢸⠘⠀⠀⠀⠀⠈⢿⠀⡟⡄⠹⣣⠀⠀⠐⠀⢸⡘⡄⣤⠀⡼⠁⠀⢺⡘⠉⠀⠀⠀⠫⣪⣌⡌⢳⡻⣦⠀⠀⢃⡽⡼⡀⠀⢣⢸⠸⡇"
"⢸⡸⢸⠀⠀⣿⠀⣇⢠⡿⠀⠀⠀⠸⡇⠀⠀⠀⠀⠀⠘⢇⠸⠘⡀⠻⣇⠀⠀⠄⠀⡇⢣⢛⠀⡇⠀⠀⣸⠇⠀⠀⠀⠀⠀⠘⠄⢻⡀⠻⣻⣧⠀⠀⠃⢧⡇⠀⢸⢸⡇⡇"
"⢸⡇⢸⣠⠀⣿⢠⣿⡾⠁⠀⢀⡀⠤⢇⣀⣐⣀⠀⠤⢀⠈⠢⡡⡈⢦⡙⣷⡀⠀⠀⢿⠈⢻⣡⠁⠀⢀⠏⠀⠀⠀⢀⠀⠄⣀⣐⣀⣙⠢⡌⣻⣷⡀⢹⢸⡅⠀⢸⠸⡇⡇"
"⢸⡇⢸⣟⠀⢿⢸⡿⠀⣀⣶⣷⣾⡿⠿⣿⣿⣿⣿⣿⣶⣬⡀⠐⠰⣄⠙⠪⣻⣦⡀⠘⣧⠀⠙⠄⠀⠀⠀⠀⠀⣨⣴⣾⣿⠿⣿⣿⣿⣿⣿⣶⣯⣿⣼⢼⡇⠀⢸⡇⡇⠇"
"⢸⢧⠀⣿⡅⢸⣼⡷⣾⣿⡟⠋⣿⠓⢲⣿⣿⣿⡟⠙⣿⠛⢯⡳⡀⠈⠓⠄⡈⠚⠿⣧⣌⢧⠀⠀⠀⠀⠀⣠⣺⠟⢫⡿⠓⢺⣿⣿⣿⠏⠙⣏⠛⣿⣿⣾⡇⢀⡿⢠⠀⡇"
"⢸⢸⠀⢹⣷⡀⢿⡁⠀⠻⣇⠀⣇⠀⠘⣿⣿⡿⠁⠐⣉⡀⠀⠁⠀⠀⠀⠀⠀⠀⠀⠀⠉⠓⠳⠄⠀⠀⠀⠀⠋⠀⠘⡇⠀⠸⣿⣿⠟⠀⢈⣉⢠⡿⠁⣼⠁⣼⠃⣼⠀⡇"
"⢸⠸⣀⠈⣯⢳⡘⣇⠀⠀⠈⡂⣜⣆⡀⠀⠀⢀⣀⡴⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢽⣆⣀⠀⠀⠀⣀⣜⠕⡊⠀⣸⠇⣼⡟⢠⠏⠀⡇"
"⢸⠀⡟⠀⢸⡆⢹⡜⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠋⣾⡏⡇⡎⡇⠀⡇"
"⢸⠀⢃⡆⠀⢿⡄⠑⢽⣄⠀⠀⠀⢀⠂⠠⢁⠈⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠄⡐⢀⠂⠀⠀⣠⣮⡟⢹⣯⣸⣱⠁⠀⡇"
"⠈⠉⠉⠉⠉⠉⠉⠉⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠉⠉⠉⠉⠉⠉⠁"))
(longest-line (apply #'max (mapcar #'length banner))))
(put-text-property
(point)
(dolist (line banner (point))
(insert (+doom-dashboard--center
+doom-dashboard--width
(concat line (make-string (max 0 (- longest-line (length line))) 32)))
"\n"))
'face 'doom-dashboard-banner)))

(setq +doom-dashboard-ascii-banner-fn #'my-weebery-is-always-greater)
#+end_src
*** modeline
Customise the modeline according to [[https://github.com/seagle0128/doom-modeline?tab=readme-ov-file#customize][https://github.com/seagle0128/doom-modeline?tab=readme-ov-file#customize]].
#+begin_src emacs-lisp
(after! doom-modeline
(setq doom-modeline-buffer-file-name-style 'file-name
doom-modeline-always-show-macro-register t
doom-modeline-enable-word-count nil
doom-modeline-buffer-encoding t
doom-modeline-major-mode-icon t
doom-modeline-bar-width 0
doom-modeline-height 25
doom-modeline-modal nil))
#+end_src
*** zen
Enable =mixed-pitch-mode= in org files and scale =doom-variable-pitch-font=.
Copied from [[https://discourse.doomemacs.org/t/cant-size-doom-variable-pitch-font/4572/2][https://discourse.doomemacs.org/t/cant-size-doom-variable-pitch-font/4572/2]].
#+begin_src emacs-lisp
(add-hook! 'org-mode-hook #'mixed-pitch-mode)

(after! mixed-pitch
(setq mixed-pitch-set-height t)
(setq variable-pitch-serif-font doom-variable-pitch-font)
(set-face-attribute 'variable-pitch nil :height 1.2))
#+end_src
*** other
**** spacious-padding
Add padding to emacs frames and windows with [[doom-package:spacious-padding][spacious-padding]].
See [[https://protesilaos.com/emacs/spacious-padding]] for configuration options.
#+begin_src emacs-lisp
(use-package! spacious-padding
:ensure t
:config
(setq spacious-padding-widths
'( :internal-border-width 15
:header-line-width 4
:mode-line-width 4
:tab-width 4
:right-divider-width 30
:scroll-bar-width 8
:fringe-width 0))
(spacious-padding-mode 1))
#+end_src
** :emacs
*** dired
Set =quick-access-entries= for =dirvish=.
#+begin_src emacs-lisp
(after! dirvish
(setq! dirvish-quick-access-entries
`(("h" "~/" "Home")
("e" ,doom-user-dir "Doom config")
("c" "~/Developer/" "Code")
("d" "~/Downloads/" "Downloads")
("g" "~/GitHub/" "GitHub")
("t" "~/.Trash/" "Trash"))))
#+end_src
** :tools
*** lsp
Improve =eglot= performance.
*NOTE*: Requires building [[https://github.com/blahgeek/emacs-lsp-booster?tab=readme-ov-file#obtain-or-build-emacs-lsp-booster][emacs-lsp-booster]].
#+begin_src emacs-lisp
(use-package! eglot-booster
:after eglot
:config (eglot-booster-mode))
#+end_src
** :lang
*** cc
Set indentation level for =cc-mode= to 2.
#+begin_src emacs-lisp
(after! cc-mode
(setq c-basic-offset 2))
#+end_src
*** java
Set indentation level for =java-mode= to 2.
#+begin_src emacs-lisp
(after! java-mode
(setq c-basic-offset 2))
#+end_src
*** latex
#+begin_src emacs-lisp
; use cdlatex completion instead of yasnippet
(map! :map cdlatex-mode-map
:i "TAB" #'cdlatex-tab)

(map! :after latex
:map cdlatex-mode-map
:localleader
:desc "Insert math symbol"
"i" #'cdlatex-math-symbol
:desc "Begin environment"
"e" #'cdlatex-environment)
#+end_src
*** org
**** org-mode
Set some org variables.
#+begin_src emacs-lisp
(setq org-directory "~/Documents/Org"
org-use-property-inheritance t ; fix weird issue with src blocks
org-startup-with-inline-images t
org-hide-emphasis-markers t
org-edit-src-content-indentation 0
org-startup-with-latex-preview t)
#+end_src

Scale org headings.
#+begin_src emacs-lisp
(after! org
(custom-set-faces!
`((org-document-title)
:foreground ,(face-attribute 'org-document-title :foreground)
:height 1.3 :weight bold)
`((org-level-1)
:foreground ,(face-attribute 'outline-1 :foreground)
:height 1.1 :weight medium)
`((org-level-2)
:foreground ,(face-attribute 'outline-2 :foreground)
:weight medium)
`((org-level-3)
:foreground ,(face-attribute 'outline-3 :foreground)
:weight medium)
`((org-level-4)
:foreground ,(face-attribute 'outline-4 :foreground)
:weight medium)
`((org-level-5)
:foreground ,(face-attribute 'outline-5 :foreground)
:weight medium)))
#+end_src

Setup LaTeX previews in =org-mode=.
See [[https://abode.karthinks.com/org-latex-preview/][https://abode.karthinks.com/org-latex-preview/]] for configuration.
#+begin_src emacs-lisp
(after! org
(add-to-list 'org-latex-packages-alist '("" "amsmath" t))
(add-to-list 'org-latex-packages-alist '("" "amssymb" t))
(add-to-list 'org-latex-packages-alist '("" "mathtools" t))
(add-to-list 'org-latex-packages-alist '("" "mathrsfs" t)))

(use-package! org-latex-preview
:after org
:config
(plist-put org-latex-preview-appearance-options
:page-width 0.8)
(add-hook 'org-mode-hook 'org-latex-preview-auto-mode)
(setq org-latex-preview-auto-ignored-commands
'(next-line previous-line mwheel-scroll
scroll-up-command scroll-down-command))
(setq org-latex-preview-numbered t)
(setq org-latex-preview-live t)
(setq org-latex-preview-live-debounce 0.25))
#+end_src
**** eye candy
=org-modern= config modified from [[https://sophiebos.io/posts/beautifying-emacs-org-mode/][https://sophiebos.io/posts/beautifying-emacs-org-mode/]].
#+begin_src emacs-lisp
(use-package! org-modern
:after org
:config
(setq
org-auto-align-tags t
org-tags-column 0
org-fold-catch-invisible-edits 'show-and-error
org-special-ctrl-a/e t
org-insert-heading-respect-content t

;; agenda
org-agenda-tags-column 0
org-agenda-block-separator ?─
org-agenda-time-grid
'((daily today require-timed)
(800 1000 1200 1400 1600 1800 2000)
" ┄┄┄┄┄ " "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄")
org-agenda-current-time-string
"⭠ now ─────────────────────────────────────────────────")

(global-org-modern-mode))
#+end_src
**** org-roam
Set up =org-roam= and =org-roam-ui= along with their keybindings that have the [[kbd:][ r]] prefix.
#+begin_src emacs-lisp
(use-package! org-roam
:defer t
:config
(setq org-roam-directory (file-truename "~/Notes")
org-roam-db-location (file-truename "~/Notes/org-roam.db")
org-attach-id-dir "assets/")
(org-roam-db-autosync-enable))

(use-package! websocket
:after org-roam)

(use-package! org-roam-ui
:after org-roam
:config
(setq org-roam-ui-sync-theme t
org-roam-ui-follow t
org-roam-ui-update-on-save t
org-roam-ui-open-on-start t))

(map! :map evil-org-mode-map
:leader
(:prefix ("r")
:desc "Insert node"
"i" #'org-roam-node-insert
:desc "Find node"
"f" #'org-roam-node-find
:desc "Capture to node"
"c" #'org-roam-capture
:desc "Toggle roam buffer"
"b" #'org-roam-buffer-toggle
:desc "Open random note"
"r" #'org-roam-node-random
:desc "Visit node"
"v" #'org-roam-node-visit
:desc "Open ORUI"
"u" #'org-roam-ui-open))
#+end_src
*** python
Requires [[doom-module::lang python +lsp][eglot]]
*NOTE*: Requires =pyright= to be installed.
Install with ~npm install -g pyright~.
#+begin_src emacs-lisp
(after! eglot
(add-to-list 'eglot-server-programs '(python-mode . ("pyright-langserver" "--stdio"))))

(add-hook! python-mode
(setq python-shell-interpreter "python3.12"
doom-modeline-env-python-executable "python3.12"))
#+end_src