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