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