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