Commit a62a29f3e06f
Changed files (1)
tools
emacs
tools/emacs/prot-init.el
@@ -0,0 +1,170 @@
+;; From https://protesilaos.com/codelog/2024-11-28-basic-emacs-configuration/
+;; For inspiration
+(setq custom-file (locate-user-emacs-file "custom.el"))
+(load custom-file :no-error-if-file-is-missing)
+
+;;; Set up the package manager
+
+(require 'package)
+(package-initialize)
+
+(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
+
+(when (< emacs-major-version 29)
+ (unless (package-installed-p 'use-package)
+ (unless package-archive-contents
+ (package-refresh-contents))
+ (package-install 'use-package)))
+
+(add-to-list 'display-buffer-alist
+ '("\\`\\*\\(Warnings\\|Compile-Log\\)\\*\\'"
+ (display-buffer-no-window)
+ (allow-no-window . t)))
+
+;;; Basic behaviour
+
+(use-package delsel
+ :ensure nil
+ :hook (after-init . delete-selection-mode))
+
+(defun prot/keyboard-quit-dwim ()
+ "Do-What-I-Mean behaviour for a general `keyboard-quit'.
+
+The generic `keyboard-quit' does not do the expected thing when
+the minibuffer is open. Whereas we want it to close the
+minibuffer, even without explicitly focusing it.
+
+The DWIM behaviour of this command is as follows:
+
+- When the region is active, disable it.
+- When a minibuffer is open, but not focused, close the minibuffer.
+- When the Completions buffer is selected, close it.
+- In every other case use the regular `keyboard-quit'."
+ (interactive)
+ (cond
+ ((region-active-p)
+ (keyboard-quit))
+ ((derived-mode-p 'completion-list-mode)
+ (delete-completion-window))
+ ((> (minibuffer-depth) 0)
+ (abort-recursive-edit))
+ (t
+ (keyboard-quit))))
+
+(define-key global-map (kbd "C-g") #'prot/keyboard-quit-dwim)
+
+;;; Tweak the looks of Emacs
+
+;; Those three belong in the early-init.el, but I am putting them here
+;; for convenience. If the early-init.el exists in the same directory
+;; as the init.el, then Emacs will read+evaluate it before moving to
+;; the init.el.
+(menu-bar-mode 1)
+(scroll-bar-mode 1)
+(tool-bar-mode -1)
+
+(let ((mono-spaced-font "Monospace")
+ (proportionately-spaced-font "Sans"))
+ (set-face-attribute 'default nil :family mono-spaced-font :height 100)
+ (set-face-attribute 'fixed-pitch nil :family mono-spaced-font :height 1.0)
+ (set-face-attribute 'variable-pitch nil :family proportionately-spaced-font :height 1.0))
+
+(use-package modus-themes
+ :ensure t
+ :config
+ (load-theme 'modus-vivendi-tinted :no-confirm-loading))
+
+;; Remember to do M-x and run `nerd-icons-install-fonts' to get the
+;; font files. Then restart Emacs to see the effect.
+(use-package nerd-icons
+ :ensure t)
+
+(use-package nerd-icons-completion
+ :ensure t
+ :after marginalia
+ :config
+ (add-hook 'marginalia-mode-hook #'nerd-icons-completion-marginalia-setup))
+
+(use-package nerd-icons-corfu
+ :ensure t
+ :after corfu
+ :config
+ (add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter))
+
+(use-package nerd-icons-dired
+ :ensure t
+ :hook
+ (dired-mode . nerd-icons-dired-mode))
+
+;;; Configure the minibuffer and completions
+
+(use-package vertico
+ :ensure t
+ :hook (after-init . vertico-mode))
+
+(use-package marginalia
+ :ensure t
+ :hook (after-init . marginalia-mode))
+
+(use-package orderless
+ :ensure t
+ :config
+ (setq completion-styles '(orderless basic))
+ (setq completion-category-defaults nil)
+ (setq completion-category-overrides nil))
+
+(use-package savehist
+ :ensure nil ; it is built-in
+ :hook (after-init . savehist-mode))
+
+(use-package corfu
+ :ensure t
+ :hook (after-init . global-corfu-mode)
+ :bind (:map corfu-map ("<tab>" . corfu-complete))
+ :config
+ (setq tab-always-indent 'complete)
+ (setq corfu-preview-current nil)
+ (setq corfu-min-width 20)
+
+ (setq corfu-popupinfo-delay '(1.25 . 0.5))
+ (corfu-popupinfo-mode 1) ; shows documentation after `corfu-popupinfo-delay'
+
+ ;; Sort by input history (no need to modify `corfu-sort-function').
+ (with-eval-after-load 'savehist
+ (corfu-history-mode 1)
+ (add-to-list 'savehist-additional-variables 'corfu-history)))
+
+;;; The file manager (Dired)
+
+(use-package dired
+ :ensure nil
+ :commands (dired)
+ :hook
+ ((dired-mode . dired-hide-details-mode)
+ (dired-mode . hl-line-mode))
+ :config
+ (setq dired-recursive-copies 'always)
+ (setq dired-recursive-deletes 'always)
+ (setq delete-by-moving-to-trash t)
+ (setq dired-dwim-target t))
+
+(use-package dired-subtree
+ :ensure t
+ :after dired
+ :bind
+ ( :map dired-mode-map
+ ("<tab>" . dired-subtree-toggle)
+ ("TAB" . dired-subtree-toggle)
+ ("<backtab>" . dired-subtree-remove)
+ ("S-TAB" . dired-subtree-remove))
+ :config
+ (setq dired-subtree-use-backgrounds nil))
+
+(use-package trashed
+ :ensure t
+ :commands (trashed)
+ :config
+ (setq trashed-action-confirmer 'y-or-n-p)
+ (setq trashed-use-header-line t)
+ (setq trashed-sort-key '("Date deleted" . t))
+ (setq trashed-date-format "%Y-%m-%d %H:%M:%S"))