system-manager-wakasu
1;; From https://protesilaos.com/codelog/2024-11-28-basic-emacs-configuration/
2;; For inspiration
3(setq custom-file (locate-user-emacs-file "custom.el"))
4(load custom-file :no-error-if-file-is-missing)
5
6;;; Set up the package manager
7
8(require 'package)
9(package-initialize)
10
11(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
12
13(when (< emacs-major-version 29)
14 (unless (package-installed-p 'use-package)
15 (unless package-archive-contents
16 (package-refresh-contents))
17 (package-install 'use-package)))
18
19(add-to-list 'display-buffer-alist
20 '("\\`\\*\\(Warnings\\|Compile-Log\\)\\*\\'"
21 (display-buffer-no-window)
22 (allow-no-window . t)))
23
24;;; Basic behaviour
25
26(use-package delsel
27 :ensure nil
28 :hook (after-init . delete-selection-mode))
29
30(defun prot/keyboard-quit-dwim ()
31 "Do-What-I-Mean behaviour for a general `keyboard-quit'.
32
33The generic `keyboard-quit' does not do the expected thing when
34the minibuffer is open. Whereas we want it to close the
35minibuffer, even without explicitly focusing it.
36
37The DWIM behaviour of this command is as follows:
38
39- When the region is active, disable it.
40- When a minibuffer is open, but not focused, close the minibuffer.
41- When the Completions buffer is selected, close it.
42- In every other case use the regular `keyboard-quit'."
43 (interactive)
44 (cond
45 ((region-active-p)
46 (keyboard-quit))
47 ((derived-mode-p 'completion-list-mode)
48 (delete-completion-window))
49 ((> (minibuffer-depth) 0)
50 (abort-recursive-edit))
51 (t
52 (keyboard-quit))))
53
54(define-key global-map (kbd "C-g") #'prot/keyboard-quit-dwim)
55
56;;; Tweak the looks of Emacs
57
58;; Those three belong in the early-init.el, but I am putting them here
59;; for convenience. If the early-init.el exists in the same directory
60;; as the init.el, then Emacs will read+evaluate it before moving to
61;; the init.el.
62(menu-bar-mode 1)
63(scroll-bar-mode 1)
64(tool-bar-mode -1)
65
66(let ((mono-spaced-font "Monospace")
67 (proportionately-spaced-font "Sans"))
68 (set-face-attribute 'default nil :family mono-spaced-font :height 100)
69 (set-face-attribute 'fixed-pitch nil :family mono-spaced-font :height 1.0)
70 (set-face-attribute 'variable-pitch nil :family proportionately-spaced-font :height 1.0))
71
72(use-package modus-themes
73 :ensure t
74 :config
75 (load-theme 'modus-vivendi-tinted :no-confirm-loading))
76
77;; Remember to do M-x and run `nerd-icons-install-fonts' to get the
78;; font files. Then restart Emacs to see the effect.
79(use-package nerd-icons
80 :ensure t)
81
82(use-package nerd-icons-completion
83 :ensure t
84 :after marginalia
85 :config
86 (add-hook 'marginalia-mode-hook #'nerd-icons-completion-marginalia-setup))
87
88(use-package nerd-icons-corfu
89 :ensure t
90 :after corfu
91 :config
92 (add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter))
93
94(use-package nerd-icons-dired
95 :ensure t
96 :hook
97 (dired-mode . nerd-icons-dired-mode))
98
99;;; Configure the minibuffer and completions
100
101(use-package vertico
102 :ensure t
103 :hook (after-init . vertico-mode))
104
105(use-package marginalia
106 :ensure t
107 :hook (after-init . marginalia-mode))
108
109(use-package orderless
110 :ensure t
111 :config
112 (setq completion-styles '(orderless basic))
113 (setq completion-category-defaults nil)
114 (setq completion-category-overrides nil))
115
116(use-package savehist
117 :ensure nil ; it is built-in
118 :hook (after-init . savehist-mode))
119
120(use-package corfu
121 :ensure t
122 :hook (after-init . global-corfu-mode)
123 :bind (:map corfu-map ("<tab>" . corfu-complete))
124 :config
125 (setq tab-always-indent 'complete)
126 (setq corfu-preview-current nil)
127 (setq corfu-min-width 20)
128
129 (setq corfu-popupinfo-delay '(1.25 . 0.5))
130 (corfu-popupinfo-mode 1) ; shows documentation after `corfu-popupinfo-delay'
131
132 ;; Sort by input history (no need to modify `corfu-sort-function').
133 (with-eval-after-load 'savehist
134 (corfu-history-mode 1)
135 (add-to-list 'savehist-additional-variables 'corfu-history)))
136
137;;; The file manager (Dired)
138
139(use-package dired
140 :ensure nil
141 :commands (dired)
142 :hook
143 ((dired-mode . dired-hide-details-mode)
144 (dired-mode . hl-line-mode))
145 :config
146 (setq dired-recursive-copies 'always)
147 (setq dired-recursive-deletes 'always)
148 (setq delete-by-moving-to-trash t)
149 (setq dired-dwim-target t))
150
151(use-package dired-subtree
152 :ensure t
153 :after dired
154 :bind
155 ( :map dired-mode-map
156 ("<tab>" . dired-subtree-toggle)
157 ("TAB" . dired-subtree-toggle)
158 ("<backtab>" . dired-subtree-remove)
159 ("S-TAB" . dired-subtree-remove))
160 :config
161 (setq dired-subtree-use-backgrounds nil))
162
163(use-package trashed
164 :ensure t
165 :commands (trashed)
166 :config
167 (setq trashed-action-confirmer 'y-or-n-p)
168 (setq trashed-use-header-line t)
169 (setq trashed-sort-key '("Date deleted" . t))
170 (setq trashed-date-format "%Y-%m-%d %H:%M:%S"))