Skip to content

hegde-atri/doom-emacs-config

Repository files navigation

Doom Emacs Config

Preface

Table of Contents

User Interface

General

;;; $DOOMDIR/config.el -*- lexical-binding: t; -*-
(setq user-full-name "Atri Hegde"
      ;; I do not use emacs as my email client lol
      user-mail-address "atri@example.com")

Relative Line numbers.

(setq display-line-numbers-type 'relative)

Scroll off settings.

(setq scroll-margin 7)

(defvar my-zero-scroll-margin-modes
  '(Info-mode term-mode eshell-mode shell-mode erc-mode vterm-mode)
  "List of major modes where scroll-margin should be set to 0.")

(defun my-set-scroll-margin ()
  "Set scroll-margin based on the current major mode."
  (setq-local scroll-margin (if (apply #'derived-mode-p my-zero-scroll-margin-modes) 0 7)))

(add-hook 'after-change-major-mode-hook #'my-set-scroll-margin)

Shell settings.

;; (setq shell-file-name "/bin/bash")
;; (setq-default shell-file-name "/bin/bash")
;; (setenv "SHELL" shell-file-name)

;; (require 'vterm)
;; (setq vterm-shell "/usr/bin/nu")

Manipulate windows easier.

(package! transpose-frame)

Evil mode better scroll

(evil-global-set-key 'motion "j" 'evil-next-visual-line)
(evil-global-set-key 'motion "k" 'evil-previous-visual-line)

Evil fine undo, which-key settings

(setq evil-want-fine-undo t
      truncate-string-ellipsis ""
      which-key-idle-delay 0.5)

;; which key prompt customisation
(setq which-key-allow-multiple-replacements t)
(after! which-key
  (pushnew!
   which-key-replacement-alist
   '(("" . "\\`+?evil[-:]?\\(?:a-\\)?\\(.*\\)") . (nil . "\\1"))
   '(("\\`g s" . "\\`evilem--?motion-\\(.*\\)") . (nil . "\\1"))
   ))

Doom Fonts

(setq doom-font (font-spec :family "JetBrains Mono" :size 15 :weight 'regular)
      doom-variable-pitch-font (font-spec :family "Iosevka Aile" :size 12)
      doom-big-font (font-spec :family "JetBrains Mono" :size 24))

(after! doom-themes
  (setq doom-themes-enable-bold t
        doom-themes-enable-italic t))

(custom-set-faces!
  '(font-lock-comment-face :slant italic))

Doom theme

;; (setq doom-theme 'doom-palenight)
(setq doom-theme 'doom-rose-pine-dawn)

Doom modeline

(after! doom-modeline
  (display-battery-mode t)
  (setq doom-modeline-major-mode-icon t))

Doom Dashboard

(setq fancy-splash-image
      (concat doom-user-dir "splash/" "i-am-doom-cropped.png"))

Remove existing menu.

(remove-hook '+doom-dashboard-functions #'doom-dashboard-widget-shortmenu)

Add custom footer.

(add-hook! '+doom-dashboard-functions :append
  (insert "\n" (+doom-dashboard--center +doom-dashboard--width "Powered by Emacs!")))

Custom menu.

;; (add-to-list '+doom-dashboard-menu-sections
;;              '("Add journal entry"
;;                :icon (all-the-icons-octicon "calendar" :face 'doom-dashboard-menu-title)
;;                :when (featurep! :lang org +journal)
;;                :face (:inherit (doom-dashboard-menu-title bold))
;;                :action org-journal-new-entry))

Fix Transparent image on transparent bg.

(defun my-load-doom-theme (frame)
  (select-frame frame)
  (load-theme doom-theme t))

(if (daemonp)
    (add-hook 'after-make-frame-functions #'my-load-doom-theme)
  (load-theme doom-theme t))

Corfu Completion

Use RET to accept completion.

(setq +corfu-want-ret-to-confirm t)
(setq corfu-preselect 'first)

Keybinds

Unbind SPC w c as it is easy to misclick

(map! :leader "w c" nil)

Bind SPC b f to format buffer using LSP.

(map! :leader
      (:prefix ("b" . "buffer")
       :desc "Format buffer" "f" #'lsp-format-buffer))

Bind SPC SPC to save buffer.

(map! :leader
      :desc "Save buffer" "SPC" #'save-buffer)
(map! :leader
      (:prefix ("=" . "open config")
       :desc "Hyprland"      "h" #'(lambda () (interactive) (find-file "~/.config/hypr/hypr.org"))
       :desc "zshrc"         "z" #'(lambda () (interactive) (find-file "~/.zshrc"))
       :desc "eww"           "e" #'(lambda () (interactive) (find-file "~/.config/eww/eww.org"))
       :desc "nushell"       "n" #'(lambda () (interactive) (find-file "~/.config/nushell/nushell.org"))
       :desc "foot"          "f" #'(lambda () (interactive) (find-file "~/.config/foot/foot.org"))))

Org mode

General Settings

Inline latex previews

(package! org-fragtog)
;; Basic org configuration
(setq org-directory "~/org/")
(setq org-log-done 'time)
(setq org-hide-emphasis-markers t)
(setq org-startup-with-inline-images t)
(setq org-ellipsis "")
(setq org-superstar-headline-bullets-list '("" "" "" "" "" "" ""))

;; Function to enable doom-modeline word count
(defun enable-doom-modeline-word-count ()
  (setq-local doom-modeline-enable-word-count t))

(after! org
;; Add hooks
(add-hook 'org-mode-hook
          (lambda ()
            (enable-doom-modeline-word-count)
            (org-fragtog-mode)
            (svg-tag-mode)
            (+zen/toggle t)))

;; Font settings
(dolist (face '((org-level-1 . 1.2)
                (org-level-2 . 1.1)))
  (set-face-attribute (car face) nil :font "Iosevka Aile" :weight 'medium :height (cdr face)))
(set-face-attribute 'org-document-title nil :font "Iosevka Aile" :weight 'bold :height 1.3)
(set-face-attribute 'org-table nil :inherit 'fixed-pitch)
(set-face-attribute 'org-formula nil :inherit 'fixed-pitch)
(set-face-attribute 'org-code nil :inherit '(shadow fixed-pitch))
(set-face-attribute 'org-verbatim nil :inherit '(shadow fixed-pitch))
(set-face-attribute 'org-special-keyword nil :inherit '(font-lock-comment-face fixed-pitch))
(set-face-attribute 'org-meta-line nil :inherit '(font-lock-comment-face fixed-pitch))
(set-face-attribute 'org-checkbox nil :inherit 'fixed-pitch)
(set-face-attribute 'line-number nil :inherit 'fixed-pitch)
(set-face-attribute 'line-number-current-line nil :inherit 'fixed-pitch)

;; Todo keywords
(setq org-todo-keywords
      '((sequence "TODO(t)" "DOING(d)" "DONE")
        (sequence "IDEA(i)" "SCRIPTED(s)" "RECORDED(r)" "EDITED")
        (sequence "CLIENT(c)" "SCRIPTED(s)" "SENT")))

(setq org-todo-keyword-faces
      '(("IDEA" . (:foreground "#ffcc00" :bold t :weight bold))
        ("SCRIPTED" . (:foreground "#b8e4f9" :bold t :weight bold))
        ("RECORDED" . (:foreground "#ff84c9" :bold t :weight bold))
        ("CLIENT" . (:foreground "#ffcc00" :bold t :weight bold))
        ("EDITED" . (:foreground "gray65" :bold t :weight bold))
        ("SENT" . (:foreground "gray65" :bold t :weight bold))))

;; Latex settings
(setq org-pretty-entities t)
(plist-put org-format-latex-options :scale 1)
(setq org-highlight-latex-and-related '(latex))
(plist-put org-format-latex-options :background "Transparent")

;; org-roam configuration
(setq org-roam-directory "~/org/roam")
(setq org-roam-capture-templates
      '(("d" "default" plain "%?"
         :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org"
                            "#+title: ${title}\n#+date: %U\n#+startup: latexpreview\n")
         :unnarrowed t)
        ("m" "module" plain
         "\n* Module details\n\n- %^{Module code}\n- Semester: %^{Semester}\n\n* %?"
         :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org"
                            "#+title: ${title}\n#+startup: latexpreview\n")
         :unnarrowed t)
        ("b" "book notes" plain
         "\n* Source\n\n- Author: %^{Author}\n- Title: ${title}\n- Year: %^{Year}\n\n%?"
         :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org"
                            "#+title: ${title}\n#+startup: latexpreview\n")
         :unnarrowed t)))
(setq org-roam-dailies-capture-templates
      '(("d" "default" entry "* %<%H:%M>: %?"
         :ifnew (file+head "%<%Y-%m-%d>.org" "#+title: %<%Y-%m-%d>\n"))))

;; writeroom configuration
(setq +zen-text-scale 0.8)
(setq writeroom-width 100)
(setq writeroom-mode-line t)
)

Latex

;; Ensure packages are loaded only when needed
(with-eval-after-load 'ox-latex
  (add-to-list 'org-latex-classes
               '("org-plain-latex"
                 "\\documentclass{article}
[NO-DEFAULT-PACKAGES]
[PACKAGES]
[EXTRA]"
                 ("\\section{%s}" . "\\section*{%s}")
                 ("\\subsection{%s}" . "\\subsection*{%s}")
                 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
                 ("\\paragraph{%s}" . "\\paragraph*{%s}")
                 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))))

(with-eval-after-load 'ox-latex
  (add-to-list 'org-latex-classes
               '("report"
                 "\\documentclass{report}"
                 ("\\chapter{%s}" . "\\section*{%s}")
                 ("\\section{%s}" . "\\subsection*{%s}")
                 ("\\subsection{%s}" . "\\subsubsection*{%s}")
                 ("\\subsubsection{%s}" . "\\paragraph*{%s}")
                 ("\\paragraph{%s}" . "\\subparagraph*{%s}"))))

(setq TeX-view-program-selection '((output-pdf "PDF Tools"))
      TeX-view-program-list '(("PDF Tools" "TeX-pdf-tools-sync-view"))
      TeX-source-correlate-start-server t)

;; Optimize LaTeX export with minted for code highlighting
(setq org-latex-src-block-backend 'minted
      org-latex-packages-alist '(("" "minted"))
      org-latex-pdf-process
      '("pdflatex -shell-escape -interaction nonstopmode -output-directory build %f"))

(add-hook 'pdf-view-mode-hook 'auto-revert-mode)

;; Only load org-latex when needed
(with-eval-after-load 'org
  (require 'ox-latex))

org-auto-tangle

Add #+auto_tangle: t to the top of an org file to enable auto-tangle!

(package! org-auto-tangle)
(use-package! org-auto-tangle
  :defer t
  :hook (org-mode . org-auto-tangle-mode)
  :config
  (setq org-auto-tangle-default t)
)

Cool SVG tags

(package! svg-lib)
(package! svg-tag-mode)

SVG tags config

(require 'svg-tag-mode)
(defconst date-re "[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}")
(defconst time-re "[0-9]\\{2\\}:[0-9]\\{2\\}")
(defconst day-re "[A-Za-z]\\{3\\}")
(defconst day-time-re (format "\\(%s\\)? ?\\(%s\\)?" day-re time-re))

(defun svg-progress-percent (value)
  (save-match-data
   (svg-image (svg-lib-concat
               (svg-lib-progress-bar  (/ (string-to-number value) 100.0)
                                 nil :margin 0 :stroke 2 :radius 3 :padding 2 :width 11)
               (svg-lib-tag (concat value "%")
                            nil :stroke 0 :margin 0)) :ascent 'center)))

(defun svg-progress-count (value)
  (save-match-data
    (let* ((seq (split-string value "/"))
           (count (if (stringp (car seq))
                      (float (string-to-number (car seq)))
                    0))
           (total (if (stringp (cadr seq))
                      (float (string-to-number (cadr seq)))
                    1000)))
      (svg-image (svg-lib-concat
                  (svg-lib-progress-bar (/ count total) nil
                                        :margin 0 :stroke 2 :radius 3 :padding 2 :width 11)
                  (svg-lib-tag value nil
                               :stroke 0 :margin 0)) :ascent 'center))))

(setq svg-tag-tags
      `(
        ;; Org tags
        ;; (":\\([A-Za-z0-9]+\\)" . ((lambda (tag) (svg-tag-make tag))))
        ;; (":\\([A-Za-z0-9]+[ \-]\\)" . ((lambda (tag) tag)))

        ;; Task priority
        ("\\[#[A-Z]\\]" . ( (lambda (tag)
                              (svg-tag-make tag :face 'org-priority
                                            :beg 2 :end -1 :margin 0))))

        ;; TODO / DONE
        ("TODO" . ((lambda (tag) (svg-tag-make "TODO" :face 'org-todo :inverse t :margin 0))))
        ("DONE" . ((lambda (tag) (svg-tag-make "DONE" :face 'org-done :margin 0))))


        ;; Citation of the form [cite:@Knuth:1984]
        ;; ("\\(\\[cite:@[A-Za-z]+:\\)" . ((lambda (tag)
        ;;                                   (svg-tag-make tag
        ;;                                                 :inverse t
        ;;                                                 :beg 7 :end -1
        ;;                                                 :crop-right t))))
        ;; ("\\[cite:@[A-Za-z]+:\\([0-9]+\\]\\)" . ((lambda (tag)
        ;;                                         (svg-tag-make tag
        ;;                                                       :end -1
        ;;                                                       :crop-left t))))


        ;; Active date (with or without day name, with or without time)
        ;; (,(format "\\(<%s>\\)" date-re) .
        ;;  ((lambda (tag)
        ;;     (svg-tag-make tag :beg 1 :end -1 :margin 0))))
        ;; (,(format "\\(<%s \\)%s>" date-re day-time-re) .
        ;;  ((lambda (tag)
        ;;     (svg-tag-make tag :beg 1 :inverse nil :crop-right t :margin 0))))
        ;; (,(format "<%s \\(%s>\\)" date-re day-time-re) .
        ;;  ((lambda (tag)
        ;;     (svg-tag-make tag :end -1 :inverse t :crop-left t :margin 0))))

        ;; Inactive date  (with or without day name, with or without time)
         ;; (,(format "\\(\\[%s\\]\\)" date-re) .
         ;;  ((lambda (tag)
         ;;     (svg-tag-make tag :beg 1 :end -1 :margin 0 :face 'org-date))))
         ;; (,(format "\\(\\[%s \\)%s\\]" date-re day-time-re) .
         ;;  ((lambda (tag)
         ;;     (svg-tag-make tag :beg 1 :inverse nil :crop-right t :margin 0 :face 'org-date))))
         ;; (,(format "\\[%s \\(%s\\]\\)" date-re day-time-re) .
         ;;  ((lambda (tag)
         ;;     (svg-tag-make tag :end -1 :inverse t :crop-left t :margin 0 :face 'org-date))))

        ;; Progress
        ;; ("\\(\\[[0-9]\\{1,3\\}%\\]\\)" . ((lambda (tag)
        ;;                                     (svg-progress-percent (substring tag 1 -2)))))
        ;; ("\\(\\[[0-9]+/[0-9]+\\]\\)" . ((lambda (tag)
        ;;                                   (svg-progress-count (substring tag 1 -1)))))
        ))

Org roam

(unpin! org-roam)
(package! org-roam-ui)
(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))

LSP

General

(after! lsp-mode
  (setq lsp-inlay-hint-enable t
        lsp-inlay-hints-mode t))

HTML tag pair editing.

(require 'sgml-mode)
(add-hook 'web-mode-hook 'sgml-electric-tag-pair-mode)

Poetry + pyenv bug fix.

(after! poetry
  (remove-hook 'python-mode-hook #'poetry-tracking-mode)
  (add-hook 'python-mode-hook 'poetry-track-virtualenv))

Prisma

(package! prisma-mode :recipe (:host github :repo "pimeys/emacs-prisma-mode" :branch "main"))

About

doom emacs config

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors