Rewrite `b/*scratch*' function in init file
[~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
AB
197 ;; completion case sensitivity
198 completion-ignore-case t
87631bd0 199 read-buffer-completion-ignore-case t
60ff805e
AB
200 ;; minibuffer
201 enable-recursive-minibuffers t
202 resize-mini-windows t
9867e4bb
AB
203 ;; mode-line
204 mode-line-compact t
205 ;; i don't feel like jumping out of my chair every now and again;
206 ;; so...don't *BEEP* at me, emacs =)
60ff805e
AB
207 ring-bell-function 'ignore
208 ;; better scrolling
9867e4bb
AB
209 ;; scroll-conservatively 101
210 scroll-conservatively 15
211 ;; scroll-preserve-screen-position 1
60ff805e 212 ;; focus follows mouse
9867e4bb
AB
213 ;; mouse-autoselect-window t
214 )
60ff805e
AB
215
216(setq-default
7682baf8
AB
217 ;; case-sensitive search (and `dabbrev-expand')
218 ;; case-fold-search nil
9867e4bb
AB
219 ;; always use space for indentation
220 indent-tabs-mode nil
221 tab-width 4)
60ff805e 222
52b7a57a
AB
223(when (display-graphic-p)
224 (set-fontset-font t 'arabic "Vazir"))
225;; ;; (set-frame-font "Drafting Mono-14:weight=light" nil t)
226;; (set-frame-font "Drafting Mono:pixelsize=16" nil t)
227;; (set-face-attribute 'bold nil :weight 'semi-bold)
7c558c9b 228
60ff805e 229;;;; Elisp-level customizations
41d290a2 230
adba94a7
AB
231;; (define-key minibuffer-local-completion-map
232;; "\t" #'minibuffer-force-complete)
233
9867e4bb 234;; (with-eval-after-load 'icomplete
adba94a7 235
9867e4bb 236;; (setq icomplete-on-del-error-function #'abort-recursive-edit)
adba94a7 237
9867e4bb
AB
238;; (defun b/icomplete-fido-backward-updir ()
239;; "Delete char before or go up directory, like `ido-mode'."
240;; (interactive)
241;; (if (and (eq (char-before) ?/)
242;; (eq (icomplete--category) 'file))
243;; (save-excursion
244;; (goto-char (1- (point)))
245;; (when (search-backward "/" (point-min) t)
246;; (delete-region (1+ (point)) (point-max))))
247;; (condition-case nil
248;; (call-interactively #'delete-backward-char)
249;; (error
250;; (when icomplete-on-del-error-function
251;; (funcall icomplete-on-del-error-function))))))
252
253;; (define-key icomplete-fido-mode-map
254;; (kbd "DEL") #'b/icomplete-fido-backward-updir))
255
78d731e1
AB
256;; subr
257;; (keyboard-translate ?\( ?\[)
258;; (keyboard-translate ?\) ?\])
259;; (keyboard-translate ?\[ ?\()
260;; (keyboard-translate ?\] ?\))
adba94a7 261
87631bd0 262;; minibuffer
78d731e1 263(setq read-file-name-completion-ignore-case t)
87631bd0 264
c84be134
AB
265;; startup
266;; don't need to see the startup echo area message
267(advice-add #'display-startup-echo-area-message :override #'ignore)
78d731e1 268(setq
c84be134
AB
269 ;; i want *scratch* as my startup buffer
270 initial-buffer-choice t
271 ;; i don't need the default hint
272 initial-scratch-message nil
273 ;; use customizable text-mode as major mode for *scratch*
274 ;; (initial-major-mode 'text-mode)
275 ;; inhibit buffer list when more than 2 files are loaded
276 inhibit-startup-buffer-menu t
277 ;; don't need to see the startup screen or echo area message
278 inhibit-startup-screen t
279 inhibit-startup-echo-area-message user-login-name)
280
281;; files
78d731e1 282(setq
c84be134
AB
283 ;; backups (C-h v make-backup-files RET)
284 backup-by-copying t
0596e3cf 285 backup-directory-alist (list (cons "." (b/var "backup/")))
c84be134
AB
286 version-control t
287 delete-old-versions t
288 ;; auto-save
289 auto-save-file-name-transforms `((".*" ,(b/var "auto-save/") t))
290 ;; insert newline at the end of files
9867e4bb 291 ;; require-final-newline t
c84be134
AB
292 ;; open read-only file buffers in view-mode
293 ;; (enables niceties like `q' for quit)
294 view-read-only t)
295
296;; novice
60ff805e 297;; disable disabled commands
78d731e1 298(setq disabled-command-function nil)
41d290a2 299
60ff805e
AB
300;; lazy-person-friendly yes/no prompts
301(defalias 'yes-or-no-p #'y-or-n-p)
b57457b2 302
8c4704d0 303;; autorevert: enable automatic reloading of changed buffers and files
78d731e1
AB
304(setq
305 ;; auto-revert-verbose nil
306 global-auto-revert-non-file-buffers nil)
8c4704d0
AB
307(require 'autorevert)
308(global-auto-revert-mode 1)
b57457b2
AB
309
310;; time and battery in mode-line
9867e4bb
AB
311(run-with-idle-timer 0.1 nil #'require 'time)
312(with-eval-after-load 'time
78d731e1 313 (setq
9867e4bb
AB
314 display-time-default-load-average nil
315 display-time-format " %a %b %-e %-l:%M%P"
316 display-time-mail-icon '(image :type xpm
317 :file "gnus/gnus-pointer.xpm"
318 :ascent center)
2698f1c3
AB
319 display-time-use-mail-icon t
320 zoneinfo-style-world-list
321 `(,@zoneinfo-style-world-list
322 ("Etc/UTC" "UTC")
323 ("Asia/Tehran" "Tehran")
324 ("Australia/Melbourne" "Melbourne")))
9867e4bb
AB
325 (display-time-mode))
326
327(run-with-idle-timer 0.1 nil #'require 'battery)
328(with-eval-after-load 'battery
78d731e1 329 (setq battery-mode-line-format " %p%% %t")
9867e4bb
AB
330 (display-battery-mode))
331
332;; (with-eval-after-load 'fringe
333;; ;; smaller fringe
334;; (fringe-mode '(3 . 1)))
c84be134 335
c84be134 336;; enable winner-mode (C-h f winner-mode RET)
9867e4bb 337(require 'winner)
c84be134
AB
338(winner-mode 1)
339
69ad7e36
AB
340(run-with-idle-timer 0.1 nil #'require 'windmove)
341(with-eval-after-load 'windmove
78d731e1 342 (setq windmove-wrap-around t)
69ad7e36
AB
343 (global-set-key (kbd "M-H") #'windmove-left)
344 (global-set-key (kbd "M-L") #'windmove-right)
345 (global-set-key (kbd "M-K") #'windmove-up)
346 (global-set-key (kbd "M-J") #'windmove-down))
347
c84be134 348(with-eval-after-load 'compile
60ff805e
AB
349 ;; don't display *compilation* buffer on success. based on
350 ;; https://stackoverflow.com/a/17788551, with changes to use `cl-letf'
351 ;; instead of the now obsolete `flet'.
dca50cf5 352 (defun b/compilation-finish-function (buffer outstr)
41d290a2
AB
353 (unless (string-match "finished" outstr)
354 (switch-to-buffer-other-window buffer))
355 t)
356
dca50cf5 357 (setq compilation-finish-functions #'b/compilation-finish-function)
41d290a2
AB
358
359 (require 'cl-macs)
360
361 (defadvice compilation-start
362 (around inhibit-display
363 (command &optional mode name-function highlight-regexp))
364 (if (not (string-match "^\\(find\\|grep\\)" command))
365 (cl-letf (((symbol-function 'display-buffer) #'ignore))
366 (save-window-excursion ad-do-it))
367 ad-do-it))
368 (ad-activate 'compilation-start))
369
c84be134 370;; isearch
78d731e1 371(setq
c84be134
AB
372 ;; allow scrolling in Isearch
373 isearch-allow-scroll t
9867e4bb 374 isearch-lazy-count t
c84be134
AB
375 ;; search for non-ASCII characters: i’d like non-ASCII characters such
376 ;; as ‘’“”«»‹›áⓐ𝒶 to be selected when i search for their ASCII
377 ;; counterpart. shoutout to
378 ;; http://endlessparentheses.com/new-in-emacs-25-1-easily-search-non-ascii-characters.html
379 search-default-mode #'char-fold-to-regexp)
380
381;; replace
60ff805e 382;; uncomment to extend the above behaviour to query-replace
78d731e1 383;; (setq replace-char-fold t)
c84be134
AB
384
385;; vc
386(global-set-key (kbd "C-x v C-=") #'vc-ediff)
387
388(with-eval-after-load 'vc-git
78d731e1
AB
389 (setq vc-git-print-log-follow t
390 vc-git-show-stash 0))
c84be134 391
78d731e1
AB
392(setq ediff-window-setup-function 'ediff-setup-windows-plain
393 ediff-split-window-function 'split-window-horizontally)
c84be134
AB
394(with-eval-after-load 'ediff
395 (add-hook 'ediff-after-quit-hook-internal #'winner-undo))
396
397;; face-remap
78d731e1 398(setq
c84be134
AB
399 ;; gentler font resizing
400 text-scale-mode-step 1.05)
401
402(run-with-idle-timer 0.4 nil #'require 'mwheel)
78d731e1
AB
403(setq mouse-wheel-scroll-amount '(1 ((shift) . 1)) ; one line at a time
404 mouse-wheel-progressive-speed nil ; don't accelerate scrolling
405 mouse-wheel-follow-mouse t) ; scroll window under mouse
c84be134
AB
406
407(run-with-idle-timer 0.4 nil #'require 'pixel-scroll)
408(with-eval-after-load 'pixel-scroll
409 (pixel-scroll-mode 1))
410
411;; epg-config
78d731e1 412(setq
c84be134
AB
413 epg-gpg-program (executable-find "gpg")
414 ;; ask for GPG passphrase in minibuffer
415 ;; this will fail if gpg>=2.1 is not available
416 epg-pinentry-mode 'loopback)
417
c84be134 418;; auth-source
78d731e1 419(setq
c84be134
AB
420 auth-sources '("~/.authinfo.gpg")
421 authinfo-hidden (regexp-opt '("password" "client-secret" "token")))
b98dbb3d 422
9867e4bb
AB
423;; info
424(with-eval-after-load 'info
78d731e1 425 (setq
966011a8
AB
426 Info-directory-list
427 `(,@Info-directory-list
428 ,(expand-file-name
429 (convert-standard-filename "info/") source-directory)
430 "/usr/share/info/")))
9867e4bb
AB
431
432;; faces
6ff057ac
AB
433(when (display-graphic-p)
434 (with-eval-after-load 'faces
435 (let* ((grey "#e7e7e7")
52b7a57a
AB
436 ;; (darker-grey "#d9d9d9")
437 ;; (box ;; 'unspecified
438 ;; `(;; :line-width -1
439 ;; :style released-button))
440 )
8ea6de12
AB
441 ;; (set-face-attribute 'fixed-pitch nil :family "Source Code Pro")
442 (set-face-attribute 'fixed-pitch nil :family "Inconsolata")
6ff057ac 443 (set-face-attribute 'mode-line nil
52b7a57a 444 :background grey ;; :box box
8ea6de12 445 :inherit 'fixed-pitch)
c6e4b014
AB
446 ;; (set-face-attribute 'mode-line-inactive nil
447 ;; :background darker-grey :box box)
448 )))
9867e4bb 449
b57457b2 450\f
927b50b7
AB
451;;; Useful utilities
452
453(defun b/add-elisp-section ()
454 (interactive)
455 (insert "\n")
456 (forward-line -1)
457 (insert "\n\f\n;;; "))
458
459(defun b/insert-asterism ()
460 "Insert a centred asterism."
461 (interactive)
462 (let ((asterism "* * *"))
463 (insert
464 (concat
465 "\n"
466 (make-string
467 (floor (/ (- fill-column (length asterism)) 2))
468 ?\s)
469 asterism
470 "\n"))))
471
472(defun b/start-process (program &rest args)
473 "Same as `start-process', but doesn't bother about name and buffer."
474 (let ((process-name (concat program "_process"))
475 (buffer-name (generate-new-buffer-name
476 (concat program "_output"))))
477 (apply #'start-process
478 process-name buffer-name program args)))
479
480(defun b/no-mouse-autoselect-window ()
481 "Conveniently disable `focus-follows-mouse'.
482For disabling the behaviour for certain buffers and/or modes."
483 (make-local-variable 'mouse-autoselect-window)
484 (setq mouse-autoselect-window nil))
485
486(defun b/kill-current-buffer ()
487 "Kill the current buffer."
488 ;; also see https://redd.it/64xb3q
489 (interactive)
490 (kill-buffer (current-buffer)))
491
492(defun b/move-indentation-or-beginning-of-line (arg)
493 "Move to the indentation or to the beginning of line."
494 (interactive "^p")
495 ;; (if (bolp)
496 ;; (back-to-indentation)
497 ;; (move-beginning-of-line arg))
498 (if (= (point)
499 (progn (back-to-indentation)
500 (point)))
501 (move-beginning-of-line arg)))
502
503(defun b/join-line-top ()
504 "Like `join-line', but join next line to the current line."
505 (interactive)
506 (join-line 1))
507
508(defun b/duplicate-line-or-region (&optional n)
509 "Duplicate the current line, or region (if active).
510Make N (default: 1) copies of the current line or region."
511 (interactive "*p")
512 (let ((u-r-p (use-region-p)) ; if region is active
513 (n1 (or n 1)))
514 (save-excursion
515 (let ((text
516 (if u-r-p
517 (buffer-substring (region-beginning) (region-end))
518 (prog1 (thing-at-point 'line)
519 (end-of-line)
520 (if (eobp)
521 (newline)
522 (forward-line 1))))))
523 (dotimes (_ (abs n1))
524 (insert text))))))
525
6cf7efb0
AB
526(defun b/invert-default-face ()
527 "Invert the `default' face (swap its background and foreground).
528Effectively a very simple light/dark theme toggle switch."
529 (interactive)
530 (invert-face 'default))
531
927b50b7 532\f
c84be134 533;;; General key bindings
b57457b2 534
c84be134
AB
535(global-set-key (kbd "C-a") #'b/move-indentation-or-beginning-of-line)
536(global-set-key (kbd "C-c a i") #'ielm)
537(global-set-key (kbd "C-c d") #'b/duplicate-line-or-region)
adba94a7 538(global-set-key (kbd "C-c j") #'b/join-line-top)
c84be134
AB
539(global-set-key (kbd "C-S-j") #'b/join-line-top)
540(global-set-key (kbd "C-c x") #'execute-extended-command)
6cf7efb0 541(global-set-key (kbd "C-c v") #'b/invert-default-face)
41d290a2 542
c84be134
AB
543;; evaling and macro-expanding
544(global-set-key (kbd "C-c e b") #'eval-buffer)
545(global-set-key (kbd "C-c e e") #'eval-last-sexp)
9867e4bb 546(global-set-key (kbd "C-c e m") #'pp-macroexpand-last-sexp)
c84be134 547(global-set-key (kbd "C-c e r") #'eval-region)
41d290a2 548
c84be134
AB
549;; emacs things
550(global-set-key (kbd "C-c e i") #'emacs-init-time)
551(global-set-key (kbd "C-c e u") #'emacs-uptime)
552(global-set-key (kbd "C-c e v") #'emacs-version)
41d290a2 553
c84be134
AB
554;; finding
555(global-set-key (kbd "C-c f .") #'find-file)
556(global-set-key (kbd "C-c f d") #'find-name-dired)
557(global-set-key (kbd "C-c f l") #'find-library)
b44dfb35 558(global-set-key (kbd "C-c f p") #'find-file-at-point)
567440fa 559
c84be134
AB
560;; frames
561(global-set-key (kbd "C-c F m") #'make-frame-command)
562(global-set-key (kbd "C-c F d") #'delete-frame)
41d290a2 563
c84be134 564;; help/describe
c84be134 565(global-set-key (kbd "C-S-h F") #'describe-face)
41d290a2 566
c84be134
AB
567;; (global-set-key (kbd "C-x k") #'b/kill-current-buffer)
568;; (global-set-key (kbd "C-x K") #'kill-buffer)
e5c2d147 569
9867e4bb 570(define-key emacs-lisp-mode-map (kbd "C-<return>") #'b/add-elisp-section)
41d290a2
AB
571
572(when (display-graphic-p)
c84be134 573 (global-unset-key (kbd "C-z")))
500004f4 574
b57457b2
AB
575\f
576;;; Essential packages
577
927b50b7
AB
578(add-to-list
579 'load-path
580 (expand-file-name
581 (convert-standard-filename "lisp") user-emacs-directory))
582
9867e4bb 583;; (require 'bandali-exwm)
33273849 584
f7910e3d 585(require 'bandali-org)
41d290a2 586
9867e4bb 587;; (require 'bandali-theme)
9c48decc 588
b57457b2 589;; recently opened files
78d731e1
AB
590(setq recentf-max-saved-items 2000
591 recentf-save-file (b/var "recentf-save.el"))
c84be134
AB
592(run-with-idle-timer 0.2 nil #'require 'recentf)
593(with-eval-after-load 'recentf
8c4704d0 594 ;; (add-to-list 'recentf-keep #'file-remote-p)
9867e4bb
AB
595 (recentf-mode)
596
597 (defun b/recentf-open ()
598 "Use `completing-read' to \\[find-file] a recent file."
599 (interactive)
600 (find-file
601 (completing-read "Find recent file: " recentf-list)))
602 (global-set-key (kbd "C-c f r") #'b/recentf-open))
41d290a2 603
87631bd0
AB
604;; (fido-mode 1)
605;; (defun b/icomplete--fido-mode-setup ()
606;; "Customizations to `fido-mode''s minibuffer."
607;; (when (and icomplete-mode (icomplete-simple-completing-p))
608;; (setq-local
609;; ;; icomplete-compute-delay 0.1
610;; ;; icomplete-hide-common-prefix t
611;; icomplete-separator " · "
612;; completion-styles '(basic substring partial-completion flex))))
613;; (add-hook 'minibuffer-setup-hook #'b/icomplete--fido-mode-setup 1)
41d290a2 614
679463c6 615(require 'bandali-eshell)
41d290a2 616
679463c6 617(require 'bandali-ibuffer)
41d290a2 618
679463c6 619(require 'bandali-dired)
41d290a2 620
c84be134 621(with-eval-after-load 'help
41d290a2 622 (temp-buffer-resize-mode)
78d731e1 623 (setq help-window-select t))
41d290a2 624
8c4704d0 625(with-eval-after-load 'help-mode
c84be134
AB
626 ;; local key bindings
627 (define-key help-mode-map (kbd "p") #'backward-button)
628 (define-key help-mode-map (kbd "n") #'forward-button))
629
630(with-eval-after-load 'tramp
78d731e1
AB
631 (setq tramp-auto-save-directory (b/var "tramp/auto-save/")
632 tramp-persistency-file-name (b/var "tramp/persistency.el"))
41d290a2
AB
633 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
634 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
635 (add-to-list 'tramp-default-proxies-alist
636 (list (regexp-quote (system-name)) nil nil)))
637
c84be134
AB
638(with-eval-after-load 'doc-view
639 (define-key doc-view-mode-map (kbd "M-RET") #'image-previous-line))
41d290a2 640
78d731e1 641(setq shr-max-width 80)
7c558c9b 642
29e8b5de 643;; Email (with Gnus, message, and smtpmail)
2087ae39 644(require 'bandali-gnus)
2087ae39 645(require 'bandali-message)
29e8b5de 646;; (with-eval-after-load 'smtpmail
78d731e1 647;; (setq smtpmail-queue-mail t
29e8b5de 648;; smtpmail-queue-dir (concat b/maildir "queue/")))
2087ae39 649
8c4704d0 650;; IRC (with ERC)
39c1c073
AB
651(require 'bandali-erc)
652
927b50b7 653;; 'paste' service (aka scp + web server)
8c4704d0 654(add-to-list 'load-path (b/lisp "scpaste"))
c84be134 655(with-eval-after-load 'scpaste
78d731e1
AB
656 (setq scpaste-http-destination "https://p.bndl.org"
657 scpaste-scp-destination "p:~"))
8c4704d0
AB
658(autoload 'scpaste "scpaste" nil t)
659(autoload 'scpaste-region "scpaste" nil t)
0596e3cf
AB
660(global-set-key (kbd "C-c a p p") #'scpaste)
661(global-set-key (kbd "C-c a p r") #'scpaste-region)
2331b5a0 662
b57457b2
AB
663\f
664;;; Editing
5750405c 665
b57457b2 666;; display Lisp objects at point in the echo area
c84be134
AB
667(when (version< "25" emacs-version)
668 (with-eval-after-load 'eldoc
78d731e1 669 (setq eldoc-minor-mode-string " eldoc")
8c4704d0 670 (global-eldoc-mode)))
41d290a2 671
b57457b2 672;; highlight matching parens
c84be134
AB
673(require 'paren)
674(show-paren-mode)
675
676;; (require 'elec-pair)
677;; (electric-pair-mode)
678
78d731e1 679(setq
c84be134
AB
680 ;; Save what I copy into clipboard from other applications into Emacs'
681 ;; kill-ring, which would allow me to still be able to easily access
682 ;; it in case I kill (cut or copy) something else inside Emacs before
683 ;; yanking (pasting) what I'd originally intended to.
684 save-interprogram-paste-before-kill t)
685(with-eval-after-load 'simple
9867e4bb
AB
686 (column-number-mode 1)
687 (line-number-mode 1))
41d290a2 688
b57457b2 689;; save minibuffer history
c84be134 690(require 'savehist)
78d731e1 691(setq savehist-file (b/var "savehist.el"))
c84be134
AB
692(savehist-mode)
693(add-to-list 'savehist-additional-variables 'kill-ring)
41d290a2 694
b57457b2 695;; automatically save place in files
c84be134 696(when (version< "25" emacs-version)
78d731e1 697 (setq save-place-file (b/var "save-place.el"))
c84be134
AB
698 (save-place-mode))
699
700(defun indicate-buffer-boundaries-left ()
78d731e1 701 (setq indicate-buffer-boundaries 'left))
c84be134
AB
702(with-eval-after-load 'prog-mode
703 (global-prettify-symbols-mode))
704(add-hook 'prog-mode-hook #'indicate-buffer-boundaries-left)
705
8c4704d0 706(define-key text-mode-map (kbd "C-<return>") #'b/insert-asterism)
c84be134
AB
707(add-hook 'text-mode-hook #'indicate-buffer-boundaries-left)
708(add-hook 'text-mode-hook #'flyspell-mode)
709
710(add-to-list 'auto-mode-alist '("\\.*rc$" . conf-mode))
711
712(add-to-list 'auto-mode-alist '("\\.bashrc$" . sh-mode))
713
8c4704d0 714(with-eval-after-load 'flyspell
78d731e1 715 (setq flyspell-mode-line-string " fly"))
8c4704d0 716
c84be134 717;; ispell
41d290a2 718;; http://endlessparentheses.com/ispell-and-apostrophes.html
c84be134
AB
719;; (run-with-idle-timer 0.6 nil #'require 'ispell)
720;; (with-eval-after-load 'ispell
721;; ;; ’ can be part of a word
78d731e1
AB
722;; (setq ispell-local-dictionary-alist
723;; `((nil "[[:alpha:]]" "[^[:alpha:]]"
724;; "['\x2019]" nil ("-B") nil utf-8))
725;; ispell-program-name (executable-find "hunspell"))
c84be134
AB
726;; ;; don't send ’ to the subprocess
727;; (defun endless/replace-apostrophe (args)
728;; (cons (replace-regexp-in-string
729;; "’" "'" (car args))
730;; (cdr args)))
731;; (advice-add #'ispell-send-string :filter-args
732;; #'endless/replace-apostrophe)
733;; ;; convert ' back to ’ from the subprocess
734;; (defun endless/replace-quote (args)
735;; (if (not (derived-mode-p 'org-mode))
736;; args
737;; (cons (replace-regexp-in-string
738;; "'" "’" (car args))
739;; (cdr args))))
740;; (advice-add #'ispell-parse-output :filter-args
741;; #'endless/replace-quote))
742
0596e3cf 743;; abbrev
78d731e1 744(setq abbrev-file-name (b/etc "abbrev.el"))
c84be134 745(add-hook 'text-mode-hook #'abbrev-mode)
54209e74 746
b57457b2
AB
747\f
748;;; Programming modes
749
c84be134 750(with-eval-after-load 'lisp-mode
41d290a2
AB
751 (defun indent-spaces-mode ()
752 (setq indent-tabs-mode nil))
753 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
754
8c4704d0
AB
755;; alloy
756(add-to-list 'load-path (b/lisp "alloy-mode"))
757(autoload 'alloy-mode "alloy-mode" nil t)
c84be134 758(with-eval-after-load 'alloy-mode
78d731e1 759 (setq alloy-basic-offset 2)
fac1032c
AB
760 ;; (defun b/alloy-simple-indent (start end)
761 ;; (interactive "r")
762 ;; ;; (if (region-active-p)
763 ;; ;; (indent-rigidly start end alloy-basic-offset)
764 ;; ;; (if (bolp)
765 ;; ;; (indent-rigidly (line-beginning-position)
766 ;; ;; (line-end-position)
767 ;; ;; alloy-basic-offset)))
768 ;; (indent-to (+ (current-column) alloy-basic-offset)))
c84be134
AB
769 ;; local key bindings
770 (define-key alloy-mode-map (kbd "RET") #'electric-newline-and-maybe-indent)
771 ;; (define-key alloy-mode-map (kbd "TAB") #'b/alloy-simple-indent)
772 (define-key alloy-mode-map (kbd "TAB") #'indent-for-tab-command))
773(add-to-list 'auto-mode-alist '("\\.\\(als\\|dsh\\)\\'" . alloy-mode))
774(add-hook 'alloy-mode-hook (lambda nil (setq-local indent-tabs-mode nil)))
775
776;; lean
777;; (eval-when-compile (defvar lean-mode-map))
778;; (run-with-idle-timer 0.4 nil #'require 'lean-mode)
779;; (with-eval-after-load 'lean-mode
780;; (require 'lean-input)
78d731e1
AB
781;; (setq default-input-method "Lean"
782;; lean-input-tweak-all '(lean-input-compose
783;; (lean-input-prepend "/")
784;; (lean-input-nonempty))
785;; lean-input-user-translations '(("/" "/")))
c84be134
AB
786;; (lean-input-setup)
787;; ;; local key bindings
788;; (define-key lean-mode-map (kbd "S-SPC") #'company-complete))
789
790(with-eval-after-load 'sgml-mode
78d731e1 791 (setq sgml-basic-offset 0))
c84be134
AB
792
793(with-eval-after-load 'css-mode
78d731e1 794 (setq css-indent-offset 2))
c84be134 795
c84be134 796;; auctex
78d731e1 797;; (setq font-latex-fontify-sectioning 'color)
c84be134
AB
798
799(with-eval-after-load 'tex-mode
748bd8ac
AB
800 (cl-delete-if
801 (lambda (p) (string-match "^---?" (car p)))
c84be134
AB
802 tex--prettify-symbols-alist))
803(add-hook 'tex-mode-hook #'auto-fill-mode)
804(add-hook 'tex-mode-hook #'flyspell-mode)
1d01c927 805
b57457b2 806\f
b57457b2 807;;; Emacs enhancements & auxiliary packages
1eb20313 808
c84be134 809(with-eval-after-load 'man
78d731e1 810 (setq Man-width 80))
c84be134 811
8c4704d0
AB
812(defun b/*scratch* ()
813 "Switch to `*scratch*' buffer, creating it if it does not exist."
814 (interactive)
272a75dc
AB
815 (let ((fun (if (functionp #'get-scratch-buffer-create)
816 #'get-scratch-buffer-create ; (version<= "29" emacs-version)
817 #'startup--get-buffer-create-scratch))) ; (version< emacs-version "29")
818 (switch-to-buffer (funcall fun))))
8c4704d0 819(global-set-key (kbd "C-c s") #'b/*scratch*)
41d290a2 820
5b10d879
AB
821;; ,----
822;; | make pretty boxed quotes like this
823;; `----
8c4704d0 824(add-to-list 'load-path (b/lisp "boxquote"))
c84be134
AB
825(run-with-idle-timer 0.6 nil #'require 'boxquote)
826(with-eval-after-load 'boxquote
827 (defvar b/boxquote-prefix-map)
828 (define-prefix-command 'b/boxquote-prefix-map)
829 (global-set-key (kbd "C-c q") 'b/boxquote-prefix-map)
830 (define-key b/boxquote-prefix-map (kbd "b") #'boxquote-buffer)
831 (define-key b/boxquote-prefix-map (kbd "B") #'boxquote-insert-buffer)
832 (define-key b/boxquote-prefix-map (kbd "d") #'boxquote-defun)
833 (define-key b/boxquote-prefix-map (kbd "F") #'boxquote-insert-file)
834 (define-key b/boxquote-prefix-map (kbd "hf") #'boxquote-describe-function)
835 (define-key b/boxquote-prefix-map (kbd "hk") #'boxquote-describe-key)
836 (define-key b/boxquote-prefix-map (kbd "hv") #'boxquote-describe-variable)
837 (define-key b/boxquote-prefix-map (kbd "hw") #'boxquote-where-is)
838 (define-key b/boxquote-prefix-map (kbd "k") #'boxquote-kill)
839 (define-key b/boxquote-prefix-map (kbd "p") #'boxquote-paragraph)
840 (define-key b/boxquote-prefix-map (kbd "q") #'boxquote-boxquote)
841 (define-key b/boxquote-prefix-map (kbd "r") #'boxquote-region)
842 (define-key b/boxquote-prefix-map (kbd "s") #'boxquote-shell-command)
843 (define-key b/boxquote-prefix-map (kbd "t") #'boxquote-text)
844 (define-key b/boxquote-prefix-map (kbd "T") #'boxquote-title)
845 (define-key b/boxquote-prefix-map (kbd "u") #'boxquote-unbox)
846 (define-key b/boxquote-prefix-map (kbd "U") #'boxquote-unbox-region)
847 (define-key b/boxquote-prefix-map (kbd "y") #'boxquote-yank)
848 (define-key b/boxquote-prefix-map (kbd "M-q") #'boxquote-fill-paragraph)
849 (define-key b/boxquote-prefix-map (kbd "M-w") #'boxquote-kill-ring-save))
850
8c4704d0 851(add-to-list 'load-path (b/lisp "hl-todo"))
c84be134
AB
852(run-with-idle-timer 0.5 nil #'require 'hl-todo)
853(with-eval-after-load 'hl-todo
1eb20313 854 ;; highlight TODOs in buffers
41d290a2
AB
855 (global-hl-todo-mode))
856
c84be134
AB
857;; expand-region
858(global-set-key (kbd "C-=") #'er/expand-region)
859
860(run-with-idle-timer 0.6 nil #'require 'yasnippet)
861(with-eval-after-load 'yasnippet
862 (declare-function yas-reload-all
863 "yasnippet" (&optional no-jit interactive))
864 (declare-function yas-maybe-expand-abbrev-key-filter
865 "yasnippet" (cmd))
866
867 (defconst yas-verbosity-cur yas-verbosity)
78d731e1
AB
868 (setq yas-verbosity 2
869 yas-snippet-dirs `(,(b/etc "yasnippet/snippets")))
5df34463 870 ;; (add-to-list 'yas-snippet-dirs "~/src/git/guix/etc/snippets" t)
c84be134
AB
871 (yas-reload-all)
872 (setq yas-verbosity yas-verbosity-cur)
873
874 (defun b/yas-maybe-expand-abbrev-key-filter (cmd)
875 (when (and (yas-maybe-expand-abbrev-key-filter cmd)
876 (not (bound-and-true-p git-commit-mode)))
877 cmd))
878 (defconst b/yas-maybe-expand
879 '(menu-item "" yas-expand
880 :filter b/yas-maybe-expand-abbrev-key-filter))
881 (define-key yas-minor-mode-map (kbd "SPC") b/yas-maybe-expand)
882
883 (yas-global-mode))
884
885;; debbugs
886(global-set-key (kbd "C-c D d") #'debbugs-gnu)
887(global-set-key (kbd "C-c D b") #'debbugs-gnu-bugs)
888(global-set-key (kbd "C-c D e") ; bug-gnu-emacs
889 (lambda ()
890 (interactive)
891 (setq debbugs-gnu-current-suppress t)
892 (debbugs-gnu debbugs-gnu-default-severities
893 '("emacs"))))
894(global-set-key (kbd "C-c D g") ; bug-gnuzilla
895 (lambda ()
896 (interactive)
897 (setq debbugs-gnu-current-suppress t)
898 (debbugs-gnu debbugs-gnu-default-severities
899 '("gnuzilla"))))
c84be134 900
0596e3cf 901;; url and url-cache
78d731e1 902(setq
0596e3cf
AB
903 url-configuration-directory (b/var "url/configuration/")
904 url-cache-directory (b/var "url/cache/"))
905
c84be134 906;; eww
78d731e1
AB
907(setq eww-download-directory (file-name-as-directory
908 (getenv "XDG_DOWNLOAD_DIR")))
c84be134 909(global-set-key (kbd "C-c a e w") #'eww)
41d290a2 910
8c4704d0 911;; ;; org-ref
78d731e1 912;; (setq
8c4704d0
AB
913;; reftex-default-bibliography '("~/usr/org/references.bib")
914;; org-ref-default-bibliography '("~/usr/org/references.bib")
915;; org-ref-bibliography-notes "~/usr/org/notes.org"
916;; org-ref-pdf-directory "~/usr/org/bibtex-pdfs/")
c84be134
AB
917
918;; fill-column-indicator ?
919
920;; window
78d731e1 921(setq split-width-threshold 150)
c84be134
AB
922(global-set-key (kbd "C-c w s l")
923 (lambda ()
924 (interactive)
925 (split-window-right)
926 (other-window 1)))
927(global-set-key (kbd "C-c w s j")
928 (lambda ()
929 (interactive)
930 (split-window-below)
931 (other-window 1)))
932(global-set-key (kbd "C-c w q") #'quit-window)
933
c84be134 934;; pass
8c4704d0
AB
935;; (global-set-key (kbd "C-c a p") #'pass)
936;; (add-hook 'pass-mode-hook #'View-exit)
c84be134
AB
937
938;; reftex
939;; uncomment to disable reftex-cite's default choice of previous word
940;; (with-eval-after-load 'reftex
941;; (require 'reftex-cite)
942;; (defun reftex-get-bibkey-default ()
943;; "If the cursor is in a citation macro, return the word before the macro."
944;; (let* ((macro (reftex-what-macro 1)))
945;; (save-excursion
946;; (when (and macro (string-match "cite" (car macro)))
947;; (goto-char (cdr macro)))
948;; (reftex-this-word)))))
949(add-hook 'latex-mode-hook #'reftex-mode)
950
951;; dmenu
1f5c92ff
AB
952(add-to-list 'load-path (b/lisp "dmenu"))
953(with-eval-after-load 'dmenu
78d731e1
AB
954 (setq dmenu-prompt-string "run: "
955 dmenu-save-file (b/var "dmenu-items")))
1f5c92ff 956(autoload 'dmenu "dmenu" nil t)
c84be134
AB
957
958;; eosd ?
9ed5410e 959
8c4704d0
AB
960;; delight
961(run-with-idle-timer 0.5 nil #'require 'delight)
962(with-eval-after-load 'delight
963 (delight 'auto-fill-function " f" "simple")
964 (delight 'abbrev-mode "" "abbrev")
8c4704d0
AB
965 (delight 'mml-mode " mml" "mml")
966 (delight 'yas-minor-mode "" "yasnippet"))
967
a85421b4
AB
968;; po-mode
969(require 'bandali-po)
970
12e6cf3c 971(with-eval-after-load 'emms
78d731e1 972 (setq emms-directory (b/var "emms")))
12e6cf3c 973
b57457b2 974\f
b57457b2
AB
975;;; Post initialization
976
41d290a2
AB
977(message "Loading %s...done (%.3fs)" user-init-file
978 (float-time (time-subtract (current-time)
dca50cf5 979 b/before-user-init-time)))
41d290a2
AB
980
981;;; init.el ends here