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