diff --git a/config/init.org b/config/init.org index 7dec69a..ce29dad 100644 --- a/config/init.org +++ b/config/init.org @@ -1,171 +1,273 @@ -#+PROPERTY: header-args:emacs-lisp :tangle yes #+TITLE: Emacs Configuration #+AUTHOR: Mars (@pupbrained) #+EMAIL: mars@pupbrained.xyz +#+PROPERTY: header-args:emacs-lisp :tangle yes + +* Basic Setup + +** Server #+begin_src emacs-lisp -; Fixes "Symbol's value as variable is void: personal-keybindings" error -(require 'bind-key) - -; Start server -(load "server") -(unless (server-running-p) (server-start)) - -; Disable bars -(menu-bar-mode -1) -(scroll-bar-mode -1) -(tool-bar-mode -1) - -; Vim-style scrolling -(setq scroll-step 3 - scroll-margin 3 - scroll-conservatively 9999) - -; Set titlebar for macOS -(when (eq system-type 'darwin) - (ns-auto-titlebar-mode)) - -; Set font size depending on the system type -(cond - ((eq system-type 'darwin) - (setq default-frame-alist '((font . "Maple Mono NF-16")))) - ((eq system-type 'gnu/linux) - (setq default-frame-alist '((font . "Maple Mono NF-12"))))) - -; Set theme -(use-package catppuccin-theme :ensure t :demand t) -(load-theme 'catppuccin t) - -; Set modeline -(use-package doom-modeline - :ensure t - :hook (after-init . doom-modeline-mode)) - -; Emoji support -(use-package emojify - :hook (after-init . global-emojify-mode)) - -; Undo tree -(use-package undo-tree - :demand t - :config - (global-undo-tree-mode) - (setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo")))) - -; Evil mode -(use-package evil - :ensure t - :init - (setq evil-want-integration t) ;; This is optional since it's already set to t by default. - (setq evil-want-keybinding nil) - (setq evil-undo-system 'undo-tree) - :config - (evil-mode 1)) - -;; Evil collection -(use-package evil-collection - :after evil - :ensure t - :config - (evil-collection-init)) - -;; Evil leader -(use-package evil-leader - :after evil - :config - (global-evil-leader-mode) - (setq evil-leader/leader "") ;; Set the leader key to space - (evil-leader/set-key "a" #'eglot-code-actions) - (evil-leader/set-key "e" #'treemacs)) - -; Dashboard -(use-package dashboard - :ensure t - :config - (dashboard-setup-startup-hook) - (setq dashboard-startup-banner 'logo)) - -(defun dashboard-recentf-filter (file) - "Add to ~recentf-exclude~ to filter recent files in dashboard buffer." - (when (eq (get-buffer dashboard-buffer-name) - (current-buffer)) - (string-match "treemacs-persist$" file))) - -(add-to-list 'recentf-exclude 'dashboard-recentf-filter) - -; Direnv -(use-package direnv - :config - (direnv-mode)) - -; Nix -(use-package nix-mode - :mode "\\.nix\\'") - -; Treesitter -(use-package tree-sitter - :hook ((prog-mode . tree-sitter-mode) - (prog-mode . tree-sitter-hl-mode))) - -(use-package tree-sitter-langs) - -(use-package treesit-auto - :config - (global-treesit-auto-mode) - (dolist (lang treesit-language-source-alist) - (let ((mode (intern (format "%s-ts-mode" (car lang))))) - (when (fboundp mode) - (add-to-list 'major-mode-remap-alist - (cons (intern (car lang)) mode)))))) - -; Eglot setup -(add-hook 'prog-mode-hook 'eglot-ensure) - -(evil-leader/set-key - "a" #'eglot-code-actions) - -;; Function to format the buffer using Eglot -(defun my/eglot-format-buffer-on-save () - "Format the current buffer if Eglot is active." - (when (bound-and-true-p eglot--managed-p) - (eglot-format-buffer))) - -;; Add the function to the save-hook -(add-hook 'before-save-hook #'my/eglot-format-buffer-on-save) - -; Flycheck -(use-package flycheck - :ensure t - :config - (add-hook 'after-init-hook #'global-flycheck-mode)) - -; Sideline -(use-package sideline-flycheck - :hook (flycheck-mode . sideline-mode) - :init (setq sideline-backends-right '(sideline-flycheck) - sideline-delay 0.0)) - -(use-package sideline-flycheck - :hook (flycheck-mode . sideline-flycheck-setup) - :init (setq sideline-flycheck-display-mode 'line)) - -; Eglot -(use-package sideline-eglot - :init - (setq sideline-backends-right '(sideline-eglot))) - -(use-package eglot :hook (eglot-mode . sideline-mode)) ; enable it when eglot is on - -; Centaur tabs -(use-package centaur-tabs - :demand t - :config - (centaur-tabs-mode t) - (setq centaur-tabs-style "wave") - :bind - ("C-" . centaur-tabs-backward) - ("C-" . centaur-tabs-forward)) - -(use-package vterm-toggle :ensure t) -(global-set-key [C-t] 'vterm-toggle) + (require 'bind-key) + (load "server") + (unless (server-running-p) (server-start)) +#+end_src + +** Disable UI Elements + +#+begin_src emacs-lisp + (menu-bar-mode -1) + (scroll-bar-mode -1) + (tool-bar-mode -1) +#+end_src + +** Vim-Style Scrolling + +#+begin_src emacs-lisp + (setq scroll-step 3 + scroll-margin 3 + scroll-conservatively 9999) +#+end_src + +** System-Specific Settings + +#+begin_src emacs-lisp + (when (and (eq system-type 'darwin) (not (daemonp))) + (ns-auto-titlebar-mode)) + + (cond + ((eq system-type 'darwin) + (setq default-frame-alist '((font . "Maple Mono NF-16")))) + ((eq system-type 'gnu/linux) + (setq default-frame-alist '((font . "Maple Mono NF-12"))))) +#+end_src + +* Package Management + +** Theme + +#+begin_src emacs-lisp + (use-package catppuccin-theme :ensure t :demand t) + (load-theme 'catppuccin t) +#+end_src + +** Dashboard + +#+begin_src emacs-lisp + (use-package dashboard + :ensure t + :config + (dashboard-setup-startup-hook) + (setq dashboard-startup-banner 'logo) + (setq dashboard-center-content t) + (setq dashboard-vertically-center-content t) + (setq dashboard-startup-banner 'logo) + (setq initial-buffer-choice (lambda () (get-buffer "*dashboard*"))) + (setq recentf-exclude '("~/.emacs.d/.cache/treemacs-persist"))) +#+end_src + +** Modeline + +#+begin_src emacs-lisp + (use-package doom-modeline + :ensure t + :hook (after-init . doom-modeline-mode)) +#+end_src + +** Emoji Support + +#+begin_src emacs-lisp + (use-package emojify + :hook (after-init . global-emojify-mode)) +#+end_src + +** Undo Tree + +#+begin_src emacs-lisp + (use-package undo-tree + :demand t + :config + (global-undo-tree-mode) + (setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo")))) +#+end_src + +* Development Tools + +** Direnv + +#+begin_src emacs-lisp + (use-package direnv + :config + (direnv-mode)) +#+end_src + +** Nix + +#+begin_src emacs-lisp + (use-package nix-mode + :mode "\\.nix\\'") +#+end_src + +** Treesitter + +#+begin_src emacs-lisp + (use-package treesit-auto + :requires treesit + :config + (setq treesit-auto-install 'prompt) + (global-treesit-auto-mode)) + + (use-package treesit + :requires treesit + :ensure nil + :config + (mapc #'exordium--add-forward-ts-hook + '( + LaTeX + bash + c + c++ + cmake + csharp + css + go + go-mod + java + js + json + markdown + python + ruby + rust + scala + toml + typescript + yaml + )) + (setq treesit-font-lock-level 4)) + + (use-package tree-sitter-langs) + (use-package tree-sitter + :diminish + :after (tree-sitter-langs) + :hook + (tree-sitter-after-on . tree-sitter-hl-mode) + :custom + (font-lock-maximum-decoration t) + :config + (when-let ((language-name (alist-get 'ruby-mode + tree-sitter-major-mode-language-alist))) + (add-to-list 'tree-sitter-major-mode-language-alist + (cons 'enh-ruby-mode language-name))) + (add-to-list 'tree-sitter-major-mode-language-alist + (cons 'forge-post-mode 'markdown)) + (global-tree-sitter-mode)) +#+end_src + +** Eglot + +#+begin_src emacs-lisp + (add-hook 'prog-mode-hook 'eglot-ensure) + + (defun my/eglot-format-buffer-on-save () + "Format the current buffer if Eglot is active." + (when (bound-and-true-p eglot--managed-p) + (eglot-format-buffer))) + + (add-hook 'before-save-hook #'my/eglot-format-buffer-on-save) +#+end_src + +** Flycheck + +#+begin_src emacs-lisp + (use-package flycheck + :ensure t + :config + (add-hook 'after-init-hook #'global-flycheck-mode)) +#+end_src + +** Sideline + +#+begin_src emacs-lisp + (use-package sideline-flycheck + :hook (flycheck-mode . sideline-mode) + :init (setq sideline-backends-right '(sideline-flycheck) + sideline-delay 0.0)) + + (use-package sideline-flycheck + :hook (flycheck-mode . sideline-flycheck-setup) + :init (setq sideline-flycheck-display-mode 'line)) + + (use-package sideline-eglot + :init + (setq sideline-backends-right '(sideline-eglot))) + + (use-package eglot :hook (eglot-mode . sideline-mode)) +#+end_src + +** VTerm Toggle + +#+begin_src emacs-lisp + (use-package vterm-toggle :ensure t) + (global-set-key [C-t] 'vterm-toggle) +#+end_src + +* Evil Mode and Keybindings + +** Evil Mode + +#+begin_src emacs-lisp + (use-package evil + :ensure t + :init + (setq evil-want-integration t) + (setq evil-want-C-u-scroll t) + (setq evil-want-keybinding nil) + (setq evil-undo-system 'undo-tree) + :config + (evil-mode 1)) +#+end_src + +** Evil Collection + +#+begin_src emacs-lisp + (use-package evil-collection + :after evil + :ensure t + :config + (evil-collection-init)) +#+end_src + +** Evil Leader + +#+begin_src emacs-lisp + (use-package evil-leader + :after evil + :config + (global-evil-leader-mode) + (setq evil-leader/leader "") + (evil-leader/set-key "a" #'eglot-code-actions) + (evil-leader/set-key "e" #'treemacs)) +#+end_src + +** Easier Copy/Paste + +#+begin_src emacs-lisp + (global-set-key (kbd "C-S-c") 'kill-ring-save) + (global-set-key (kbd "C-S-v") 'yank) +#+end_src + +* Tab Management + +** Centaur Tabs + +#+begin_src emacs-lisp + (use-package centaur-tabs + :demand t + :config + (centaur-tabs-mode t) + (setq centaur-tabs-style "wave") + :bind + ("C-" . centaur-tabs-backward) + ("C-" . centaur-tabs-forward)) #+end_src