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