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