#+TITLE: Materus Emacs Cfg #+AUTHOR: materus #+DESCRIPTION: materus emacs configuration #+STARTUP: overview #+PROPERTY: EMACS-DIR: "./" #+PROPERTY: header-args :tangle (concat (org-entry-get nil "EMACS-DIR" t) "etc/materus/emacs-config.el") :comments link #+OPTIONS: \n:t #+auto_tangle: t My emacs config, tangled file is [[file:etc/materus/emacs-config.el][there]] #+HTML:
#+HTML: #+HTML: #+HTML:
* Table of Contents :noexport:TOC_3: - [[#init-files][Init Files]] - [[#early-init][Early Init]] - [[#early-init-variables][Early Init Variables]] - [[#garbage-collector][Garbage Collector]] - [[#early-frame-settings][Early Frame Settings]] - [[#native-compilation][Native compilation]] - [[#init][Init]] - [[#compile-time][Compile Time]] - [[#packages][Packages]] - [[#init-package-manager-config][Init package manager config]] - [[#packages-list--function][Packages list & function]] - [[#configuration][Configuration]] - [[#no-littering][No Littering]] - [[#graphical][Graphical]] - [[#mouse][Mouse]] - [[#misc][Misc]] - [[#dashboard][Dashboard]] - [[#modeline][Modeline]] - [[#diff-hl][Diff-hl]] - [[#org-mode][Org-mode]] - [[#completions][Completions]] - [[#style][Style]] - [[#minibuffer][Minibuffer]] - [[#code-completion][Code completion]] - [[#terms][Terms]] - [[#eat][Eat]] - [[#miscellaneous][Miscellaneous]] - [[#defaults][Defaults]] - [[#elcord][Elcord]] - [[#undo-tree][Undo-Tree]] - [[#projectile][Projectile]] - [[#treemacs][Treemacs]] - [[#magit][Magit]] - [[#dirvish][Dirvish]] - [[#perspective][Perspective]] - [[#programming][Programming]] - [[#lsp][LSP]] - [[#nix][Nix]] - [[#emacs-lisp][Emacs Lisp]] - [[#cc][C/C++]] - [[#python][Python]] - [[#java][Java]] - [[#other][Other]] - [[#keybindings][Keybindings]] - [[#snippets][Snippets]] - [[#yasnippet-init][Yasnippet init]] - [[#other-1][Other]] - [[#update-config-script][Update config script]] - [[#byte-compile][Byte compile]] - [[#test][Test]] * Init Files ** Early Init :PROPERTIES: :header-args: :tangle (concat (org-entry-get nil "EMACS-DIR" t) "early-init.el") :comments link :END: Early init file, setting for GC and some paths. Tangled file is [[./early-init.el][there]] #+begin_src emacs-lisp :comments no ;;; -*- lexical-binding: t; -*- #+end_src *** Early Init Variables Setting early init variables #+begin_src emacs-lisp (defvar materus/init-early t "Is emacs using materus early init") ; Var to ensure early-init loaded, not used anymore but keeping it anyway (setq materus/init-early t) ; Probably useless (setenv "LSP_USE_PLISTS" "true") ; Make lsp-mode use plists ;; (setq c-default-style nil) ; Clear default styles for languages, will set them up later (setq default-input-method nil) ; Disable default input method, I'm not using them anyway so far (setq initial-major-mode 'fundamental-mode) ; Use fundamental mode in scratch buffer, speed up loading, not really important when emacs used as daemon (setq auto-save-default nil) ; TODO: configure auto saves, disable for now (setq backup-directory-alist `((".*" . ,(concat user-emacs-directory "var/backups/")))) ; Set backup location (setq auto-save-file-name-transforms `((".*" ,(concat user-emacs-directory "var/recovery/") t))) ; Set auto-save location (setq auto-save-list-file-prefix (concat user-emacs-directory "var/auto-save/sessions/")) ; Set auto-save-list location (setq load-prefer-newer t) ; Prefer newer files to load ;; Packages (setq package-enable-at-startup t) ; Ensure packages are enable since I'm either using built in package manager or nix (setq package-quickstart nil) ; Disable package quickstart, it's annoying if forget to update it and doesn't speed up much ;; (setq inhibit-compacting-font-caches t) ; Don't compact fonts (set-language-environment "UTF-8") ; Use UTF-8 (setq custom-file (concat user-emacs-directory "etc/custom.el")) ; Set custom file location, don't want clutter in main directory (setq custom-theme-directory (concat user-emacs-directory "/etc/materus/themes" )) ; Set custom themes location (setq ring-bell-function 'ignore) ; Disable bell (defvar materus-emacs-gc-cons-threshold (* 64 1024 1024) "The value of `gc-cons-threshold' after Emacs startup.") ; Define after init garbage collector threshold #+end_src *** Garbage Collector Settings for garbage collector #+begin_src emacs-lisp (setq gc-cons-threshold most-positive-fixnum) ; Set `gc-cons-threshold' so it won't collectect during initialization (add-hook 'emacs-startup-hook (lambda () (setq gc-cons-threshold materus-emacs-gc-cons-threshold))) ; Set `gc-cons-threshold' to desired value after startup #+end_src *** Early Frame Settings Early frame settings, maybe some could be move to normal init #+begin_src emacs-lisp (setq frame-inhibit-implied-resize t) (setq frame-resize-pixelwise t) (setq window-resize-pixelwise t) ; Allow pixelwise resizing of window and frame (unless (daemonp) (add-to-list 'initial-frame-alist '(fullscreen . maximized))) ; Start first frame maximized if not running as daemon, daemon frame are set up later in config (setq default-frame-alist ; Set default size for frames '((width . 130) (height . 40))) (advice-add #'tty-run-terminal-initialization :override #'ignore) (add-hook 'window-setup-hook (lambda () (unless (display-graphic-p) (advice-remove #'tty-run-terminal-initialization #'ignore) (tty-run-terminal-initialization (selected-frame) nil t) ))) #+end_src *** Native compilation #+begin_src emacs-lisp (setq native-comp-async-report-warnings-errors nil) ; Silence warnings (setq native-comp-speed 3) ; Set native-comp speed (setq native-comp-jit-compilation t ;;native-comp-deferred-compilation t package-native-compile t) ;; Setting up native-comp cache location (when (and (fboundp 'startup-redirect-eln-cache) (fboundp 'native-comp-available-p) (native-comp-available-p)) (startup-redirect-eln-cache (convert-standard-filename (concat user-emacs-directory "var/eln-cache/")))) #+end_src ** Init :PROPERTIES: :header-args: :tangle (concat (org-entry-get nil "EMACS-DIR" t) "init.el") :comments link :END: Init File, tangled [[./init.el][there]] Checking if using emacs from my nix config, loads config and custom.el Sets up package.el #+begin_src emacs-lisp :comments no ;;; -*- lexical-binding: t; -*- #+end_src #+begin_src emacs-lisp (setq-default materus/use-nix-packages (require 'materus-config nil 'noerror)) (require 'cl-lib) (require 'package) (add-to-list 'load-path (concat user-emacs-directory "etc/materus/extra")) ; Extra load path for packages (setq package-user-dir (concat user-emacs-directory "var/elpa/" emacs-version "/" )) ; Set elpa path for this emacs version, should use nix packages anyway so keeping just in case (setq package-gnupghome-dir (concat user-emacs-directory "var/elpa/gnupg/" )) ; Set path to gnupg for elpa (add-to-list 'package-archives '("nongnu-devel" . "https://elpa.nongnu.org/nongnu-devel/")) ; Add nongnu-devel repo to package manager (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) ; Add melpa repo to package manager (customize-set-variable 'package-archive-priorities '(("gnu" . 99) ("nongnu" . 80) ("nongnu-devel" . 70) ("melpa" . 0))) ; Repository priority (load (concat user-emacs-directory "etc/materus/nix-init") t) (load (concat user-emacs-directory "etc/materus/emacs-config")) (load custom-file t) #+end_src ** Compile Time Some defvar so native-compile wont complain #+begin_src emacs-lisp :comments no ;;; -*- lexical-binding: t; -*- #+end_src #+begin_src emacs-lisp (eval-when-compile (defvar doom-modeline-support-imenu nil) (defvar display-time-24hr-format nil) (defvar lsp-nix-nixd-formatting-command nil) (defvar cua--cua-keys-keymap nil) (declare-function lsp-stdio-connection "lsp-mode" (COMMAND &optional TEST-COMMAND)) (declare-function make-lsp-client "lsp-mode") (declare-function lsp-register-client "lsp-mode" ( CLIENT )) ) #+end_src * Packages Package manager config if not using nix. After some testing default package manager works best for me. ** Init package manager config #+begin_src emacs-lisp #+end_src ** Packages list & function Packages to install #+begin_src emacs-lisp (defvar materus/packages '( use-package elcord dashboard magit git-timemachine avy vterm direnv projectile clipetty which-key iedit hideshowvis evil perspective treemacs-evil treemacs treemacs-nerd-icons treemacs-perspective treemacs-icons-dired treemacs-magit treemacs-projectile tree-edit nerd-icons nerd-icons-completion minions rainbow-delimiters rainbow-mode cmake-mode lsp-mode lsp-java lsp-jedi lsp-haskell lsp-ui lsp-treemacs flycheck gradle-mode groovy-mode kotlin-mode dap-mode d-mode lua-mode multiple-cursors org org-contrib org-ql org-rainbow-tags org-roam org-roam-ui org-review org-present org-superstar org-auto-tangle visual-fill-column csharp-mode markdown-mode json-mode nix-mode nixfmt no-littering right-click-context dracula-theme doom-themes doom-modeline popper undo-tree bash-completion eldoc-box yasnippet async request nix-ts-mode markdown-ts-mode llvm-ts-mode treesit-fold treesit-auto tree-sitter-langs eat vlf edit-indirect zones sudo-edit toc-org empv volatile-highlights highlight elfeed elfeed-goodies drag-stuff dirvish rg shfmt ;; Completions & Minibuffer corfu company company-quickhelp cape embark embark-consult orderless vertico marginalia ) "A list of packages to ensure are installed at launch.") (defun materus/packages-installed-p () (cl-loop for p in materus/packages when (not (package-installed-p p)) do (cl-return nil) finally (cl-return t))) (defun materus/install-packages () (unless (materus/packages-installed-p) (package-refresh-contents) (dolist (p materus/packages) (when (not (package-installed-p p)) (package-install p))))) (unless materus/use-nix-packages (materus/install-packages)) #+end_src * Configuration General configurations of packages modes etc. ** No Littering Set up no littering #+begin_src emacs-lisp (require 'recentf) (use-package no-littering :config (setq package-quickstart-file (concat user-emacs-directory "var/quickstart/package-quickstart-" emacs-version ".el" )) (add-to-list 'recentf-exclude (recentf-expand-file-name no-littering-var-directory)) (add-to-list 'recentf-exclude (recentf-expand-file-name no-littering-etc-directory))) #+end_src ** Graphical Graphical related settings. *** Mouse #+begin_src emacs-lisp (context-menu-mode 1) (setq mouse-wheel-follow-mouse 't) (setq scroll-step 1) (setq mouse-drag-and-drop-region t) (xterm-mouse-mode 1) (pixel-scroll-precision-mode 1) (setq-default pixel-scroll-precision-large-scroll-height 10.0) #+end_src *** Misc #+begin_src emacs-lisp (when (daemonp) (add-hook 'after-make-frame-functions (lambda (frame) (when (= (length (frame-list)) 2) (set-frame-parameter frame 'fullscreen 'maximized))))) (when (display-graphic-p) (set-frame-font "Hack Nerd Font" nil t) ) (setq-default display-line-numbers-width 3) (setq-default display-line-numbers-widen t) (setq truncate-string-ellipsis "…") (global-tab-line-mode 1) (tool-bar-mode -1) (setq window-divider-default-bottom-width 1) (setq window-divider-default-right-width 1) (window-divider-mode 1) (setq-default cursor-type '(bar . 1)) ;; Rainbow mode (use-package rainbow-mode :hook ((org-mode . rainbow-mode) (prog-mode . rainbow-mode))) ;; Delimiters (use-package rainbow-delimiters :hook (prog-mode . rainbow-delimiters-mode) :config (set-face-attribute 'rainbow-delimiters-depth-1-face nil :foreground "#FFFFFF") (set-face-attribute 'rainbow-delimiters-depth-2-face nil :foreground "#FFFF00") (set-face-attribute 'rainbow-delimiters-depth-5-face nil :foreground "#6A5ACD") (set-face-attribute 'rainbow-delimiters-unmatched-face nil :foreground "#FF0000")) ;; Nerd Icons (use-package nerd-icons) (use-package nerd-icons-completion :after (marginalia) :config (nerd-icons-completion-mode 1) (add-hook 'marginalia-mode-hook #'nerd-icons-completion-marginalia-setup)) ;; Theme (use-package dracula-theme :config (if (daemonp) (add-hook 'after-make-frame-functions (lambda (frame) (with-selected-frame frame (load-theme 'dracula t)))) (load-theme 'dracula t))) (defun startup-screen-advice (orig-fun &rest args) (when (= (seq-count #'buffer-file-name (buffer-list)) 0) (apply orig-fun args))) (advice-add 'display-startup-screen :around #'startup-screen-advice) ; Hide startup screen if started with file #+end_src *** Dashboard #+begin_src emacs-lisp (use-package dashboard :after (nerd-icons projectile) :config (setq dashboard-center-content t) (setq dashboard-display-icons-p t) (setq dashboard-icon-type 'nerd-icons) (setq dashboard-projects-backend 'projectile) (setq dashboard-items '((recents . 5) (bookmarks . 5) (projects . 5) (agenda . 5) (registers . 5))) (dashboard-setup-startup-hook) (when (daemonp) (setq initial-buffer-choice (lambda () (get-buffer "*dashboard*"))) ; Show dashboard when emacs is running as daemon ) ) #+end_src *** Modeline #+begin_src emacs-lisp (use-package doom-modeline :init (setq doom-modeline-support-imenu t) :hook (after-init . doom-modeline-mode) :config (setq doom-modeline-icon t) (setq doom-modeline-project-detection 'auto) (setq doom-modeline-height 20) (setq doom-modeline-enable-word-count t) (setq doom-modeline-minor-modes t) (setq display-time-24hr-format t) (display-time-mode 1) (column-number-mode 1) (line-number-mode 1)) (use-package minions :hook (after-init . minions-mode)) #+end_src *** Diff-hl #+begin_src emacs-lisp (use-package diff-hl :config (setq diff-hl-side 'right) (global-diff-hl-mode 1) (diff-hl-margin-mode 1) (diff-hl-flydiff-mode 1) (global-diff-hl-show-hunk-mouse-mode 1)) #+end_src ** Org-mode Org mode settings #+begin_src emacs-lisp (use-package org :mode (("\\.org$" . org-mode)) :hook ((org-mode . org-indent-mode) (org-mode . display-line-numbers-mode) ) :config (require 'org-mouse) (require 'org-tempo) (setq org-src-window-setup 'current-window) (add-hook 'org-mode-hook (lambda () (setq-local electric-pair-inhibit-predicate `(lambda (c) (if (char-equal c ?<) t (,electric-pair-inhibit-predicate c))))))) (use-package org-superstar :after (org) :hook (org-mode . org-superstar-mode)) :config (setq org-superstar-leading-bullet " ") (use-package org-auto-tangle :after (org) :hook (org-mode . org-auto-tangle-mode)) (use-package toc-org :after (org) :hook ((org-mode . toc-org-mode ) (markdown-mode . toc-org-mode))) #+end_src ** Completions *** Style #+begin_src emacs-lisp (use-package orderless :init ;; Tune the global completion style settings to your liking! ;; This affects the minibuffer and non-lsp completion at point. (setq completion-styles '(basic partial-completion orderless) completion-category-defaults nil completion-category-overrides nil)) #+end_src *** Minibuffer #+begin_src emacs-lisp (use-package consult) (use-package marginalia) (use-package which-key :config (which-key-mode 1)) (use-package vertico :after (consult marginalia) :config (setq completion-in-region-function (lambda (&rest args) (apply (if vertico-mode #'consult-completion-in-region #'completion--in-region) args))) (vertico-mode 1) (marginalia-mode 1)) (use-package vertico-mouse :config (vertico-mouse-mode 1)) #+end_src *** Code completion #+begin_src emacs-lisp (use-package cape) (use-package corfu ;; Optional customizations :custom (corfu-cycle nil) ;; Enable cycling for `corfu-next/previous' (corfu-auto t) ;; Enable auto completion (global-corfu-minibuffer nil) ;; (corfu-quit-at-boundary nil) ;; Never quit at completion boundary ;; (corfu-quit-no-match nil) ;; Never quit, even if there is no match (corfu-preview-current nil) ;; Disable current candidate preview ;; (corfu-preselect 'prompt) ;; Preselect the prompt ;; (corfu-on-exact-match nil) ;; Configure handling of exact matches ;; Enable Corfu only for certain modes. See also `global-corfu-modes'. ;; :hook ((prog-mode . corfu-mode) ;; (shell-mode . corfu-mode) ;; (eshell-mode . corfu-mode)) ;; Recommended: Enable Corfu globally. This is recommended since Dabbrev can ;; be used globally (M-/). See also the customization variable ;; `global-corfu-modes' to exclude certain modes. :init (global-corfu-mode 1) (corfu-popupinfo-mode 1) (corfu-history-mode 1)) (use-package corfu-terminal :after (corfu) :config (when (or (daemonp) (not (display-graphic-p))) (corfu-terminal-mode))) (use-package corfu-mouse :after (corfu) :config (corfu-mouse-mode) (keymap-set corfu--mouse-ignore-map "