emacs: Rework configuration

This commit is contained in:
caem 2025-02-21 17:28:19 +01:00
parent 79bb2f7c9c
commit 0abac2afd1
Signed by: caem
GPG key ID: 69A830D03203405F
20 changed files with 105 additions and 113 deletions

View file

@ -1,12 +1,12 @@
{ pkgs, config, ... }:
let
# Has to be >= 29 due to treesitter
# Has to be >= 29.1 due to treesitter
emacsPkg = "emacs30";
in {
services.emacs = {
enable = true;
package = pkgs."${emacsPkg}";
package = pkgs."${emacsPkg}";
defaultEditor = true;
};

View file

@ -1,9 +0,0 @@
(setq custom-file "/dev/null")
(let ((backup_dir (concat (or (getenv "XDG_CACHE_HOME") "~/.cache") "/emacs_backups")))
(make-directory backup_dir t)
(setq backup-directory-alist '(("." . backup_dir))
backup-by-copying t))
(setq inhibit-startup-message t)
(setq auto-save-default nil)

View file

@ -1,24 +0,0 @@
(tool-bar-mode 0)
(menu-bar-mode 0)
(scroll-bar-mode 0)
(setq display-line-numbers-type 'relative)
(global-display-line-numbers-mode t)
(global-hl-line-mode t)
(set-frame-parameter nil 'alpha-background 90)
(add-to-list 'default-frame-alist
'(font . "Go Mono Nerd Font-12"))
(use-package darktooth-theme
:ensure t
:config
(load-theme 'darktooth-dark t)
(set-face-background 'hl-line "#262626")) ;; darktooth-background-0
(use-package tree-sitter :ensure t)
(use-package tree-sitter-langs :ensure t)
(setq treesit-extra-load-path
(file-expand-wildcards (concat package-user-dir "/tree-sitter-langs*/bin")))
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)

View file

@ -1,8 +0,0 @@
(ido-mode 1)
(ido-everywhere 1)
(use-package smex
:ensure t
:bind (("M-x" . smex)
("M-X" . smex-major-mode-commands))
:config (smex-initialize))

View file

@ -0,0 +1,27 @@
(tool-bar-mode 0)
(menu-bar-mode 0)
(scroll-bar-mode 0)
(setq display-line-numbers-type 'relative)
(global-display-line-numbers-mode t)
(global-hl-line-mode t)
(add-to-list 'default-frame-alist
'(font . "Go Mono Nerd Font-12"))
(let ((opacity 95))
(set-frame-parameter nil 'alpha-background opacity)
(add-to-list 'default-frame-alist `(alpha-background . ,opacity)))
(setq compilation-scroll-output t)
(use-package rainbow-delimiters
:ensure t
:hook
((prog-mode . rainbow-delimiters-mode)))
(use-package darktooth-theme
:ensure t
:config
(load-theme 'darktooth-dark t)
(set-face-background 'hl-line "#262626"))

View file

@ -0,0 +1,17 @@
(use-package smex
:ensure t
:bind
(("M-x" . smex)
("M-X" . smex-major-mode-commands))
:config (smex-initialize))
(use-package ido-completing-read+
:ensure t
:config (ido-ubiquitous-mode 1))
(use-package amx
:ensure t
:config (amx-mode 1))
(ido-mode 1)
(ido-everywhere 1)

View file

@ -0,0 +1,5 @@
(rei/load "repositories.el")
(rei/load "litter.el")
(rei/load "appearance.el")
(rei/load "tree-sitter.el")
(rei/load "ido.el")

View file

@ -0,0 +1,10 @@
(setq custom-file "/dev/null"
inhibit-splash-screen t
backup-by-copying t)
(use-package no-littering
:ensure t
:init
(setq no-littering-etc-directory (file-name-concat (xdg-data-home) "emacs")
no-littering-var-directory (file-name-concat (xdg-data-home) "emacs"))
(no-littering-theme-backups))

View file

@ -0,0 +1,8 @@
;; Set the elpa directory ahead of loading the no-littering package, as it would
;; otherwise cause it to be installed in the configuration directory as no-littering
;; has to be first insalled from melpa before being able to be called.
(setq package-user-dir (file-name-concat (xdg-data-home) "emacs" "elpa"))
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize)

View file

@ -0,0 +1,11 @@
(require 'treesit)
(setq treesit-font-lock-level 4)
(use-package treesit-auto
:ensure t
:custom
(treesit-auto-install 'prompt)
:config
(treesit-auto-add-to-auto-mode-alist 'all)
(global-treesit-auto-mode))

View file

@ -1,16 +0,0 @@
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq indent-line-function 'insert-tab)
(setq-default show-trailing-whitespace t)
(use-package indent-bars
:ensure t
:hook ((prog-mode . indent-bars-mode)
(text-mode . indent-bars-mode))
:custom
(indent-bars-display-on-blank-lines t)
(indent-bars-pattern " . . . ")
(indent-bars-color '("#7C6F64" :blend 0.2))
(indent-bars-width-frac 0.15)
(indent-bars-color-by-depth nil)
(indent-bars-highlight-current-depth '(:color "#DD6F48" :pattern "." :blend 0.4)))

View file

@ -1,29 +1,8 @@
(setq conf-home (concat (or (getenv "XDG_CONFIG_HOME") "~/.config") "/emacs"))
(require 'xdg)
(setq user-emacs-directory (file-name-concat (xdg-config-home) "emacs"))
(add-to-list 'load-path user-emacs-directory)
;; Set up paths so that emacs never touches ~/.config/emacs
(let ((data-home (concat (or (getenv "XDG_DATA_HOME") "~/.local/share") "/emacs")))
(setq user-emacs-directory data-home
custom-file (expand-file-name "custom.el" data-home)
url-history-file (expand-file-name "url/history" data-home)
package-user-dir (expand-file-name "elpa" data-home)
boomark-default-file (expand-file-name "bookmarks" data-home)
recentf-save-file (expand-file-name "recentf" data-home)
tramp-persistent-file-name (expand-file-name "tramp" data-home)
auto-save-list-file-prefix (expand-file-name "auto-save-list/.saves-" data-home)
abbrev-file-name (expand-file-name "abbrev.el" data-home)
savehist-file (expand-file-name "savehist" data-home)
server-auth-dir (expand-file-name "server" data-home)
package-quickstart-file (expand-file-name "package-quickstart.elc" data-home))
(startup-redirect-eln-cache (expand-file-name "eln-cache" data-home)))
(require 'rei)
(package-initialize)
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(load (expand-file-name "./appearance.el" conf-home))
(load (expand-file-name "./annoyances.el" conf-home))
(load (expand-file-name "./completions.el" conf-home))
(load (expand-file-name "./formatting.el" conf-home))
(mapc 'load (file-expand-wildcards (expand-file-name "./languages/*.el" conf-home)))
(rei/load "core")
(rei/load "modes")

View file

@ -1,6 +0,0 @@
(setq c-basic-offset 4)
;; https://files.catbox.moe/miu12k.jpg
(setq c-default-style '((other . "stroustrup")
(awk-mode . "awk")
(java-mode . "java")))

View file

@ -1,11 +0,0 @@
(use-package nix-mode
:ensure t
:mode "\\.nix\\'")
(use-package pretty-sha-path
:ensure t
:config (global-pretty-sha-path-mode 1))
(add-hook 'nix-mode-hook
(lambda ()
(setq tab-width 2)))

View file

@ -1,4 +0,0 @@
(use-package rust-mode
:ensure t
:init
(setq rust-mode-treesitter-derive t))

View file

@ -1,2 +0,0 @@
(use-package systemd
:ensure t)

View file

@ -1,4 +0,0 @@
(use-package yaml-mode
:ensure t
:mode ("\\.yaml\\'" . yaml-mode)
:mode ("\\.yml\\'" . yaml-mode))

View file

@ -0,0 +1 @@
(rei/load "nix-mode.el")

View file

@ -0,0 +1,5 @@
(use-package nix-mode
:ensure t
:mode ("\\.nix\\'" "\\.nix.in\\'")
:init
(global-nix-prettify-mode 1))

View file

@ -0,0 +1,13 @@
(provide 'rei)
(defun rei/load (path)
"Load a configuraion file relative to the current file.
When the specified path is a directory it will look for a init.el file to load."
(when load-file-name
(let ((fp (file-name-concat (file-name-directory load-file-name) path)))
(if (file-directory-p fp)
(let ((fdp (file-name-concat fp "init.el")))
(if (file-exists-p fdp)
(load fdp)
(error "Cannot load %s directory as it's missing an init.el file." path)))
(load fp)))))