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