8449569783ef6b6fb6f475a9b9ffb36c6f0bb7ac
[~bandali/configs] / init.el
1 ;;; init.el --- bandali's emacs configuration -*- lexical-binding: t -*-
2
3 ;; Copyright (C) 2018-2020 Amin Bandali <bandali@gnu.org>
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
20 ;; GNU Emacs configuration of Amin Bandali, computer scientist,
21 ;; Free Software activist, and GNU maintainer & webmaster. Packages
22 ;; are installed through using Borg for a fully reproducible setup.
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
35
36 ;;; Code:
37
38 ;;; Emacs initialization
39
40 (defvar b/before-user-init-time (current-time)
41 "Value of `current-time' when Emacs begins loading `user-init-file'.")
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))))
49
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.
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)
56 (setq gc-cons-threshold (* 30 1024 1024) ; 30 MiB
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
62 ;; set them back to their defaults once we're done initializing
63 (defun b/post-init ()
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
68 file-name-handler-alist b/file-name-handler-alist)
69 (when (featurep 'exwm-workspace)
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
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")))
91 (add-hook 'after-init-hook #'b/post-init)
92
93 ;; increase number of lines kept in *Messages* log
94 (setq message-log-max 20000)
95
96 ;; optionally, uncomment to supress some byte-compiler warnings
97 ;; (see C-h v byte-compile-warnings RET for more info)
98 ;; (setq byte-compile-warnings
99 ;; '(not free-vars unresolved noruntime lexical make-local))
100
101 \f
102 ;;; whoami
103
104 (setq user-full-name "Amin Bandali"
105 user-mail-address "bandali@gnu.org")
106
107 \f
108 ;;; Package management
109
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")
138
139 \f
140 ;;; Initial setup
141
142 ;; keep ~/.emacs.d clean
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.")
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.")
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))
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))
164
165 (csetq
166 auto-save-list-file-prefix (b/var "auto-save/sessions/")
167 nsm-settings-file (b/var "nsm-settings.el"))
168
169 ;; separate custom file (don't want it mixing with init.el)
170 (with-eval-after-load 'custom
171 (setq custom-file (b/etc "custom.el"))
172 (when (file-exists-p custom-file)
173 (load custom-file))
174 ;; while at it, treat themes as safe
175 ;; (setf custom-safe-themes t)
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))))
181
182 ;; load the secrets file if it exists, otherwise show a warning
183 (comment
184 (with-demoted-errors
185 (load (b/etc "secrets"))))
186
187 ;; start up emacs server. see
188 ;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server
189 (run-with-idle-timer 0.5 nil #'require 'server)
190 (with-eval-after-load 'server
191 (declare-function server-edit "server")
192 (global-set-key (kbd "C-c F D") #'server-edit)
193 (declare-function server-running-p "server")
194 (or (server-running-p) (server-mode)))
195
196 \f
197 ;;; Defaults
198
199 ;;;; C-level customizations
200
201 (csetq
202 ;; minibuffer
203 enable-recursive-minibuffers t
204 resize-mini-windows t
205 ;; more useful frame titles
206 ;; frame-title-format '("" invocation-name " - "
207 ;; (:eval
208 ;; (if (buffer-file-name)
209 ;; (abbreviate-file-name (buffer-file-name))
210 ;; "%b")))
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
218 scroll-conservatively 101
219 scroll-preserve-screen-position 1
220 ;; focus follows mouse
221 mouse-autoselect-window t)
222
223 (setq-default
224 ;; always use space for indentation
225 indent-tabs-mode nil
226 tab-width 4
227 ;; case-sensitive search (and `dabbrev-expand')
228 ;; case-fold-search nil
229 ;; cursor shape
230 cursor-type t)
231
232 (set-fontset-font t 'arabic "Vazir")
233
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
267 ;;;; Elisp-level customizations
268
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
289 backup-directory-alist (list (cons "." (b/var "backup/")))
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
301 ;; disable disabled commands
302 (csetq disabled-command-function nil)
303
304 ;; lazy-person-friendly yes/no prompts
305 (defalias 'yes-or-no-p #'y-or-n-p)
306
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)
312
313 ;; time and battery in mode-line
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
324 (csetq battery-mode-line-format " %p%% %t")
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
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'.
341 (defun b/compilation-finish-function (buffer outstr)
342 (unless (string-match "finished" outstr)
343 (switch-to-buffer-other-window buffer))
344 t)
345
346 (setq compilation-finish-functions #'b/compilation-finish-function)
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
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
370 ;; uncomment to extend the above behaviour to query-replace
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")))
414
415 \f
416 ;;; General key bindings
417
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)
423
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)
429
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)
434
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)
439
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)
443
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)
447
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)
452
453 (define-key emacs-lisp-mode-map (kbd "<C-return>") #'b/add-elisp-section)
454
455 (when (display-graphic-p)
456 (global-unset-key (kbd "C-z")))
457
458 \f
459 ;;; Essential packages
460
461 ;; (require 'bandali-exwm)
462
463 (require 'bandali-org)
464
465 (require 'bandali-theme)
466
467 ;; (require 'bandali-magit)
468
469 ;; recently opened files
470 (csetq recentf-max-saved-items 2000
471 recentf-save-file (b/var "recentf-save.el"))
472 (run-with-idle-timer 0.2 nil #'require 'recentf)
473 (with-eval-after-load 'recentf
474 ;; (add-to-list 'recentf-keep #'file-remote-p)
475 (recentf-mode))
476
477 ;; needed for history for counsel
478 (csetq amx-save-file (b/var "amx-save.el"))
479 (add-to-list 'load-path (b/lisp "s"))
480 (add-to-list 'load-path (b/lisp "amx"))
481 (run-with-idle-timer 0.3 nil #'require 'amx)
482 (with-eval-after-load 'amx
483 (amx-mode))
484
485 (require 'bandali-ivy)
486
487 (require 'bandali-eshell)
488
489 (require 'bandali-ibuffer)
490
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)
520
521 (require 'bandali-dired)
522
523 (with-eval-after-load 'help
524 (temp-buffer-resize-mode)
525 (csetq help-window-select t))
526
527 (with-eval-after-load 'help-mode
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
533 (csetq tramp-auto-save-directory (b/var "tramp/auto-save/")
534 tramp-persistency-file-name (b/var "tramp/persistency.el"))
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
540 (with-eval-after-load 'doc-view
541 (define-key doc-view-mode-map (kbd "M-RET") #'image-previous-line))
542
543 (csetq shr-max-width 80)
544
545 ;; Email (with Gnus, message, and EBDB)
546 (require 'bandali-gnus)
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))
552 (require 'bandali-message)
553 (require 'bandali-ebdb)
554
555 ;; IRC (with ERC)
556 (require 'bandali-erc)
557
558 (add-to-list 'load-path (b/lisp "scpaste"))
559 (with-eval-after-load 'scpaste
560 (csetq scpaste-http-destination "https://p.bndl.org"
561 scpaste-scp-destination "p:~"))
562 (autoload 'scpaste "scpaste" nil t)
563 (autoload 'scpaste-region "scpaste" nil t)
564 (global-set-key (kbd "C-c a p p") #'scpaste)
565 (global-set-key (kbd "C-c a p r") #'scpaste-region)
566
567 \f
568 ;;; Editing
569
570 ;; display Lisp objects at point in the echo area
571 (when (version< "25" emacs-version)
572 (with-eval-after-load 'eldoc
573 (csetq eldoc-minor-mode-string " eldoc")
574 (global-eldoc-mode)))
575
576 ;; highlight matching parens
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
590 (column-number-mode 1))
591
592 ;; save minibuffer history
593 (require 'savehist)
594 (csetq savehist-file (b/var "savehist.el"))
595 (savehist-mode)
596 (add-to-list 'savehist-additional-variables 'kill-ring)
597
598 ;; automatically save place in files
599 (when (version< "25" emacs-version)
600 (csetq save-place-file (b/var "save-place.el"))
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
609 (define-key text-mode-map (kbd "C-<return>") #'b/insert-asterism)
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
617 (with-eval-after-load 'flyspell
618 (csetq flyspell-mode-line-string " fly"))
619
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
634 ;; http://endlessparentheses.com/ispell-and-apostrophes.html
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
659 ;; abbrev
660 (csetq abbrev-file-name (b/etc "abbrev.el"))
661 (add-hook 'text-mode-hook #'abbrev-mode)
662
663 \f
664 ;;; Programming modes
665
666 (with-eval-after-load 'lisp-mode
667 (defun indent-spaces-mode ()
668 (setq indent-tabs-mode nil))
669 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
670
671 ;; alloy
672 (add-to-list 'load-path (b/lisp "alloy-mode"))
673 (autoload 'alloy-mode "alloy-mode" nil t)
674 (with-eval-after-load 'alloy-mode
675 (csetq alloy-basic-offset 2)
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)))
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
719 (cl-delete-if
720 (lambda (p) (string-match "^---?" (car p)))
721 tex--prettify-symbols-alist))
722 (add-hook 'tex-mode-hook #'auto-fill-mode)
723 (add-hook 'tex-mode-hook #'flyspell-mode)
724
725 \f
726 ;;; Emacs enhancements & auxiliary packages
727
728 (with-eval-after-load 'man
729 (csetq Man-width 80))
730
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*)
740
741 ;; ,----
742 ;; | make pretty boxed quotes like this
743 ;; `----
744 (add-to-list 'load-path (b/lisp "boxquote"))
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
771 (add-to-list 'load-path (b/lisp "hl-todo"))
772 (run-with-idle-timer 0.5 nil #'require 'hl-todo)
773 (with-eval-after-load 'hl-todo
774 ;; highlight TODOs in buffers
775 (global-hl-todo-mode))
776
777 (add-to-list 'load-path (b/lisp "page-break-lines"))
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)
781 (global-page-break-lines-mode))
782
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)
795 (csetq yas-snippet-dirs `(,(b/etc "yasnippet/snippets")))
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
839 ;; url and url-cache
840 (csetq
841 url-configuration-directory (b/var "url/configuration/")
842 url-cache-directory (b/var "url/cache/"))
843
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)
848
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/")
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
883 ;; (global-set-key (kbd "C-c a p") #'pass)
884 ;; (add-hook 'pass-mode-hook #'View-exit)
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
900 ;; (csetq
901 ;; dmenu-prompt-string "run: "
902 ;; dmenu-save-file (b/var "dmenu-items"))
903
904 ;; eosd ?
905
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
917 \f
918 ;;; Post initialization
919
920 (message "Loading %s...done (%.3fs)" user-init-file
921 (float-time (time-subtract (current-time)
922 b/before-user-init-time)))
923
924 ;;; init.el ends here