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