diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2025-05-17 19:05:29 +0200 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2025-05-17 19:05:29 +0200 |
| commit | 4f73327da10444275439d20ef68f4b218b1e26e4 (patch) | |
| tree | f5549608330f9f393fe95f36c4f115f88920acb5 /config | |
| parent | 59fc44870d8ff5a57a36aa5e608006536af95f55 (diff) | |
Completely Refactor Emacs Configuration
We now have a monolithic `init.el` instead of spliting it into files.
I noticed that the splitting wasn't so helpful anyway... Maybe in the
future when the config grows, I can think about splitting again
(although, I will try to avoid that situation as much as possible).
One large functional change is that I no longer try to fight Emacs to
get it to put files in '~/.cache/emacs'. It was annoying, and it is
just easier and more practical to just use a '.gitignore' in order to
ignore any files other than my configuration (and since there are so
few - two in fact - it is not a hard list to maintain).
Diffstat (limited to 'config')
| -rw-r--r-- | config/emacs/.gitignore | 10 | ||||
| -rw-r--r-- | config/emacs/early-init.el | 22 | ||||
| -rw-r--r-- | config/emacs/flavours/development.el | 91 | ||||
| -rw-r--r-- | config/emacs/flavours/macos.el | 3 | ||||
| -rw-r--r-- | config/emacs/init.el | 226 |
5 files changed, 226 insertions, 126 deletions
diff --git a/config/emacs/.gitignore b/config/emacs/.gitignore new file mode 100644 index 0000000..c553df8 --- /dev/null +++ b/config/emacs/.gitignore @@ -0,0 +1,10 @@ +# Emacs tends to put **A LOT** of packages in the `emacs-user-directory` (i.e. +# `.emacs.d` or `~/.config/emacs`). At first, I tried to fight it by adding +# various configurations to put those files in `~/.cache/emacs` but decided that +# it was a Sisyphean task. Instead, we make `.gitignore` everything but the +# actual configuration files. + +* +!/.gitignore +!/early-init.el +!/init.el diff --git a/config/emacs/early-init.el b/config/emacs/early-init.el index fda615f..bf76d4b 100644 --- a/config/emacs/early-init.el +++ b/config/emacs/early-init.el @@ -1,19 +1,13 @@ -;;; -*- lexical-binding: t -*- +;;; early-init.el --- Emacs early initialization -*- lexical-binding: t -*- -;; Go VROOM-VROOM -(setq gc-cons-threshold 10000000) +;;; Commentary: -;; Setup the cache directory nice and early; we use it everywhere -(make-directory "~/.cache/emacs" t) +;; Early initialization configuration. Right now, it just increases +;; the `gc-cons-threshold' in order to speed up initialization. -;; Configure package.el directories -(setq - package-user-dir "~/.cache/emacs/elpa/" - package-gnupghome-dir "~/.cache/emacs/elpa/gnupg") +;;; Code: -;; Configure native-comp cache direactory -(when (boundp 'native-comp-eln-load-path) - (startup-redirect-eln-cache "~/.cache/emacs/eln-cache")) +(setq gc-cons-threshold 104857600) -;; Suppress native-comp warnings on startup -(setq warning-suppress-log-types '((comp) (bytecomp))) +(provide 'early-init) +;;; early-init.el ends here diff --git a/config/emacs/flavours/development.el b/config/emacs/flavours/development.el deleted file mode 100644 index 26ca23e..0000000 --- a/config/emacs/flavours/development.el +++ /dev/null @@ -1,91 +0,0 @@ -;;; -*- lexical-binding: t -*- - -;;; -;;; General -;;; - -(use-package copilot - :custom - (copilot-install-dir "~/.cache/emacs/copilot") - :bind (("C-<tab>" . copilot-accept-completion) - ("C-M-<tab>" . copilot-accept-completion-by-word) - ("C-c a a" . copilot-mode) - ("C-c a n" . copilot-next-completion) - ("C-c a p" . copilot-previous-completion))) - -(use-package eglot - :ensure nil - :bind - (:map eglot-mode-map - ("M-q" . eglot-format))) - -(use-package ligature - :hook - (prog-mode . ligature-mode) - :config - (ligature-set-ligatures - 'prog-mode - '(;; Group A - ".." ".=" "..." "..<" "::" ":::" ":=" "::=" ";;" ";;;" "??" "???" ".?" "?." - ":?" "?:" "?=" "**" "***" "/*" "*/" "/**" - ;; Group B - "<-" "->" "-<" ">-" "<--" "-->" "<<-" "->>" "-<<" ">>-" "<-<" ">->" "<-|" - "|->" "-|" "|-" "||-" "<!--" "<#--" "<=" "=>" ">=" "<==" "==>" "<<=" "=>>" - "=<<" ">>=" "<=<" ">=>" "<=|" "|=>" "<=>" "<==>" "||=" "|=" "//=" "/=" - "/==" - ;; Group C - "<<" ">>" "<<<" ">>>" "<>" "<$" "$>" "<$>" "<+" "+>" "<+>" "<:" ":<" "<:<" - ">:" ":>" "<~" "~>" "<~>" "<<~" "<~~" "~~>" "~~" "<|" "|>" "<|>" "<||" - "||>" "<|||" "|||>" "</" "/>" "</>" "<*" "*>" "<*>" ":?>" - ;; Group D - "#(" "#{" "#[" "]#" "#!" "#?" "#=" "#_" "#_(" "##" "###" "####" - ;; Group E - "[|" "|]" "[<" ">]" "{!!" "!!}" "{|" "|}" "{{" "}}" "{{--" "--}}" "{!--" - "//" "///" "!!" - ;; Group F - "www" "@_" "&&" "&&&" "&=" "~@" "++" "+++" "/\\" "\\/" "_|_" "||" - ;; Group G - "=:" "=:=" "=!=" "==" "===" "=/=" "=~" "~-" "^=" "__" "!=" "!==" "-~" "--" - "---"))) - -(use-package magit - :custom - (transient-levels-file "~/.cache/emacs/transient/levels.el") - (transient-values-file "~/.cache/emacs/transient/values.el") - (transient-history-file "~/.cache/emacs/transient/history.el")) - -(use-package markdown-mode - :hook - (gfm-mode . flyspell-mode) - (gfm-mode . visual-line-mode) - :init - (add-to-list 'major-mode-remap-alist '(markdown-mode . gfm-mode))) - -(use-package projectile - :bind-keymap - ("C-c p" . projectile-command-map) - :custom - (projectile-known-projects-file "~/.cache/emacs/projectile-bookmarks.eld") - (projectile-project-search-path '(("~/Developer/" . 2))) - :config - (projectile-mode +1)) - -(use-package rg) - -;;; -;;; Docker -;;; - -(use-package dockerfile-mode) - -;;; -;;; Ocaml -;;; - -(use-package tuareg) - -(use-package ocaml-eglot - :after (tuareg) - :hook - (tuareg-mode . ocaml-eglot) - (ocaml-eglot . eglot-ensure)) diff --git a/config/emacs/flavours/macos.el b/config/emacs/flavours/macos.el deleted file mode 100644 index 463eec1..0000000 --- a/config/emacs/flavours/macos.el +++ /dev/null @@ -1,3 +0,0 @@ -(use-package exec-path-from-shell - :config - (exec-path-from-shell-initialize)) diff --git a/config/emacs/init.el b/config/emacs/init.el index 4f56d56..3324325 100644 --- a/config/emacs/init.el +++ b/config/emacs/init.el @@ -1,6 +1,12 @@ -;;; -*- lexical-binding: t -*- +;;; init.el --- Emacs initialization -*- lexical-binding: t -*- + +;;; Commentary: + +;; Emacs initialization file. Contains my personal and evolving Emacs +;; configuration - what a rabbit hole! + +;;; TODO: -;;; TODO(nlordell): ;; 1. Emacs over TRAMP with `flatpak-spawn --host podman` ;; <https://happihacking.com/blog/posts/2023/dev-containers-emacs/> ;; 2. Setup LLM coding: gptel, aidermacs @@ -8,7 +14,11 @@ ;; 4. Take some stuff from Emacs NANO ;; <https://github.com/rougier/nano-emacs> -(defcustom system-flavour 'plain +;;; Code: + +;;; -- Customizations -- + +(defcustom init/system-flavour 'plain "The flavour of system. Allows initialization and customization differentiation with a @@ -17,18 +27,198 @@ (const :tag "Development" development)) :group 'convenience) -(defun init/load (name &rest kargs) - "Loads an init file." - (let* ((init-directory (file-name-directory (or load-file-name (buffer-file-name)))) - (file-name (file-name-concat init-directory name)) - (is-optional (plist-get kargs :optional)) - (should-load (or (not is-optional) (file-exists-p file-name)))) - (when should-load - (load file-name nil t)))) - -(init/load "sanemacs.el") -(when (eq system-flavour 'development) - (init/load "flavours/development.el")) -(when (eq system-type 'darwin) - (init/load "flavours/macos.el")) -(init/load "local-init.el" :optional t) +;;; -- Utility Functions -- + +(defun init/expand-file-name (name) + "Expands file NAME relative to the `user-emacs-directory'." + (expand-file-name name user-emacs-directory)) + +(defun init/show-trailing-whitespace () + "Show trailing whitespace for the current buffer." + (setq show-trailing-whitespace t)) + +(defun init/open-init () + "Opens the Emacs init.el configuration file." + (interactive) + (find-file (init/expand-file-name "init.el"))) + +(defun init/open-local-init () + "Opens the system-specific configuration file." + (interactive) + (find-file custom-file)) + +;;; -- Emacs Configuration -- + +;; Mostly adapted from `sanemacs.el', and ported to a `use-package' +;; section. + +(use-package emacs + :hook ((prog-mode . completion-preview-mode) + (prog-mode . display-line-numbers-mode) + (prog-mode . init/show-trailing-whitespace) + (before-safe . delete-trailing-whitespace)) + :bind (("C-c ," . init/open-local-init) + ("C-c C-," . init/open-init) + ("C-x k" . kill-current-buffer) + ("M-/" . hippie-expand)) + :init + (menu-bar-mode -1) + (tool-bar-mode -1) + (scroll-bar-mode -1) + (which-key-mode +1) + (column-number-mode +1) + (delete-selection-mode +1) + (global-auto-revert-mode +1) + (load-theme 'modus-vivendi) + (load (init/expand-file-name "local-init.el") t t) + :custom + (use-short-answers t) + (inhibit-startup-screen t) + (initial-scratch-message "") + (frame-title-format '("%b")) + (ring-bell-function 'ignore) + (sentence-end-double-space nil) + (cursor-type 'bar) + (indent-tabs-mode nil) + (tab-width 2) + (backup-by-copying t) + (backup-directory-alist `((".*" . ,(init/expand-file-name "backup")))) + (create-lockfiles nil) + (tab-width 4) + (custom-file (init/expand-file-name "local-init.el"))) + +;;; -- Packages -- + +;; Enable MELPA, but make it a lower priority to GNU and non-GNU ELPA +;; repositories. This makes it so we fallback to MELPA when there are +;; no stable versions on the official ELPA repositories. + +(use-package package + :custom + (package-archives '(("gnu" . "https://elpa.gnu.org/packages/") + ("nongnu" . "https://elpa.nongnu.org/nongnu/") + ("melpa" . "https://melpa.org/packages/"))) + (package-archive-priorities '(("gnu" . 1) + ("nongnu" . 1) + ("melpa" . 0)))) + +;;; -- Prelude -- + +;; Some useful packages taken from `prelude.el' that just generally +;; enhance Emacs editing. + +(use-package ace-window + :ensure t + :bind (("C-x o" . ace-window))) + +(use-package avy + :ensure t + :bind (("C-:" . avy-goto-char) + ("M-g f" . avy-goto-line))) + +(use-package exec-path-from-shell + :if (eq system-type 'darwin) + :ensure t + :init + (exec-path-from-shell-initialize)) + +(use-package undo-tree + :ensure t + :init + (global-undo-tree-mode +1) + :custom + (undo-tree-auto-save-history nil)) + +;;; -- LLM -- + +(use-package copilot + :ensure t + :bind (("C-<tab>" . copilot-accept-completion) + ("C-M-<tab>" . copilot-accept-completion-by-word) + ("C-c a a" . copilot-mode) + ("C-c a n" . copilot-next-completion) + ("C-c a p" . copilot-previous-completion))) + +;;; -- General Development -- + +(use-package ligature + :if (eq init/system-flavour 'development) + :ensure t + :hook + (prog-mode . ligature-mode) + :config + (ligature-set-ligatures + 'prog-mode + '(;; Group A + ".." ".=" "..." "..<" "::" ":::" ":=" "::=" ";;" ";;;" "??" "???" ".?" "?." + ":?" "?:" "?=" "**" "***" "/*" "*/" "/**" + ;; Group B + "<-" "->" "-<" ">-" "<--" "-->" "<<-" "->>" "-<<" ">>-" "<-<" ">->" "<-|" + "|->" "-|" "|-" "||-" "<!--" "<#--" "<=" "=>" ">=" "<==" "==>" "<<=" "=>>" + "=<<" ">>=" "<=<" ">=>" "<=|" "|=>" "<=>" "<==>" "||=" "|=" "//=" "/=" + "/==" + ;; Group C + "<<" ">>" "<<<" ">>>" "<>" "<$" "$>" "<$>" "<+" "+>" "<+>" "<:" ":<" "<:<" + ">:" ":>" "<~" "~>" "<~>" "<<~" "<~~" "~~>" "~~" "<|" "|>" "<|>" "<||" + "||>" "<|||" "|||>" "</" "/>" "</>" "<*" "*>" "<*>" ":?>" + ;; Group D + "#(" "#{" "#[" "]#" "#!" "#?" "#=" "#_" "#_(" "##" "###" "####" + ;; Group E + "[|" "|]" "[<" ">]" "{!!" "!!}" "{|" "|}" "{{" "}}" "{{--" "--}}" "{!--" + "//" "///" "!!" + ;; Group F + "www" "@_" "&&" "&&&" "&=" "~@" "++" "+++" "/\\" "\\/" "_|_" "||" + ;; Group G + "=:" "=:=" "=!=" "==" "===" "=/=" "=~" "~-" "^=" "__" "!=" "!==" "-~" "--" + "---"))) + +(use-package magit + :if (eq init/system-flavour 'development) + :ensure t + :bind (("C-x g" . magit-status))) + +(use-package projectile + :if (eq init/system-flavour 'development) + :ensure t + :bind-keymap ("C-c p" . projectile-command-map) + :custom + (projectile-project-search-path '(("~/Developer/" . 2))) + :config + (projectile-mode +1)) + +(use-package rg + :if (eq init/system-flavour 'development) + :ensure t) + +;;; -- Miscellaneous -- + +(use-package markdown-mode + :if (eq init/system-flavour 'development) + :ensure t + :hook + (gfm-mode . flyspell-mode) + (gfm-mode . visual-line-mode) + :init + (add-to-list 'major-mode-remap-alist '(markdown-mode . gfm-mode))) + +(use-package dockerfile-mode + :if (eq init/system-flavour 'development) + :ensure t) + +;;; -- OCaml -- + +(use-package tuareg + :if (eq init/system-flavour 'development) + :ensure t) + +(use-package ocaml-eglot + :if (eq init/system-flavour 'development) + :ensure t + :after (tuareg) + :bind (("M-q" . eglot-format)) + :hook + (tuareg-mode . ocaml-eglot) + (ocaml-eglot . eglot-ensure)) + +(provide 'init) +;;; init.el ends here. |
