;; put auto-generated configs in a separate file ;; https://protesilaos.com/codelog/2024-11-28-basic-emacs-configuration/#h:7db72beb-b8ac-4c6d-a6f4-a52661208e23 (setq custom-file (locate-user-emacs-file "custom.el")) (load custom-file :no-error-if-file-is-missing) ;; Set up package.el to work with MELPA (require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/")) ;; View package diffs on upgrade ;; https://www.reddit.com/r/emacs/comments/1rowm5i/comment/o9hzo8w/ (setq package-review-policy t package-review-diff-command '("git" "diff" "--no-index" "--color=never" "--diff-filter=d")) (package-initialize) ;; Use Evil Mode (use-package evil :ensure t :init (setq evil-want-keybinding nil) ;; required for evil-collection :custom (evil-undo-system 'undo-redo) (evil-want-C-u-scroll t) (evil-want-Y-yank-to-eol t) :config (evil-mode 1) ) (use-package evil-collection :after evil :ensure t :config (evil-collection-init)) ;; compilation keybinds (evil-set-leader 'normal (kbd "SPC")) (evil-define-key 'normal 'global (kbd "cc") 'compile) (evil-define-key 'normal 'global (kbd "cp") 'project-compile) (evil-define-key 'normal 'global (kbd "cr") 'recompile) ;; Don't show the splash screen (setq inhibit-startup-message t) ;; Turn off unneeded UI elements (menu-bar-mode -1) (tool-bar-mode -1) (scroll-bar-mode -1) ;; Set line numbers (setq display-line-numbers-type 'relative) (global-display-line-numbers-mode 1) ;; Remove left continuation fringe arrow (the wrapping one) ;; Source - https://stackoverflow.com/a/27854648 (setf (cdr (assq 'continuation fringe-indicator-alist)) '(nil right-curly-arrow)) ;; Turn off blinking cursor (blink-cursor-mode -1) ;; Set font (add-to-list 'default-frame-alist '(font . "TX-02 Condensed-13")) ;; Add nerdfont to list of fallback fonts ;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Modifying-Fontsets.html (set-fontset-font "fontset-default" nil "Symbols Nerd Font" nil 'append) ;; Theme (use-package standard-themes :ensure t :custom (modus-themes-common-palette-overrides '((fringe unspecified) ;; make fringe invisible )) :config (modus-themes-load-theme 'standard-light)) ;; reset current line number styling to default (set-face-attribute 'line-number-current-line nil :inherit) ;; small amount of header spacing (setq-default header-line-format "") (set-face-attribute 'header-line nil :background 'unspecified :height (* 10 5)) ;; Color output when compiling (use-package fancy-compilation :ensure t :commands (fancy-compilation-mode) :custom (fancy-compilation-quiet-prelude nil) (fancy-compilation-override-colors nil) ) (with-eval-after-load 'compile (fancy-compilation-mode)) (with-eval-after-load 'project-compile (fancy-compilation-mode)) ;; Git highlight (use-package diff-hl :ensure t :hook (dired-mode . diff-hl-dired-mode) :config (global-diff-hl-mode)) ;; Magit (use-package magit :ensure t) ;; Move temporary files to /var/tmp/ (setq backup-directory-alist `(("." . "/var/tmp/"))) ;; https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Locks.html#index-lock_002dfile_002dname_002dtransforms (setq lock-file-name-transforms '(("\\`/.*/\\([^/]+\\)\\'" "/var/tmp/\\1" t))) (setq auto-save-file-name-transforms '(("\\`/.*/\\([^/]+\\)\\'" "/var/tmp/\\1" t))) ;; consult (use-package consult :ensure t :bind ("C-x b" . consult-buffer) ;; orig. switch-to-buffer ) ;; Set spellcheck program (setq ispell-program-name "/usr/bin/aspell") ;; Word counter ;; Using unix wc because emacs's built-in 'count-words gives wrong count ;; https://www.emacswiki.org/emacs/WordCount#h5o-7 (the unix way) ;; https://stackoverflow.com/a/5020475 (why substring is required) (defun unix-wc-word (str) (substring (shell-command-to-string (concat "echo " (shell-quote-argument str) " | wc -w")) 0 -1) ) (defun wc (start end) ;; (interactive) TODO: not sure how to make it interactive, tbh (unix-wc-word (buffer-substring start end)) ) (defun wci () (interactive) (message "Words: %s" (wc (mark) (point)) ) ) ;; Most code taken from https://web.archive.org/web/20160322014200/http://www.dr-qubit.org/emacs-misc/wc-mode-0.3.el ;; BUG: doesn't correctly in Evil Visual-Line mode ;; use Visual mode for correct WC of a region (setq mode-line-position (assq-delete-all 'wc-mode mode-line-position)) ;; BUG: Using this makes the buffer VERY laggy. ;; I guess it's because of the constant calls to "$ wc" ;; Manually using the above wci for now (setq mode-line-position (append mode-line-position '((wc-mode (6 (:eval (if (use-region-p) (format "WC:%s" (wc (mark) (point))) ;; (count-words-region (region-beginning) (region-end))) (format "WC:%s" (wc (point-min) (point-max)))))) ;; (count-words-region (point-min) (point-max)))))) nil)))) (define-minor-mode wc-mode "Toggle word-count mode. With no argument, this command toggles the mode. A non-null prefix argument turns the mode on. A null prefix argument turns it off. When enabled, the total number of characters, words, and lines is displayed in the mode-line.") ;;;;;;;;;;;;;;; ;; Languages ;; ;;;;;;;;;;;;;;; (use-package eglot) (use-package reformatter :ensure t) ;; Typst (reformatter-define typstyle :program "typstyle") (use-package typst-ts-mode :vc (:url "https://codeberg.org/meow_king/typst-ts-mode.git") :mode ("\\.typ\\'" . typst-ts-mode) :interpreter ("Typst" . typst-ts-mode) :config (add-to-list 'eglot-server-programs `((typst-ts-mode) . ,(eglot-alternatives `(,typst-ts-lsp-download-path "tinymist" "typst-lsp")))) :hook (typst-ts-mode . eglot-ensure) :hook (typst-ts-mode . typstyle-on-save-mode) ) ;; Python (use-package python :config (add-to-list 'eglot-server-programs `(python-mode . ("ruff" "server"))) ;; :hook (python-mode . eglot-ensure) ;; :hook (python-mode . (lambda () (add-hook 'after-save-hook 'eglot-format nil t))) ) ;; Rust (use-package rust-mode :ensure t) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Other Development Stuff ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; direnv (use-package envrc :ensure t :hook (after-init . envrc-global-mode)) ;;;;;;;;;;;;;;; ;; Clipboard ;; ;;;;;;;;;;;;;;; ;; Fixes Wayland clipboard troubles ;; see https://www.emacswiki.org/emacs/CopyAndPaste#h5o-6 (setq wl-copy-process nil) (defun wl-copy (text) (setq wl-copy-process (make-process :name "wl-copy" :buffer nil :command '("wl-copy" "-f" "-n") :connection-type 'pipe :noquery t)) (process-send-string wl-copy-process text) (process-send-eof wl-copy-process)) (defun wl-paste () (if (and wl-copy-process (process-live-p wl-copy-process)) nil ; should return nil if we're the current paste owner (shell-command-to-string "wl-paste -n | tr -d \r"))) (setq interprogram-cut-function 'wl-copy) (setq interprogram-paste-function 'wl-paste)