* .emacs.d/init.el: Small cleanups.
[~bandali/configs] / .emacs.d / init.el
CommitLineData
33b1a7ea 1;;; init.el --- bandali's emacs configuration -*- lexical-binding: t -*-
41d290a2 2
78d731e1 3;; Copyright (C) 2018-2022 Amin Bandali <bandali@gnu.org>
41d290a2
AB
4
5;; This program is free software: you can redistribute it and/or modify
6;; it under the terms of the GNU General Public License as published by
7;; the Free Software Foundation, either version 3 of the License, or
8;; (at your option) any later version.
9
10;; This program is distributed in the hope that it will be useful,
11;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13;; GNU General Public License for more details.
14
15;; You should have received a copy of the GNU General Public License
16;; along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18;;; Commentary:
19
9867e4bb
AB
20;; GNU Emacs configuration of bandali, free software activist,
21;; computing scientist, and GNU maintainer and volunteer.
b57457b2
AB
22
23;; Over the years, I've taken inspiration from configurations of many
24;; great people. Some that I can remember off the top of my head are:
25;;
26;; - https://github.com/dieggsy/dotfiles
27;; - https://github.com/dakra/dmacs
28;; - http://pages.sachachua.com/.emacs.d/Sacha.html
29;; - https://github.com/dakrone/eos
30;; - http://doc.rix.si/cce/cce.html
31;; - https://github.com/jwiegley/dot-emacs
32;; - https://github.com/wasamasa/dotemacs
33;; - https://github.com/hlissner/doom-emacs
41d290a2 34
49e9503b
AB
35;;; Code:
36
b57457b2
AB
37;;; Emacs initialization
38
dca50cf5 39(defvar b/before-user-init-time (current-time)
41d290a2 40 "Value of `current-time' when Emacs begins loading `user-init-file'.")
83364e5b
AB
41(defvar b/emacs-initialized nil
42 "Whether Emacs has been initialized.")
43
44(when (not (bound-and-true-p b/emacs-initialized))
45 (message "Loading Emacs...done (%.3fs)"
46 (float-time (time-subtract b/before-user-init-time
47 before-init-time))))
41d290a2 48
b57457b2
AB
49;; temporarily increase `gc-cons-threshhold' and `gc-cons-percentage'
50;; during startup to reduce garbage collection frequency. clearing
51;; `file-name-handler-alist' seems to help reduce startup time too.
dca50cf5
AB
52(defvar b/gc-cons-threshold gc-cons-threshold)
53(defvar b/gc-cons-percentage gc-cons-percentage)
54(defvar b/file-name-handler-alist file-name-handler-alist)
bc58e70a 55(setq gc-cons-threshold (* 30 1024 1024) ; 30 MiB
41d290a2
AB
56 gc-cons-percentage 0.6
57 file-name-handler-alist nil
58 ;; sidesteps a bug when profiling with esup
59 esup-child-profile-require-level 0)
60
b57457b2 61;; set them back to their defaults once we're done initializing
dca50cf5 62(defun b/post-init ()
83364e5b
AB
63 "My post-initialize function, run after loading `user-init-file'."
64 (setq b/emacs-initialized t
65 gc-cons-threshold b/gc-cons-threshold
66 gc-cons-percentage b/gc-cons-percentage
e8a3b8f7 67 file-name-handler-alist b/file-name-handler-alist)
c84be134 68 (when (featurep 'exwm-workspace)
8b1a2f32
AB
69 (with-eval-after-load 'exwm-workspace
70 (setq-default
71 mode-line-format
72 (append
73 mode-line-format
74 '((:eval
75 (format
76 "[%s]" (number-to-string
8c4704d0 77 exwm-workspace-current-index))))))))
9867e4bb
AB
78 (when (version< emacs-version "28")
79 ;; manually make some mode-line spaces smaller
80 ;; (version<= "28" emacs-version) can do an awesome job at this
81 ;; out of the box if `mode-line-compact' is set to t (see below)
82 (setq-default
83 mode-line-format
84 (mapcar
85 (lambda (x)
86 (if (and (stringp x)
87 (or (string= x " ")
88 (string= x " ")))
89 " "
90 x))
91 mode-line-format)
92 mode-line-buffer-identification
93 (propertized-buffer-identification "%10b"))))
dca50cf5 94(add-hook 'after-init-hook #'b/post-init)
41d290a2 95
b57457b2 96;; increase number of lines kept in *Messages* log
41d290a2
AB
97(setq message-log-max 20000)
98
b57457b2
AB
99\f
100;;; whoami
101
5e1c3722 102(setq user-full-name "Amin Bandali"
33b1a7ea 103 user-mail-address "bandali@gnu.org")
41d290a2 104
b57457b2 105\f
33273849
AB
106;;; Package management
107
8c4704d0
AB
108;; variables of interest:
109;; package-archive-priorities
110;; package-load-list
111;; package-pinned-packages
112
113;; (let* ((b (find-file-noselect "refinery-theme.el"))
114;; (d (with-current-buffer b (package-buffer-info))))
115;; (package-generate-description-file d "refinery-theme-pkg.el"))
116(run-with-idle-timer 0.01 nil #'require 'package)
117(with-eval-after-load 'package
78d731e1 118 ;; (setq
5e1c3722
AB
119 ;; ;; package-archives
120 ;; ;; `(,@package-archives
121 ;; ;; ("bndl" . "https://p.bndl.org/elpa/"))
122 ;; package-load-list
123 ;; '(;; GNU ELPA
124 ;; (debbugs "0.29")
125 ;; (delight "1.7")
126 ;; (emms "7.7")
127 ;; (expand-region "0.11.0")
128 ;; (rt-liberation "2.4")
129 ;; (yasnippet "0.14.0")))
12e6cf3c 130(package-initialize))
8c4704d0 131
78d731e1 132(setq package-archive-upload-base "/ssh:caffeine:~/www/p/elpa")
41d290a2 133
b57457b2
AB
134\f
135;;; Initial setup
136
137;; keep ~/.emacs.d clean
0596e3cf
AB
138(defvar b/etc-dir
139 (expand-file-name
140 (convert-standard-filename "etc/") user-emacs-directory)
141 "The directory where packages place their configuration files.")
142(defvar b/var-dir
143 (expand-file-name
144 (convert-standard-filename "var/") user-emacs-directory)
145 "The directory where packages place their persistent data files.")
8c4704d0
AB
146(defvar b/lisp-dir
147 (expand-file-name
148 (convert-standard-filename "lisp/") user-emacs-directory)
149 "The directory where packages place their persistent data files.")
0596e3cf
AB
150(defun b/etc (file)
151 "Expand filename FILE relative to `b/etc-dir'."
152 (expand-file-name (convert-standard-filename file) b/etc-dir))
153(defun b/var (file)
154 "Expand filename FILE relative to `b/var-dir'."
155 (expand-file-name (convert-standard-filename file) b/var-dir))
8c4704d0
AB
156(defun b/lisp (file)
157 "Expand filename FILE relative to `b/lisp-dir'."
158 (expand-file-name (convert-standard-filename file) b/lisp-dir))
0596e3cf 159
78d731e1 160(setq
0596e3cf
AB
161 auto-save-list-file-prefix (b/var "auto-save/sessions/")
162 nsm-settings-file (b/var "nsm-settings.el"))
c84be134 163
b57457b2 164;; separate custom file (don't want it mixing with init.el)
c84be134 165(with-eval-after-load 'custom
dca50cf5 166 (setq custom-file (b/etc "custom.el"))
41d290a2
AB
167 (when (file-exists-p custom-file)
168 (load custom-file))
b57457b2 169 ;; while at it, treat themes as safe
8c4704d0 170 ;; (setf custom-safe-themes t)
60ff805e 171 ;; only one custom theme at a time
927b50b7
AB
172 ;; (defadvice load-theme (before clear-previous-themes activate)
173 ;; "Clear existing theme settings instead of layering them"
174 ;; (mapc #'disable-theme custom-enabled-themes))
175 )
41d290a2 176
b57457b2 177;; load the secrets file if it exists, otherwise show a warning
927b50b7
AB
178;; (with-demoted-errors
179;; (load (b/etc "secrets")))
41d290a2 180
b57457b2
AB
181;; start up emacs server. see
182;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server
c84be134
AB
183(run-with-idle-timer 0.5 nil #'require 'server)
184(with-eval-after-load 'server
2087ae39 185 (declare-function server-edit "server")
0596e3cf 186 (global-set-key (kbd "C-c F D") #'server-edit)
2087ae39
AB
187 (declare-function server-running-p "server")
188 (or (server-running-p) (server-mode)))
41d290a2 189
60ff805e 190\f
60ff805e
AB
191;;; Defaults
192
193;;;; C-level customizations
194
78d731e1 195(setq
52b7a57a 196 ;; line-spacing 3
9867e4bb 197 completion-ignore-case t
87631bd0 198 read-buffer-completion-ignore-case t
60ff805e
AB
199 enable-recursive-minibuffers t
200 resize-mini-windows t
9867e4bb 201 mode-line-compact t
2176627c
AB
202 ;; mouse-autoselect-window t
203 scroll-preserve-screen-position 1
9867e4bb
AB
204 ;; i don't feel like jumping out of my chair every now and again;
205 ;; so...don't *BEEP* at me, emacs =)
2176627c 206 ring-bell-function 'ignore)
60ff805e
AB
207
208(setq-default
7682baf8
AB
209 ;; case-sensitive search (and `dabbrev-expand')
210 ;; case-fold-search nil
9867e4bb
AB
211 ;; always use space for indentation
212 indent-tabs-mode nil
213 tab-width 4)
60ff805e 214
52b7a57a
AB
215(when (display-graphic-p)
216 (set-fontset-font t 'arabic "Vazir"))
217;; ;; (set-frame-font "Drafting Mono-14:weight=light" nil t)
218;; (set-frame-font "Drafting Mono:pixelsize=16" nil t)
219;; (set-face-attribute 'bold nil :weight 'semi-bold)
7c558c9b 220
60ff805e 221;;;; Elisp-level customizations
41d290a2 222
adba94a7
AB
223;; (define-key minibuffer-local-completion-map
224;; "\t" #'minibuffer-force-complete)
225
9867e4bb 226;; (with-eval-after-load 'icomplete
adba94a7 227
9867e4bb 228;; (setq icomplete-on-del-error-function #'abort-recursive-edit)
adba94a7 229
9867e4bb
AB
230;; (defun b/icomplete-fido-backward-updir ()
231;; "Delete char before or go up directory, like `ido-mode'."
232;; (interactive)
233;; (if (and (eq (char-before) ?/)
234;; (eq (icomplete--category) 'file))
235;; (save-excursion
236;; (goto-char (1- (point)))
237;; (when (search-backward "/" (point-min) t)
238;; (delete-region (1+ (point)) (point-max))))
239;; (condition-case nil
240;; (call-interactively #'delete-backward-char)
241;; (error
242;; (when icomplete-on-del-error-function
243;; (funcall icomplete-on-del-error-function))))))
244
245;; (define-key icomplete-fido-mode-map
246;; (kbd "DEL") #'b/icomplete-fido-backward-updir))
247
78d731e1
AB
248;; subr
249;; (keyboard-translate ?\( ?\[)
250;; (keyboard-translate ?\) ?\])
251;; (keyboard-translate ?\[ ?\()
252;; (keyboard-translate ?\] ?\))
adba94a7 253
87631bd0 254;; minibuffer
78d731e1 255(setq read-file-name-completion-ignore-case t)
87631bd0 256
c84be134
AB
257;; startup
258;; don't need to see the startup echo area message
259(advice-add #'display-startup-echo-area-message :override #'ignore)
78d731e1 260(setq
c84be134
AB
261 ;; i want *scratch* as my startup buffer
262 initial-buffer-choice t
263 ;; i don't need the default hint
264 initial-scratch-message nil
265 ;; use customizable text-mode as major mode for *scratch*
266 ;; (initial-major-mode 'text-mode)
267 ;; inhibit buffer list when more than 2 files are loaded
268 inhibit-startup-buffer-menu t
269 ;; don't need to see the startup screen or echo area message
270 inhibit-startup-screen t
271 inhibit-startup-echo-area-message user-login-name)
272
273;; files
78d731e1 274(setq
c84be134
AB
275 ;; backups (C-h v make-backup-files RET)
276 backup-by-copying t
0596e3cf 277 backup-directory-alist (list (cons "." (b/var "backup/")))
c84be134
AB
278 version-control t
279 delete-old-versions t
280 ;; auto-save
281 auto-save-file-name-transforms `((".*" ,(b/var "auto-save/") t))
282 ;; insert newline at the end of files
9867e4bb 283 ;; require-final-newline t
c84be134
AB
284 ;; open read-only file buffers in view-mode
285 ;; (enables niceties like `q' for quit)
286 view-read-only t)
287
288;; novice
60ff805e 289;; disable disabled commands
78d731e1 290(setq disabled-command-function nil)
41d290a2 291
60ff805e
AB
292;; lazy-person-friendly yes/no prompts
293(defalias 'yes-or-no-p #'y-or-n-p)
b57457b2 294
8c4704d0 295;; autorevert: enable automatic reloading of changed buffers and files
78d731e1
AB
296(setq
297 ;; auto-revert-verbose nil
298 global-auto-revert-non-file-buffers nil)
8c4704d0
AB
299(require 'autorevert)
300(global-auto-revert-mode 1)
b57457b2
AB
301
302;; time and battery in mode-line
9867e4bb
AB
303(run-with-idle-timer 0.1 nil #'require 'time)
304(with-eval-after-load 'time
78d731e1 305 (setq
9867e4bb
AB
306 display-time-default-load-average nil
307 display-time-format " %a %b %-e %-l:%M%P"
308 display-time-mail-icon '(image :type xpm
309 :file "gnus/gnus-pointer.xpm"
310 :ascent center)
2698f1c3
AB
311 display-time-use-mail-icon t
312 zoneinfo-style-world-list
313 `(,@zoneinfo-style-world-list
314 ("Etc/UTC" "UTC")
315 ("Asia/Tehran" "Tehran")
316 ("Australia/Melbourne" "Melbourne")))
9867e4bb
AB
317 (display-time-mode))
318
319(run-with-idle-timer 0.1 nil #'require 'battery)
320(with-eval-after-load 'battery
78d731e1 321 (setq battery-mode-line-format " %p%% %t")
9867e4bb
AB
322 (display-battery-mode))
323
324;; (with-eval-after-load 'fringe
325;; ;; smaller fringe
326;; (fringe-mode '(3 . 1)))
c84be134 327
c84be134 328;; enable winner-mode (C-h f winner-mode RET)
9867e4bb 329(require 'winner)
c84be134
AB
330(winner-mode 1)
331
69ad7e36
AB
332(run-with-idle-timer 0.1 nil #'require 'windmove)
333(with-eval-after-load 'windmove
78d731e1 334 (setq windmove-wrap-around t)
69ad7e36
AB
335 (global-set-key (kbd "M-H") #'windmove-left)
336 (global-set-key (kbd "M-L") #'windmove-right)
337 (global-set-key (kbd "M-K") #'windmove-up)
338 (global-set-key (kbd "M-J") #'windmove-down))
339
c84be134 340(with-eval-after-load 'compile
60ff805e
AB
341 ;; don't display *compilation* buffer on success. based on
342 ;; https://stackoverflow.com/a/17788551, with changes to use `cl-letf'
343 ;; instead of the now obsolete `flet'.
dca50cf5 344 (defun b/compilation-finish-function (buffer outstr)
41d290a2
AB
345 (unless (string-match "finished" outstr)
346 (switch-to-buffer-other-window buffer))
347 t)
348
dca50cf5 349 (setq compilation-finish-functions #'b/compilation-finish-function)
41d290a2
AB
350
351 (require 'cl-macs)
352
353 (defadvice compilation-start
354 (around inhibit-display
355 (command &optional mode name-function highlight-regexp))
356 (if (not (string-match "^\\(find\\|grep\\)" command))
357 (cl-letf (((symbol-function 'display-buffer) #'ignore))
358 (save-window-excursion ad-do-it))
359 ad-do-it))
360 (ad-activate 'compilation-start))
361
c84be134 362;; isearch
78d731e1 363(setq
c84be134
AB
364 ;; allow scrolling in Isearch
365 isearch-allow-scroll t
9867e4bb 366 isearch-lazy-count t
c84be134
AB
367 ;; search for non-ASCII characters: i’d like non-ASCII characters such
368 ;; as ‘’“”«»‹›áⓐ𝒶 to be selected when i search for their ASCII
369 ;; counterpart. shoutout to
370 ;; http://endlessparentheses.com/new-in-emacs-25-1-easily-search-non-ascii-characters.html
371 search-default-mode #'char-fold-to-regexp)
372
373;; replace
60ff805e 374;; uncomment to extend the above behaviour to query-replace
78d731e1 375;; (setq replace-char-fold t)
c84be134
AB
376
377;; vc
378(global-set-key (kbd "C-x v C-=") #'vc-ediff)
379
380(with-eval-after-load 'vc-git
78d731e1
AB
381 (setq vc-git-print-log-follow t
382 vc-git-show-stash 0))
c84be134 383
78d731e1
AB
384(setq ediff-window-setup-function 'ediff-setup-windows-plain
385 ediff-split-window-function 'split-window-horizontally)
c84be134
AB
386(with-eval-after-load 'ediff
387 (add-hook 'ediff-after-quit-hook-internal #'winner-undo))
388
389;; face-remap
78d731e1 390(setq
c84be134
AB
391 ;; gentler font resizing
392 text-scale-mode-step 1.05)
393
394(run-with-idle-timer 0.4 nil #'require 'mwheel)
78d731e1
AB
395(setq mouse-wheel-scroll-amount '(1 ((shift) . 1)) ; one line at a time
396 mouse-wheel-progressive-speed nil ; don't accelerate scrolling
397 mouse-wheel-follow-mouse t) ; scroll window under mouse
c84be134
AB
398
399(run-with-idle-timer 0.4 nil #'require 'pixel-scroll)
400(with-eval-after-load 'pixel-scroll
401 (pixel-scroll-mode 1))
402
403;; epg-config
78d731e1 404(setq
c84be134
AB
405 epg-gpg-program (executable-find "gpg")
406 ;; ask for GPG passphrase in minibuffer
407 ;; this will fail if gpg>=2.1 is not available
408 epg-pinentry-mode 'loopback)
409
c84be134 410;; auth-source
78d731e1 411(setq
c84be134
AB
412 auth-sources '("~/.authinfo.gpg")
413 authinfo-hidden (regexp-opt '("password" "client-secret" "token")))
b98dbb3d 414
9867e4bb
AB
415;; info
416(with-eval-after-load 'info
78d731e1 417 (setq
966011a8
AB
418 Info-directory-list
419 `(,@Info-directory-list
420 ,(expand-file-name
421 (convert-standard-filename "info/") source-directory)
422 "/usr/share/info/")))
9867e4bb
AB
423
424;; faces
6ff057ac
AB
425(when (display-graphic-p)
426 (with-eval-after-load 'faces
2176627c
AB
427 (let ((grey "#e7e7e7"))
428 (set-face-attribute 'fixed-pitch nil :family "Source Code Pro")
6ff057ac 429 (set-face-attribute 'mode-line nil
2176627c
AB
430 :background grey
431 :inherit 'fixed-pitch))))
9867e4bb 432
b57457b2 433\f
927b50b7
AB
434;;; Useful utilities
435
436(defun b/add-elisp-section ()
437 (interactive)
438 (insert "\n")
439 (forward-line -1)
440 (insert "\n\f\n;;; "))
441
442(defun b/insert-asterism ()
443 "Insert a centred asterism."
444 (interactive)
445 (let ((asterism "* * *"))
446 (insert
447 (concat
448 "\n"
449 (make-string
450 (floor (/ (- fill-column (length asterism)) 2))
451 ?\s)
452 asterism
453 "\n"))))
454
455(defun b/start-process (program &rest args)
456 "Same as `start-process', but doesn't bother about name and buffer."
457 (let ((process-name (concat program "_process"))
458 (buffer-name (generate-new-buffer-name
459 (concat program "_output"))))
460 (apply #'start-process
461 process-name buffer-name program args)))
462
463(defun b/no-mouse-autoselect-window ()
464 "Conveniently disable `focus-follows-mouse'.
465For disabling the behaviour for certain buffers and/or modes."
466 (make-local-variable 'mouse-autoselect-window)
467 (setq mouse-autoselect-window nil))
468
469(defun b/kill-current-buffer ()
470 "Kill the current buffer."
471 ;; also see https://redd.it/64xb3q
472 (interactive)
473 (kill-buffer (current-buffer)))
474
475(defun b/move-indentation-or-beginning-of-line (arg)
476 "Move to the indentation or to the beginning of line."
477 (interactive "^p")
478 ;; (if (bolp)
479 ;; (back-to-indentation)
480 ;; (move-beginning-of-line arg))
481 (if (= (point)
482 (progn (back-to-indentation)
483 (point)))
484 (move-beginning-of-line arg)))
485
486(defun b/join-line-top ()
487 "Like `join-line', but join next line to the current line."
488 (interactive)
489 (join-line 1))
490
491(defun b/duplicate-line-or-region (&optional n)
492 "Duplicate the current line, or region (if active).
493Make N (default: 1) copies of the current line or region."
494 (interactive "*p")
495 (let ((u-r-p (use-region-p)) ; if region is active
496 (n1 (or n 1)))
497 (save-excursion
498 (let ((text
499 (if u-r-p
500 (buffer-substring (region-beginning) (region-end))
501 (prog1 (thing-at-point 'line)
502 (end-of-line)
503 (if (eobp)
504 (newline)
505 (forward-line 1))))))
506 (dotimes (_ (abs n1))
507 (insert text))))))
508
6cf7efb0
AB
509(defun b/invert-default-face ()
510 "Invert the `default' face (swap its background and foreground).
511Effectively a very simple light/dark theme toggle switch."
512 (interactive)
513 (invert-face 'default))
514
927b50b7 515\f
c84be134 516;;; General key bindings
b57457b2 517
c84be134
AB
518(global-set-key (kbd "C-a") #'b/move-indentation-or-beginning-of-line)
519(global-set-key (kbd "C-c a i") #'ielm)
520(global-set-key (kbd "C-c d") #'b/duplicate-line-or-region)
adba94a7 521(global-set-key (kbd "C-c j") #'b/join-line-top)
c84be134
AB
522(global-set-key (kbd "C-S-j") #'b/join-line-top)
523(global-set-key (kbd "C-c x") #'execute-extended-command)
6cf7efb0 524(global-set-key (kbd "C-c v") #'b/invert-default-face)
41d290a2 525
c84be134
AB
526;; evaling and macro-expanding
527(global-set-key (kbd "C-c e b") #'eval-buffer)
528(global-set-key (kbd "C-c e e") #'eval-last-sexp)
9867e4bb 529(global-set-key (kbd "C-c e m") #'pp-macroexpand-last-sexp)
c84be134 530(global-set-key (kbd "C-c e r") #'eval-region)
41d290a2 531
c84be134
AB
532;; emacs things
533(global-set-key (kbd "C-c e i") #'emacs-init-time)
534(global-set-key (kbd "C-c e u") #'emacs-uptime)
535(global-set-key (kbd "C-c e v") #'emacs-version)
41d290a2 536
c84be134
AB
537;; finding
538(global-set-key (kbd "C-c f .") #'find-file)
539(global-set-key (kbd "C-c f d") #'find-name-dired)
540(global-set-key (kbd "C-c f l") #'find-library)
b44dfb35 541(global-set-key (kbd "C-c f p") #'find-file-at-point)
567440fa 542
c84be134
AB
543;; frames
544(global-set-key (kbd "C-c F m") #'make-frame-command)
545(global-set-key (kbd "C-c F d") #'delete-frame)
41d290a2 546
c84be134 547;; help/describe
c84be134 548(global-set-key (kbd "C-S-h F") #'describe-face)
41d290a2 549
c84be134
AB
550;; (global-set-key (kbd "C-x k") #'b/kill-current-buffer)
551;; (global-set-key (kbd "C-x K") #'kill-buffer)
e5c2d147 552
9867e4bb 553(define-key emacs-lisp-mode-map (kbd "C-<return>") #'b/add-elisp-section)
41d290a2
AB
554
555(when (display-graphic-p)
c84be134 556 (global-unset-key (kbd "C-z")))
500004f4 557
b57457b2
AB
558\f
559;;; Essential packages
560
927b50b7
AB
561(add-to-list
562 'load-path
563 (expand-file-name
564 (convert-standard-filename "lisp") user-emacs-directory))
565
9867e4bb 566;; (require 'bandali-exwm)
33273849 567
f7910e3d 568(require 'bandali-org)
41d290a2 569
9867e4bb 570;; (require 'bandali-theme)
9c48decc 571
b57457b2 572;; recently opened files
78d731e1
AB
573(setq recentf-max-saved-items 2000
574 recentf-save-file (b/var "recentf-save.el"))
c84be134
AB
575(run-with-idle-timer 0.2 nil #'require 'recentf)
576(with-eval-after-load 'recentf
8c4704d0 577 ;; (add-to-list 'recentf-keep #'file-remote-p)
9867e4bb
AB
578 (recentf-mode)
579
580 (defun b/recentf-open ()
581 "Use `completing-read' to \\[find-file] a recent file."
582 (interactive)
583 (find-file
584 (completing-read "Find recent file: " recentf-list)))
585 (global-set-key (kbd "C-c f r") #'b/recentf-open))
41d290a2 586
87631bd0
AB
587;; (fido-mode 1)
588;; (defun b/icomplete--fido-mode-setup ()
589;; "Customizations to `fido-mode''s minibuffer."
590;; (when (and icomplete-mode (icomplete-simple-completing-p))
591;; (setq-local
592;; ;; icomplete-compute-delay 0.1
593;; ;; icomplete-hide-common-prefix t
594;; icomplete-separator " · "
595;; completion-styles '(basic substring partial-completion flex))))
596;; (add-hook 'minibuffer-setup-hook #'b/icomplete--fido-mode-setup 1)
41d290a2 597
679463c6 598(require 'bandali-eshell)
41d290a2 599
679463c6 600(require 'bandali-ibuffer)
41d290a2 601
679463c6 602(require 'bandali-dired)
41d290a2 603
c84be134 604(with-eval-after-load 'help
41d290a2 605 (temp-buffer-resize-mode)
78d731e1 606 (setq help-window-select t))
41d290a2 607
8c4704d0 608(with-eval-after-load 'help-mode
c84be134
AB
609 ;; local key bindings
610 (define-key help-mode-map (kbd "p") #'backward-button)
611 (define-key help-mode-map (kbd "n") #'forward-button))
612
613(with-eval-after-load 'tramp
78d731e1
AB
614 (setq tramp-auto-save-directory (b/var "tramp/auto-save/")
615 tramp-persistency-file-name (b/var "tramp/persistency.el"))
41d290a2
AB
616 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
617 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
618 (add-to-list 'tramp-default-proxies-alist
619 (list (regexp-quote (system-name)) nil nil)))
620
c84be134
AB
621(with-eval-after-load 'doc-view
622 (define-key doc-view-mode-map (kbd "M-RET") #'image-previous-line))
41d290a2 623
78d731e1 624(setq shr-max-width 80)
7c558c9b 625
29e8b5de 626;; Email (with Gnus, message, and smtpmail)
2087ae39 627(require 'bandali-gnus)
2087ae39 628(require 'bandali-message)
29e8b5de 629;; (with-eval-after-load 'smtpmail
78d731e1 630;; (setq smtpmail-queue-mail t
29e8b5de 631;; smtpmail-queue-dir (concat b/maildir "queue/")))
2087ae39 632
8c4704d0 633;; IRC (with ERC)
39c1c073
AB
634(require 'bandali-erc)
635
927b50b7 636;; 'paste' service (aka scp + web server)
8c4704d0 637(add-to-list 'load-path (b/lisp "scpaste"))
c84be134 638(with-eval-after-load 'scpaste
78d731e1
AB
639 (setq scpaste-http-destination "https://p.bndl.org"
640 scpaste-scp-destination "p:~"))
8c4704d0
AB
641(autoload 'scpaste "scpaste" nil t)
642(autoload 'scpaste-region "scpaste" nil t)
0596e3cf
AB
643(global-set-key (kbd "C-c a p p") #'scpaste)
644(global-set-key (kbd "C-c a p r") #'scpaste-region)
2331b5a0 645
b57457b2
AB
646\f
647;;; Editing
5750405c 648
b57457b2 649;; display Lisp objects at point in the echo area
c84be134
AB
650(when (version< "25" emacs-version)
651 (with-eval-after-load 'eldoc
78d731e1 652 (setq eldoc-minor-mode-string " eldoc")
8c4704d0 653 (global-eldoc-mode)))
41d290a2 654
b57457b2 655;; highlight matching parens
c84be134
AB
656(require 'paren)
657(show-paren-mode)
658
659;; (require 'elec-pair)
660;; (electric-pair-mode)
661
78d731e1 662(setq
c84be134
AB
663 ;; Save what I copy into clipboard from other applications into Emacs'
664 ;; kill-ring, which would allow me to still be able to easily access
665 ;; it in case I kill (cut or copy) something else inside Emacs before
666 ;; yanking (pasting) what I'd originally intended to.
667 save-interprogram-paste-before-kill t)
668(with-eval-after-load 'simple
9867e4bb
AB
669 (column-number-mode 1)
670 (line-number-mode 1))
41d290a2 671
b57457b2 672;; save minibuffer history
c84be134 673(require 'savehist)
78d731e1 674(setq savehist-file (b/var "savehist.el"))
c84be134
AB
675(savehist-mode)
676(add-to-list 'savehist-additional-variables 'kill-ring)
41d290a2 677
b57457b2 678;; automatically save place in files
c84be134 679(when (version< "25" emacs-version)
78d731e1 680 (setq save-place-file (b/var "save-place.el"))
c84be134
AB
681 (save-place-mode))
682
683(defun indicate-buffer-boundaries-left ()
78d731e1 684 (setq indicate-buffer-boundaries 'left))
c84be134
AB
685(with-eval-after-load 'prog-mode
686 (global-prettify-symbols-mode))
687(add-hook 'prog-mode-hook #'indicate-buffer-boundaries-left)
688
8c4704d0 689(define-key text-mode-map (kbd "C-<return>") #'b/insert-asterism)
c84be134
AB
690(add-hook 'text-mode-hook #'indicate-buffer-boundaries-left)
691(add-hook 'text-mode-hook #'flyspell-mode)
692
693(add-to-list 'auto-mode-alist '("\\.*rc$" . conf-mode))
694
695(add-to-list 'auto-mode-alist '("\\.bashrc$" . sh-mode))
696
8c4704d0 697(with-eval-after-load 'flyspell
78d731e1 698 (setq flyspell-mode-line-string " fly"))
8c4704d0 699
c84be134 700;; ispell
41d290a2 701;; http://endlessparentheses.com/ispell-and-apostrophes.html
c84be134
AB
702;; (run-with-idle-timer 0.6 nil #'require 'ispell)
703;; (with-eval-after-load 'ispell
704;; ;; ’ can be part of a word
78d731e1
AB
705;; (setq ispell-local-dictionary-alist
706;; `((nil "[[:alpha:]]" "[^[:alpha:]]"
707;; "['\x2019]" nil ("-B") nil utf-8))
708;; ispell-program-name (executable-find "hunspell"))
c84be134
AB
709;; ;; don't send ’ to the subprocess
710;; (defun endless/replace-apostrophe (args)
711;; (cons (replace-regexp-in-string
712;; "’" "'" (car args))
713;; (cdr args)))
714;; (advice-add #'ispell-send-string :filter-args
715;; #'endless/replace-apostrophe)
716;; ;; convert ' back to ’ from the subprocess
717;; (defun endless/replace-quote (args)
718;; (if (not (derived-mode-p 'org-mode))
719;; args
720;; (cons (replace-regexp-in-string
721;; "'" "’" (car args))
722;; (cdr args))))
723;; (advice-add #'ispell-parse-output :filter-args
724;; #'endless/replace-quote))
725
0596e3cf 726;; abbrev
78d731e1 727(setq abbrev-file-name (b/etc "abbrev.el"))
c84be134 728(add-hook 'text-mode-hook #'abbrev-mode)
54209e74 729
b57457b2
AB
730\f
731;;; Programming modes
732
c84be134 733(with-eval-after-load 'lisp-mode
41d290a2
AB
734 (defun indent-spaces-mode ()
735 (setq indent-tabs-mode nil))
736 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
737
8c4704d0
AB
738;; alloy
739(add-to-list 'load-path (b/lisp "alloy-mode"))
740(autoload 'alloy-mode "alloy-mode" nil t)
c84be134 741(with-eval-after-load 'alloy-mode
78d731e1 742 (setq alloy-basic-offset 2)
fac1032c
AB
743 ;; (defun b/alloy-simple-indent (start end)
744 ;; (interactive "r")
745 ;; ;; (if (region-active-p)
746 ;; ;; (indent-rigidly start end alloy-basic-offset)
747 ;; ;; (if (bolp)
748 ;; ;; (indent-rigidly (line-beginning-position)
749 ;; ;; (line-end-position)
750 ;; ;; alloy-basic-offset)))
751 ;; (indent-to (+ (current-column) alloy-basic-offset)))
c84be134
AB
752 ;; local key bindings
753 (define-key alloy-mode-map (kbd "RET") #'electric-newline-and-maybe-indent)
754 ;; (define-key alloy-mode-map (kbd "TAB") #'b/alloy-simple-indent)
755 (define-key alloy-mode-map (kbd "TAB") #'indent-for-tab-command))
756(add-to-list 'auto-mode-alist '("\\.\\(als\\|dsh\\)\\'" . alloy-mode))
757(add-hook 'alloy-mode-hook (lambda nil (setq-local indent-tabs-mode nil)))
758
759;; lean
760;; (eval-when-compile (defvar lean-mode-map))
761;; (run-with-idle-timer 0.4 nil #'require 'lean-mode)
762;; (with-eval-after-load 'lean-mode
763;; (require 'lean-input)
78d731e1
AB
764;; (setq default-input-method "Lean"
765;; lean-input-tweak-all '(lean-input-compose
766;; (lean-input-prepend "/")
767;; (lean-input-nonempty))
768;; lean-input-user-translations '(("/" "/")))
c84be134
AB
769;; (lean-input-setup)
770;; ;; local key bindings
771;; (define-key lean-mode-map (kbd "S-SPC") #'company-complete))
772
773(with-eval-after-load 'sgml-mode
78d731e1 774 (setq sgml-basic-offset 0))
c84be134
AB
775
776(with-eval-after-load 'css-mode
78d731e1 777 (setq css-indent-offset 2))
c84be134 778
c84be134 779;; auctex
78d731e1 780;; (setq font-latex-fontify-sectioning 'color)
c84be134
AB
781
782(with-eval-after-load 'tex-mode
748bd8ac
AB
783 (cl-delete-if
784 (lambda (p) (string-match "^---?" (car p)))
c84be134
AB
785 tex--prettify-symbols-alist))
786(add-hook 'tex-mode-hook #'auto-fill-mode)
787(add-hook 'tex-mode-hook #'flyspell-mode)
1d01c927 788
b57457b2 789\f
b57457b2 790;;; Emacs enhancements & auxiliary packages
1eb20313 791
c84be134 792(with-eval-after-load 'man
78d731e1 793 (setq Man-width 80))
c84be134 794
8c4704d0
AB
795(defun b/*scratch* ()
796 "Switch to `*scratch*' buffer, creating it if it does not exist."
797 (interactive)
272a75dc
AB
798 (let ((fun (if (functionp #'get-scratch-buffer-create)
799 #'get-scratch-buffer-create ; (version<= "29" emacs-version)
800 #'startup--get-buffer-create-scratch))) ; (version< emacs-version "29")
801 (switch-to-buffer (funcall fun))))
8c4704d0 802(global-set-key (kbd "C-c s") #'b/*scratch*)
41d290a2 803
5b10d879
AB
804;; ,----
805;; | make pretty boxed quotes like this
806;; `----
8c4704d0 807(add-to-list 'load-path (b/lisp "boxquote"))
c84be134
AB
808(run-with-idle-timer 0.6 nil #'require 'boxquote)
809(with-eval-after-load 'boxquote
810 (defvar b/boxquote-prefix-map)
811 (define-prefix-command 'b/boxquote-prefix-map)
812 (global-set-key (kbd "C-c q") 'b/boxquote-prefix-map)
813 (define-key b/boxquote-prefix-map (kbd "b") #'boxquote-buffer)
814 (define-key b/boxquote-prefix-map (kbd "B") #'boxquote-insert-buffer)
815 (define-key b/boxquote-prefix-map (kbd "d") #'boxquote-defun)
816 (define-key b/boxquote-prefix-map (kbd "F") #'boxquote-insert-file)
817 (define-key b/boxquote-prefix-map (kbd "hf") #'boxquote-describe-function)
818 (define-key b/boxquote-prefix-map (kbd "hk") #'boxquote-describe-key)
819 (define-key b/boxquote-prefix-map (kbd "hv") #'boxquote-describe-variable)
820 (define-key b/boxquote-prefix-map (kbd "hw") #'boxquote-where-is)
821 (define-key b/boxquote-prefix-map (kbd "k") #'boxquote-kill)
822 (define-key b/boxquote-prefix-map (kbd "p") #'boxquote-paragraph)
823 (define-key b/boxquote-prefix-map (kbd "q") #'boxquote-boxquote)
824 (define-key b/boxquote-prefix-map (kbd "r") #'boxquote-region)
825 (define-key b/boxquote-prefix-map (kbd "s") #'boxquote-shell-command)
826 (define-key b/boxquote-prefix-map (kbd "t") #'boxquote-text)
827 (define-key b/boxquote-prefix-map (kbd "T") #'boxquote-title)
828 (define-key b/boxquote-prefix-map (kbd "u") #'boxquote-unbox)
829 (define-key b/boxquote-prefix-map (kbd "U") #'boxquote-unbox-region)
830 (define-key b/boxquote-prefix-map (kbd "y") #'boxquote-yank)
831 (define-key b/boxquote-prefix-map (kbd "M-q") #'boxquote-fill-paragraph)
832 (define-key b/boxquote-prefix-map (kbd "M-w") #'boxquote-kill-ring-save))
833
8c4704d0 834(add-to-list 'load-path (b/lisp "hl-todo"))
c84be134
AB
835(run-with-idle-timer 0.5 nil #'require 'hl-todo)
836(with-eval-after-load 'hl-todo
1eb20313 837 ;; highlight TODOs in buffers
41d290a2
AB
838 (global-hl-todo-mode))
839
c84be134
AB
840;; expand-region
841(global-set-key (kbd "C-=") #'er/expand-region)
842
843(run-with-idle-timer 0.6 nil #'require 'yasnippet)
844(with-eval-after-load 'yasnippet
845 (declare-function yas-reload-all
846 "yasnippet" (&optional no-jit interactive))
847 (declare-function yas-maybe-expand-abbrev-key-filter
848 "yasnippet" (cmd))
849
850 (defconst yas-verbosity-cur yas-verbosity)
78d731e1
AB
851 (setq yas-verbosity 2
852 yas-snippet-dirs `(,(b/etc "yasnippet/snippets")))
5df34463 853 ;; (add-to-list 'yas-snippet-dirs "~/src/git/guix/etc/snippets" t)
c84be134
AB
854 (yas-reload-all)
855 (setq yas-verbosity yas-verbosity-cur)
856
857 (defun b/yas-maybe-expand-abbrev-key-filter (cmd)
858 (when (and (yas-maybe-expand-abbrev-key-filter cmd)
859 (not (bound-and-true-p git-commit-mode)))
860 cmd))
861 (defconst b/yas-maybe-expand
862 '(menu-item "" yas-expand
863 :filter b/yas-maybe-expand-abbrev-key-filter))
864 (define-key yas-minor-mode-map (kbd "SPC") b/yas-maybe-expand)
865
866 (yas-global-mode))
867
868;; debbugs
869(global-set-key (kbd "C-c D d") #'debbugs-gnu)
870(global-set-key (kbd "C-c D b") #'debbugs-gnu-bugs)
871(global-set-key (kbd "C-c D e") ; bug-gnu-emacs
872 (lambda ()
873 (interactive)
874 (setq debbugs-gnu-current-suppress t)
875 (debbugs-gnu debbugs-gnu-default-severities
876 '("emacs"))))
877(global-set-key (kbd "C-c D g") ; bug-gnuzilla
878 (lambda ()
879 (interactive)
880 (setq debbugs-gnu-current-suppress t)
881 (debbugs-gnu debbugs-gnu-default-severities
882 '("gnuzilla"))))
c84be134 883
0596e3cf 884;; url and url-cache
78d731e1 885(setq
0596e3cf
AB
886 url-configuration-directory (b/var "url/configuration/")
887 url-cache-directory (b/var "url/cache/"))
888
c84be134 889;; eww
78d731e1
AB
890(setq eww-download-directory (file-name-as-directory
891 (getenv "XDG_DOWNLOAD_DIR")))
c84be134 892(global-set-key (kbd "C-c a e w") #'eww)
41d290a2 893
8c4704d0 894;; ;; org-ref
78d731e1 895;; (setq
8c4704d0
AB
896;; reftex-default-bibliography '("~/usr/org/references.bib")
897;; org-ref-default-bibliography '("~/usr/org/references.bib")
898;; org-ref-bibliography-notes "~/usr/org/notes.org"
899;; org-ref-pdf-directory "~/usr/org/bibtex-pdfs/")
c84be134
AB
900
901;; fill-column-indicator ?
902
903;; window
78d731e1 904(setq split-width-threshold 150)
c84be134
AB
905(global-set-key (kbd "C-c w s l")
906 (lambda ()
907 (interactive)
908 (split-window-right)
909 (other-window 1)))
910(global-set-key (kbd "C-c w s j")
911 (lambda ()
912 (interactive)
913 (split-window-below)
914 (other-window 1)))
915(global-set-key (kbd "C-c w q") #'quit-window)
916
c84be134 917;; pass
8c4704d0
AB
918;; (global-set-key (kbd "C-c a p") #'pass)
919;; (add-hook 'pass-mode-hook #'View-exit)
c84be134
AB
920
921;; reftex
922;; uncomment to disable reftex-cite's default choice of previous word
923;; (with-eval-after-load 'reftex
924;; (require 'reftex-cite)
925;; (defun reftex-get-bibkey-default ()
926;; "If the cursor is in a citation macro, return the word before the macro."
927;; (let* ((macro (reftex-what-macro 1)))
928;; (save-excursion
929;; (when (and macro (string-match "cite" (car macro)))
930;; (goto-char (cdr macro)))
931;; (reftex-this-word)))))
932(add-hook 'latex-mode-hook #'reftex-mode)
933
934;; dmenu
1f5c92ff
AB
935(add-to-list 'load-path (b/lisp "dmenu"))
936(with-eval-after-load 'dmenu
78d731e1
AB
937 (setq dmenu-prompt-string "run: "
938 dmenu-save-file (b/var "dmenu-items")))
1f5c92ff 939(autoload 'dmenu "dmenu" nil t)
c84be134
AB
940
941;; eosd ?
9ed5410e 942
8c4704d0
AB
943;; delight
944(run-with-idle-timer 0.5 nil #'require 'delight)
945(with-eval-after-load 'delight
946 (delight 'auto-fill-function " f" "simple")
947 (delight 'abbrev-mode "" "abbrev")
8c4704d0
AB
948 (delight 'mml-mode " mml" "mml")
949 (delight 'yas-minor-mode "" "yasnippet"))
950
a85421b4
AB
951;; po-mode
952(require 'bandali-po)
953
12e6cf3c 954(with-eval-after-load 'emms
78d731e1 955 (setq emms-directory (b/var "emms")))
12e6cf3c 956
b57457b2 957\f
b57457b2
AB
958;;; Post initialization
959
41d290a2
AB
960(message "Loading %s...done (%.3fs)" user-init-file
961 (float-time (time-subtract (current-time)
dca50cf5 962 b/before-user-init-time)))
41d290a2
AB
963
964;;; init.el ends here