* init.el: Disable diff-hl for now, don't set case-fold-search
[~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 (defvar b/exwm-p (string= (system-name) "chaman")
45 "Whether or not we will be using `exwm'.")
46
47 (when (not (bound-and-true-p b/emacs-initialized))
48 (message "Loading Emacs...done (%.3fs)"
49 (float-time (time-subtract b/before-user-init-time
50 before-init-time))))
51
52 ;; temporarily increase `gc-cons-threshhold' and `gc-cons-percentage'
53 ;; during startup to reduce garbage collection frequency. clearing
54 ;; `file-name-handler-alist' seems to help reduce startup time too.
55 (defvar b/gc-cons-threshold gc-cons-threshold)
56 (defvar b/gc-cons-percentage gc-cons-percentage)
57 (defvar b/file-name-handler-alist file-name-handler-alist)
58 (setq gc-cons-threshold (* 30 1024 1024) ; 30 MiB
59 gc-cons-percentage 0.6
60 file-name-handler-alist nil
61 ;; sidesteps a bug when profiling with esup
62 esup-child-profile-require-level 0)
63
64 ;; set them back to their defaults once we're done initializing
65 (defun b/post-init ()
66 "My post-initialize function, run after loading `user-init-file'."
67 (setq b/emacs-initialized t
68 gc-cons-threshold b/gc-cons-threshold
69 gc-cons-percentage b/gc-cons-percentage
70 file-name-handler-alist b/file-name-handler-alist)
71 (when b/exwm-p
72 (with-eval-after-load 'exwm-workspace
73 (setq-default
74 mode-line-format
75 (append
76 mode-line-format
77 '((:eval
78 (format
79 "[%s]" (number-to-string
80 exwm-workspace-current-index)))))))))
81 (add-hook 'after-init-hook #'b/post-init)
82
83 ;; increase number of lines kept in *Messages* log
84 (setq message-log-max 20000)
85
86 ;; optionally, uncomment to supress some byte-compiler warnings
87 ;; (see C-h v byte-compile-warnings RET for more info)
88 ;; (setq byte-compile-warnings
89 ;; '(not free-vars unresolved noruntime lexical make-local))
90
91 \f
92 ;;; whoami
93
94 (setq user-full-name "Amin Bandali"
95 user-mail-address "bandali@gnu.org")
96
97 \f
98 ;;; Package management
99
100 (progn ; `borg'
101 (add-to-list 'load-path
102 (expand-file-name "lib/borg" user-emacs-directory))
103 (require 'borg)
104 (borg-initialize)
105 (setq borg-rewrite-urls-alist
106 '(("git@github.com:" . "https://github.com/")
107 ("git@gitlab.com:" . "https://gitlab.com/"))))
108
109 ;; use-package
110 (if nil ; set to t when need to debug init
111 (progn
112 (setq use-package-verbose t
113 use-package-expand-minimally nil
114 use-package-compute-statistics t
115 debug-on-error t)
116 (require 'use-package))
117 (setq use-package-verbose nil
118 use-package-expand-minimally t))
119
120 (setq use-package-always-defer t)
121 (require 'bind-key)
122
123 \f
124 ;;; Initial setup
125
126 ;; keep ~/.emacs.d clean
127 (use-package no-littering
128 :demand
129 :config
130 (defalias 'b/etc 'no-littering-expand-etc-file-name)
131 (defalias 'b/var 'no-littering-expand-var-file-name))
132
133 (use-package auto-compile
134 :demand
135 :config
136 (auto-compile-on-load-mode)
137 (auto-compile-on-save-mode)
138 (setq auto-compile-display-buffer nil)
139 (setq auto-compile-mode-line-counter t)
140 (setq auto-compile-source-recreate-deletes-dest t)
141 (setq auto-compile-toggle-deletes-nonlib-dest t)
142 (setq auto-compile-update-autoloads t))
143
144 ;; separate custom file (don't want it mixing with init.el)
145 (use-package custom
146 :no-require
147 :config
148 (setq custom-file (b/etc "custom.el"))
149 (when (file-exists-p custom-file)
150 (load custom-file))
151 ;; while at it, treat themes as safe
152 (setf custom-safe-themes t)
153 ;; only one custom theme at a time
154 (comment
155 (defadvice load-theme (before clear-previous-themes activate)
156 "Clear existing theme settings instead of layering them"
157 (mapc #'disable-theme custom-enabled-themes))))
158
159 ;; load the secrets file if it exists, otherwise show a warning
160 (comment
161 (with-demoted-errors
162 (load (b/etc "secrets"))))
163
164 ;; start up emacs server. see
165 ;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server
166 (use-package server
167 :defer 0.5
168 :config
169 (declare-function server-edit "server")
170 (bind-key "C-c F D" 'server-edit)
171 (declare-function server-running-p "server")
172 (or (server-running-p) (server-mode)))
173
174 \f
175 ;;; Defaults
176
177 ;;;; C-level customizations
178
179 (setq
180 ;; minibuffer
181 enable-recursive-minibuffers t
182 resize-mini-windows t
183 ;; more useful frame titles
184 frame-title-format '("" invocation-name " - "
185 (:eval
186 (if (buffer-file-name)
187 (abbreviate-file-name (buffer-file-name))
188 "%b")))
189 ;; i don't feel like jumping out of my chair every now and again; so
190 ;; don't BEEP! at me, emacs
191 ring-bell-function 'ignore
192 ;; better scrolling
193 ;; scroll-margin 1
194 ;; scroll-conservatively 10000
195 scroll-step 1
196 scroll-conservatively 101
197 scroll-preserve-screen-position 1
198 ;; focus follows mouse
199 mouse-autoselect-window t)
200
201 (setq-default
202 ;; always use space for indentation
203 indent-tabs-mode nil
204 tab-width 4
205 ;; case-sensitive search (and `dabbrev-expand')
206 ;; case-fold-search nil
207 ;; cursor shape
208 cursor-type t)
209
210 ;; unicode support
211 (comment
212 (dolist (ft (fontset-list))
213 (set-fontset-font
214 ft
215 'unicode
216 (font-spec :name "Source Code Pro" :size 14))
217 (set-fontset-font
218 ft
219 'unicode
220 (font-spec :name "DejaVu Sans Mono")
221 nil
222 'append)
223 ;; (set-fontset-font
224 ;; ft
225 ;; 'unicode
226 ;; (font-spec
227 ;; :name "Symbola monospacified for DejaVu Sans Mono")
228 ;; nil
229 ;; 'append)
230 ;; (set-fontset-font
231 ;; ft
232 ;; #x2115 ; ℕ
233 ;; (font-spec :name "DejaVu Sans Mono")
234 ;; nil
235 ;; 'append)
236 (set-fontset-font
237 ft
238 (cons ?Α ?ω)
239 (font-spec :name "DejaVu Sans Mono" :size 14)
240 nil
241 'prepend)))
242
243 ;;;; Elisp-level customizations
244
245 (use-package startup
246 :no-require
247 :demand
248 :config
249 ;; don't need to see the startup echo area message
250 (advice-add #'display-startup-echo-area-message :override #'ignore)
251 :custom
252 ;; i want *scratch* as my startup buffer
253 (initial-buffer-choice t)
254 ;; i don't need the default hint
255 (initial-scratch-message nil)
256 ;; use customizable text-mode as major mode for *scratch*
257 ;; (initial-major-mode 'text-mode)
258 ;; inhibit buffer list when more than 2 files are loaded
259 (inhibit-startup-buffer-menu t)
260 ;; don't need to see the startup screen or echo area message
261 (inhibit-startup-screen t)
262 (inhibit-startup-echo-area-message user-login-name))
263
264 (use-package files
265 :no-require
266 :demand
267 :custom
268 ;; backups (C-h v make-backup-files RET)
269 (backup-by-copying t)
270 (version-control t)
271 (delete-old-versions t)
272
273 ;; auto-save
274 (auto-save-file-name-transforms
275 `((".*" ,(b/var "auto-save/") t)))
276
277 ;; insert newline at the end of files
278 (require-final-newline t)
279
280 ;; open read-only file buffers in view-mode
281 ;; (enables niceties like `q' for quit)
282 (view-read-only t))
283
284 ;; disable disabled commands
285 (setq disabled-command-function nil)
286
287 ;; lazy-person-friendly yes/no prompts
288 (defalias 'yes-or-no-p #'y-or-n-p)
289
290 ;; enable automatic reloading of changed buffers and files
291 (use-package autorevert
292 :demand
293 :config
294 (global-auto-revert-mode 1)
295 :custom
296 (auto-revert-verbose nil)
297 (global-auto-revert-non-file-buffers nil))
298
299 ;; time and battery in mode-line
300 (use-package time
301 :demand
302 :config
303 (display-time-mode)
304 :custom
305 (display-time-default-load-average nil)
306 (display-time-format " %a %b %-e %-l:%M%P")
307 (display-time-mail-icon '(image :type xpm :file "gnus/gnus-pointer.xpm" :ascent center))
308 (display-time-use-mail-icon t))
309
310 (use-package battery
311 :demand
312 :config
313 (display-battery-mode)
314 :custom
315 (battery-mode-line-format "%p%% %t"))
316
317 (use-package fringe
318 :demand
319 :config
320 ;; smaller fringe
321 ;; (fringe-mode '(3 . 1))
322 (fringe-mode nil))
323
324 (use-package winner
325 :demand
326 :config
327 ;; enable winner-mode (C-h f winner-mode RET)
328 (winner-mode 1))
329
330 (use-package compile
331 :config
332 ;; don't display *compilation* buffer on success. based on
333 ;; https://stackoverflow.com/a/17788551, with changes to use `cl-letf'
334 ;; instead of the now obsolete `flet'.
335 (defun b/compilation-finish-function (buffer outstr)
336 (unless (string-match "finished" outstr)
337 (switch-to-buffer-other-window buffer))
338 t)
339
340 (setq compilation-finish-functions #'b/compilation-finish-function)
341
342 (require 'cl-macs)
343
344 (defadvice compilation-start
345 (around inhibit-display
346 (command &optional mode name-function highlight-regexp))
347 (if (not (string-match "^\\(find\\|grep\\)" command))
348 (cl-letf (((symbol-function 'display-buffer) #'ignore))
349 (save-window-excursion ad-do-it))
350 ad-do-it))
351 (ad-activate 'compilation-start))
352
353 (use-package isearch
354 :custom
355 ;; allow scrolling in Isearch
356 (isearch-allow-scroll t)
357 ;; search for non-ASCII characters: i’d like non-ASCII characters such
358 ;; as ‘’“”«»‹›áⓐ𝒶 to be selected when i search for their ASCII
359 ;; counterpart. shoutout to
360 ;; http://endlessparentheses.com/new-in-emacs-25-1-easily-search-non-ascii-characters.html
361 (search-default-mode #'char-fold-to-regexp))
362
363 ;; uncomment to extend the above behaviour to query-replace
364 (comment
365 (use-package replace
366 :custom
367 (replace-char-fold t)))
368
369 (use-package vc
370 :bind ("C-x v C-=" . vc-ediff))
371
372 (use-package vc-git
373 :after vc
374 :custom
375 (vc-git-print-log-follow t))
376
377 (use-package ediff
378 :config (add-hook 'ediff-after-quit-hook-internal 'winner-undo)
379 :custom ((ediff-window-setup-function 'ediff-setup-windows-plain)
380 (ediff-split-window-function 'split-window-horizontally)))
381
382 (use-package face-remap
383 :custom
384 ;; gentler font resizing
385 (text-scale-mode-step 1.05))
386
387 (use-package mwheel
388 :defer 0.4
389 :config
390 (setq 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 (use-package pixel-scroll
395 :defer 0.4
396 :config (pixel-scroll-mode 1))
397
398 (use-package epg-config
399 :config
400 ;; ask for GPG passphrase in minibuffer
401 ;; this will fail if gpg>=2.1 is not available
402 (setq epg-pinentry-mode 'loopback)
403 :custom
404 (epg-gpg-program (executable-find "gpg")))
405
406 (use-package epg
407 :after epg-config)
408
409 (use-package pinentry
410 :disabled
411 :demand
412 :after (epa epg server)
413 :config
414 ;; workaround for systemd-based distros:
415 ;; (setq pinentry--socket-dir server-socket-dir)
416 (pinentry-start))
417
418 (use-package auth-source
419 :custom
420 (auth-sources '("~/.authinfo.gpg"))
421 (authinfo-hidden (regexp-opt '("password" "client-secret" "token"))))
422
423 \f
424 ;;; General bindings
425
426 (bind-keys
427 ("C-a" . b/move-indentation-or-beginning-of-line)
428 ("C-c a i" . ielm)
429 ("C-c d" . b/duplicate-line-or-region)
430
431 ("C-c e b" . eval-buffer)
432 ("C-c e e" . eval-last-sexp)
433 ("C-c e p" . pp-macroexpand-last-sexp)
434 ("C-c e r" . eval-region)
435
436 ("C-c e i" . emacs-init-time)
437 ("C-c e u" . emacs-uptime)
438 ("C-c e v" . emacs-version)
439
440 ("C-c f ." . find-file)
441 ("C-c f d" . find-name-dired)
442 ("C-c f l" . find-library)
443
444 ("C-c F m" . make-frame-command)
445 ("C-c F d" . delete-frame)
446
447 ("C-S-h C" . describe-char)
448 ("C-S-h F" . describe-face)
449
450 ("C-S-j" . b/join-line-top)
451
452 ("C-c x" . execute-extended-command)
453
454 ("C-x k" . b/kill-current-buffer)
455 ("C-x K" . kill-buffer)
456 ("C-x s" . save-buffer)
457 ("C-x S" . save-some-buffers)
458
459 :map emacs-lisp-mode-map
460 ("<C-return>" . b/add-elisp-section))
461
462 (when (display-graphic-p)
463 (unbind-key "C-z" global-map))
464
465 (bind-keys
466 ;; for back and forward mouse keys
467 ("<XF86Back>" . previous-buffer)
468 ("<mouse-8>" . previous-buffer)
469 ;; ("<drag-mouse-8>" . previous-buffer)
470 ("<XF86Forward>" . next-buffer)
471 ("<mouse-9>" . next-buffer)
472 ;; ("<drag-mouse-9>" . next-buffer)
473 ;; ("<drag-mouse-2>" . kill-this-buffer)
474 ;; ("<drag-mouse-3>" . switch-to-buffer)
475 )
476
477 \f
478 ;;; Essential packages
479
480 (when b/exwm-p
481 (require 'bandali-exwm))
482
483 (require 'bandali-org)
484
485 (require 'bandali-theme)
486
487 ;; *the* right way to do git
488 (use-package magit
489 :bind (("C-x g" . magit-status)
490 ("C-c g g" . magit-status)
491 ("C-c g b" . magit-blame-addition)
492 ("C-c g l" . magit-log-buffer-file))
493 :config
494 (declare-function magit-add-section-hook "magit-section"
495 (hook function &optional at append local))
496 (magit-add-section-hook 'magit-status-sections-hook
497 'magit-insert-modules
498 'magit-insert-stashes
499 'append)
500 ;; (magit-add-section-hook 'magit-status-sections-hook
501 ;; 'magit-insert-ignored-files
502 ;; 'magit-insert-untracked-files
503 ;; 'append)
504 (setq magit-repository-directories '(("~/.emacs.d/" . 0)
505 ("~/src/git/" . 2)))
506 (nconc magit-section-initial-visibility-alist
507 '(([unpulled status] . show)
508 ([unpushed status] . show)))
509 (declare-function magit-display-buffer-fullframe-status-v1 "magit-mode" (buffer))
510 :custom
511 (magit-diff-refine-hunk t)
512 (magit-display-buffer-function #'magit-display-buffer-fullframe-status-v1)
513 ;; (magit-completing-read-function 'magit-ido-completing-read)
514 :custom-face (magit-diff-file-heading ((t (:weight normal)))))
515
516 ;; recently opened files
517 (use-package recentf
518 :defer 0.2
519 :config
520 (add-to-list 'recentf-keep 'file-remote-p)
521 :config
522 (recentf-mode)
523 :custom
524 (recentf-max-saved-items 2000))
525
526 ;; needed for history for counsel
527 (use-package amx
528 :defer 0.3
529 :config
530 (amx-mode))
531
532 ;; (require 'bandali-ido)
533 (require 'bandali-ivy)
534
535 (require 'bandali-eshell)
536 ;; (require 'bandali-multi-term)
537
538 (require 'bandali-ibuffer)
539
540 (use-package outline
541 :disabled
542 :hook (prog-mode . outline-minor-mode)
543 :bind
544 (:map
545 outline-minor-mode-map
546 ("<s-tab>" . outline-toggle-children)
547 ("M-p" . outline-previous-visible-heading)
548 ("M-n" . outline-next-visible-heading)
549 :prefix-map b/outline-prefix-map
550 :prefix "s-O"
551 ("TAB" . outline-toggle-children)
552 ("a" . outline-hide-body)
553 ("H" . outline-hide-body)
554 ("S" . outline-show-all)
555 ("h" . outline-hide-subtree)
556 ("s" . outline-show-subtree))
557 :config
558 (when (featurep 'which-key)
559 (which-key-add-key-based-replacements
560 "C-c @" "outline"
561 "s-O" "outline")))
562
563 (require 'bandali-dired)
564
565 (use-package help
566 :bind
567 (:map help-mode-map
568 ("p" . backward-button)
569 ("n" . forward-button))
570 :config
571 (temp-buffer-resize-mode)
572 (setq help-window-select t))
573
574 (use-package tramp
575 :config
576 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
577 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
578 (add-to-list 'tramp-default-proxies-alist
579 (list (regexp-quote (system-name)) nil nil)))
580
581 (use-package doc-view
582 :bind (:map doc-view-mode-map
583 ("M-RET" . image-previous-line)))
584
585 ;; Email (with Gnus, message, and EBDB)
586 (require 'bandali-gnus)
587 (use-package sendmail
588 :config
589 (setq sendmail-program (executable-find "msmtp")
590 ;; message-sendmail-extra-arguments '("-v" "-d")
591 mail-specify-envelope-from t
592 mail-envelope-from 'header))
593 (require 'bandali-message)
594 (require 'bandali-ebdb)
595
596 ;; IRC (with ERC and ZNC)
597 (require 'bandali-erc)
598
599 (use-package scpaste
600 :config
601 (setq scpaste-http-destination "https://p.bndl.org"
602 scpaste-scp-destination "p:~"))
603
604 \f
605 ;;; Editing
606
607 ;; highlight uncommitted changes in the left fringe
608 (use-package diff-hl
609 :disabled
610 :defer 0.6
611 :config
612 (setq diff-hl-draw-borders nil)
613 (global-diff-hl-mode)
614 :hook
615 ((magit-pre-refresh . diff-hl-magit-pre-refresh)
616 (magit-post-refresh . diff-hl-magit-post-refresh)))
617
618 ;; display Lisp objects at point in the echo area
619 (use-package eldoc
620 :when (version< "25" emacs-version)
621 :config (global-eldoc-mode))
622
623 ;; highlight matching parens
624 (use-package paren
625 :demand
626 :config (show-paren-mode))
627
628 (use-package elec-pair
629 :demand
630 :config (electric-pair-mode))
631
632 (use-package simple
633 :config (column-number-mode)
634 :custom
635 ;; Save what I copy into clipboard from other applications into Emacs'
636 ;; kill-ring, which would allow me to still be able to easily access
637 ;; it in case I kill (cut or copy) something else inside Emacs before
638 ;; yanking (pasting) what I'd originally intended to.
639 (save-interprogram-paste-before-kill t))
640
641 ;; save minibuffer history
642 (use-package savehist
643 :demand
644 :config
645 (savehist-mode)
646 (add-to-list 'savehist-additional-variables 'kill-ring))
647
648 ;; automatically save place in files
649 (use-package saveplace
650 :when (version< "25" emacs-version)
651 :config (save-place-mode))
652
653 (use-package prog-mode
654 :config (global-prettify-symbols-mode)
655 (defun indicate-buffer-boundaries-left ()
656 (setq indicate-buffer-boundaries 'left))
657 (add-hook 'prog-mode-hook #'indicate-buffer-boundaries-left))
658
659 (use-package text-mode
660 :bind (:map text-mode-map ("C-*" . b/insert-asterism))
661 :hook ((text-mode . indicate-buffer-boundaries-left)
662 (text-mode . flyspell-mode)))
663
664 (use-package conf-mode
665 :mode "\\.*rc$")
666
667 (use-package sh-script
668 :mode ("\\.bashrc$" . sh-mode))
669
670 (use-package company
671 :disabled
672 :bind
673 (:map company-active-map
674 ([tab] . company-complete-common-or-cycle)
675 ([escape] . company-abort)
676 ("C-p" . company-select-previous-or-abort)
677 ("C-n" . company-select-next-or-abort))
678 :custom
679 (company-minimum-prefix-length 1)
680 (company-selection-wrap-around t)
681 (company-dabbrev-char-regexp "\\sw\\|\\s_\\|[-_]")
682 (company-dabbrev-downcase nil)
683 (company-dabbrev-ignore-case nil)
684 ;; :config
685 ;; (global-company-mode t)
686 )
687
688 (use-package flycheck
689 :disabled
690 :defer 0.6
691 :hook (prog-mode . flycheck-mode)
692 :bind
693 (:map flycheck-mode-map
694 ("M-P" . flycheck-previous-error)
695 ("M-N" . flycheck-next-error))
696 :config
697 ;; Use the load-path from running Emacs when checking elisp files
698 (setq flycheck-emacs-lisp-load-path 'inherit)
699
700 ;; Only flycheck when I actually save the buffer
701 (setq flycheck-check-syntax-automatically '(mode-enabled save))
702 :custom (flycheck-mode-line-prefix "flyc"))
703
704 ;; (use-package flyspell)
705
706 ;; http://endlessparentheses.com/ispell-and-apostrophes.html
707 (use-package ispell
708 :disabled
709 :defer 0.6
710 :config
711 ;; ’ can be part of a word
712 (setq ispell-local-dictionary-alist
713 `((nil "[[:alpha:]]" "[^[:alpha:]]"
714 "['\x2019]" nil ("-B") nil utf-8))
715 ispell-program-name (executable-find "hunspell"))
716 ;; don't send ’ to the subprocess
717 (defun endless/replace-apostrophe (args)
718 (cons (replace-regexp-in-string
719 "’" "'" (car args))
720 (cdr args)))
721 (advice-add #'ispell-send-string :filter-args
722 #'endless/replace-apostrophe)
723
724 ;; convert ' back to ’ from the subprocess
725 (defun endless/replace-quote (args)
726 (if (not (derived-mode-p 'org-mode))
727 args
728 (cons (replace-regexp-in-string
729 "'" "’" (car args))
730 (cdr args))))
731 (advice-add #'ispell-parse-output :filter-args
732 #'endless/replace-quote))
733
734 (use-package abbrev
735 :hook (text-mode . abbrev-mode))
736
737 \f
738 ;;; Programming modes
739
740 (use-package lisp-mode
741 :config
742 (defun indent-spaces-mode ()
743 (setq indent-tabs-mode nil))
744 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
745
746 (use-package alloy-mode
747 :mode "\\.\\(als\\|dsh\\)\\'"
748 :config
749 (setq alloy-basic-offset 2)
750 ;; (defun b/alloy-simple-indent (start end)
751 ;; (interactive "r")
752 ;; ;; (if (region-active-p)
753 ;; ;; (indent-rigidly start end alloy-basic-offset)
754 ;; ;; (if (bolp)
755 ;; ;; (indent-rigidly (line-beginning-position)
756 ;; ;; (line-end-position)
757 ;; ;; alloy-basic-offset)))
758 ;; (indent-to (+ (current-column) alloy-basic-offset)))
759 :bind (:map alloy-mode-map
760 ("RET" . electric-newline-and-maybe-indent)
761 ;; ("TAB" . b/alloy-simple-indent)
762 ("TAB" . indent-for-tab-command))
763 :hook (alloy-mode . (lambda () (setq-local indent-tabs-mode nil))))
764
765 (use-package lean-mode
766 :disabled
767 :defer 0.4
768 :init (eval-when-compile (defvar lean-mode-map))
769 :bind (:map lean-mode-map
770 ("S-SPC" . company-complete))
771 :config
772 (require 'lean-input)
773 (setq default-input-method "Lean"
774 lean-input-tweak-all '(lean-input-compose
775 (lean-input-prepend "/")
776 (lean-input-nonempty))
777 lean-input-user-translations '(("/" "/")))
778 (lean-input-setup))
779
780 (use-package sgml-mode
781 :config
782 (setq sgml-basic-offset 0))
783
784 (use-package css-mode
785 :config
786 (setq css-indent-offset 2))
787
788 (use-package geiser
789 :disabled)
790
791 (use-package geiser-guile
792 :disabled
793 :config
794 (setq geiser-guile-load-path "~/src/git/guix"))
795
796 (use-package guix
797 :disabled)
798
799 (use-package go-mode
800 :disabled)
801
802 (use-package po-mode
803 :disabled
804 :hook
805 (po-mode . (lambda () (run-with-timer 0.1 nil 'View-exit))))
806
807 (use-package auctex
808 :disabled
809 :custom
810 (font-latex-fontify-sectioning 'color))
811
812 (use-package tex-mode
813 :config
814 (cl-delete-if
815 (lambda (p) (string-match "^---?" (car p)))
816 tex--prettify-symbols-alist)
817 :hook ((tex-mode . auto-fill-mode)
818 (tex-mode . flyspell-mode)))
819
820 ;; (use-package george-mode
821 ;; :straight (:host nil :repo "https://git.shemshak.org/amin/george-mode")
822 ;; :mode "\\.grg\\'")
823
824 \f
825 ;;; Emacs enhancements & auxiliary packages
826
827 (use-package man
828 :config (setq Man-width 80))
829
830 (use-package which-key
831 :defer 0.4
832 :config
833 (which-key-add-key-based-replacements
834 ;; prefixes for global prefixes and minor modes
835 "C-c !" "flycheck"
836 "C-x RET" "coding system"
837 "C-x 8" "unicode"
838 "C-x @" "event modifiers"
839 "C-x a" "abbrev/expand"
840 "C-x r" "rectangle/register/bookmark"
841 "C-x t" "tabs"
842 "C-x v" "version control"
843 "C-x X" "edebug"
844 "C-x C-a" "edebug"
845 "C-x C-k" "kmacro"
846 ;; prefixes for my personal bindings
847 "C-c &" "yasnippet"
848 "C-c a" "applications"
849 "C-c a e" "erc"
850 "C-c a o" "org"
851 "C-c a s" "shells"
852 "C-c b" "buffers"
853 "C-c c" "compile-and-comments"
854 "C-c e" "eval"
855 "C-c f" "files"
856 "C-c F" "frames"
857 "C-c g" "magit"
858 "C-S-h" "help(ful)"
859 "C-c q" "boxquote"
860 "C-c t" "themes")
861
862 ;; prefixes for major modes
863 (which-key-add-major-mode-key-based-replacements 'org-mode
864 "C-c C-v" "org-babel")
865
866 (which-key-mode)
867 :custom
868 (which-key-add-column-padding 5)
869 (which-key-idle-delay 10000)
870 (which-key-idle-secondary-delay 0.05)
871 (which-key-max-description-length 32)
872 (which-key-show-early-on-C-h t))
873
874 ;; (require 'bandali-projectile)
875
876 (use-package helpful
877 :disabled
878 :defer 0.6
879 :bind
880 (("C-S-h c" . helpful-command)
881 ("C-S-h f" . helpful-callable) ; helpful-function
882 ("C-S-h v" . helpful-variable)
883 ("C-S-h k" . helpful-key)
884 ("C-S-h p" . helpful-at-point)))
885
886 (use-package unkillable-scratch
887 :defer 0.6
888 :config
889 (unkillable-scratch 1)
890 :custom
891 (unkillable-buffers '("^\\*scratch\\*$" "^\\*Messages\\*$")))
892
893 ;; ,----
894 ;; | make pretty boxed quotes like this
895 ;; `----
896 (use-package boxquote
897 :defer 0.6
898 :bind
899 (:prefix-map
900 b/boxquote-prefix-map
901 :prefix "C-c q"
902 ("b" . boxquote-buffer)
903 ("B" . boxquote-insert-buffer)
904 ("d" . boxquote-defun)
905 ("F" . boxquote-insert-file)
906 ("hf" . boxquote-describe-function)
907 ("hk" . boxquote-describe-key)
908 ("hv" . boxquote-describe-variable)
909 ("hw" . boxquote-where-is)
910 ("k" . boxquote-kill)
911 ("p" . boxquote-paragraph)
912 ("q" . boxquote-boxquote)
913 ("r" . boxquote-region)
914 ("s" . boxquote-shell-command)
915 ("t" . boxquote-text)
916 ("T" . boxquote-title)
917 ("u" . boxquote-unbox)
918 ("U" . boxquote-unbox-region)
919 ("y" . boxquote-yank)
920 ("M-q" . boxquote-fill-paragraph)
921 ("M-w" . boxquote-kill-ring-save)))
922
923 (use-package hl-todo
924 ;; highlight TODOs in buffers
925 :defer 0.5
926 :config
927 (global-hl-todo-mode))
928
929 (use-package page-break-lines
930 :defer 0.5
931 :custom
932 (page-break-lines-max-width fill-column)
933 :config
934 (global-page-break-lines-mode))
935
936 (use-package expand-region
937 :bind ("C-=" . er/expand-region))
938
939 (require 'bandali-yasnippet)
940
941 (use-package debbugs
942 :bind
943 (("C-c D d" . debbugs-gnu)
944 ("C-c D b" . debbugs-gnu-bugs)
945 ("C-c D e" .
946 (lambda ()
947 (interactive) ; bug-gnu-emacs
948 (setq debbugs-gnu-current-suppress t)
949 (debbugs-gnu debbugs-gnu-default-severities '("emacs"))))
950 ("C-c D g" . ; bug-gnuzilla
951 (lambda ()
952 (interactive)
953 (setq debbugs-gnu-current-suppress t)
954 (debbugs-gnu debbugs-gnu-default-severities '("gnuzilla"))))
955 ("C-c D G b" . ; bug-guix
956 (lambda ()
957 (interactive)
958 (setq debbugs-gnu-current-suppress t)
959 (debbugs-gnu debbugs-gnu-default-severities '("guix"))))
960 ("C-c D G p" . ; guix-patches
961 (lambda ()
962 (interactive)
963 (setq debbugs-gnu-current-suppress t)
964 (debbugs-gnu debbugs-gnu-default-severities '("guix-patches"))))))
965
966 (comment
967
968 (use-package org-ref
969 :init
970 (b/setq-every '("~/usr/org/references.bib")
971 reftex-default-bibliography
972 org-ref-default-bibliography)
973 (setq
974 org-ref-bibliography-notes "~/usr/org/notes.org"
975 org-ref-pdf-directory "~/usr/org/bibtex-pdfs/"))
976
977 ;; (use-package fill-column-indicator)
978
979 (use-package window
980 :bind
981 (("C-c w s l" . (lambda ()
982 (interactive)
983 (split-window-right)
984 (other-window 1)))
985 ("C-c w s j" . (lambda ()
986 (interactive)
987 (split-window-below)
988 (other-window 1)))
989 ("C-c w q" . quit-window))
990 :custom
991 (split-width-threshold 150))
992
993 (use-package windmove
994 :defer 0.6
995 :bind
996 (("C-c w h" . windmove-left)
997 ("C-c w j" . windmove-down)
998 ("C-c w k" . windmove-up)
999 ("C-c w l" . windmove-right)
1000 ("C-c w H" . windmove-swap-states-left)
1001 ("C-c w J" . windmove-swap-states-down)
1002 ("C-c w K" . windmove-swap-states-up)
1003 ("C-c w L" . windmove-swap-states-right)))
1004
1005 (use-package pass
1006 :commands pass
1007 :bind ("C-c a p" . pass)
1008 :hook (pass-mode . View-exit))
1009
1010 (use-package pdf-tools
1011 :defer 0.5
1012 :bind (:map pdf-view-mode-map
1013 ("<C-XF86Back>" . pdf-history-backward)
1014 ("<mouse-8>" . pdf-history-backward)
1015 ("<drag-mouse-8>" . pdf-history-backward)
1016 ("<C-XF86Forward>" . pdf-history-forward)
1017 ("<mouse-9>" . pdf-history-forward)
1018 ("<drag-mouse-9>" . pdf-history-forward)
1019 ("M-RET" . image-previous-line)
1020 ("C-s" . isearch-forward)
1021 ("s s" . isearch-forward))
1022 :config (pdf-tools-install nil t)
1023 :custom (pdf-view-resize-factor 1.05))
1024
1025 (use-package org-pdftools
1026 :disabled
1027 :straight (:host github :repo "fuxialexander/org-pdftools")
1028 :demand
1029 :after org
1030 :config
1031 (with-eval-after-load 'org
1032 (require 'org-pdftools)))
1033
1034 (use-package biblio)
1035
1036 (use-package reftex
1037 :hook (latex-mode . reftex-mode))
1038
1039 (use-package reftex-cite
1040 :after reftex
1041 :disabled ; enable to disable
1042 ; reftex-cite's default choice
1043 ; of previous word
1044 :config
1045 (defun reftex-get-bibkey-default ()
1046 "If the cursor is in a citation macro, return the word before the macro."
1047 (let* ((macro (reftex-what-macro 1)))
1048 (save-excursion
1049 (when (and macro (string-match "cite" (car macro)))
1050 (goto-char (cdr macro)))
1051 (reftex-this-word)))))
1052
1053 (use-package dmenu
1054 :custom
1055 (dmenu-prompt-string "run: ")
1056 (dmenu-save-file (b/var "dmenu-items")))
1057
1058 (use-package eosd
1059 ;; TODO: fix build by properly building the eosd-pixbuf.c module
1060 ;; e.g. see https://github.com/raxod502/straight.el/issues/386
1061 :disabled
1062 :straight (:host github :repo "clarete/eosd")
1063 :demand
1064 :after exwm
1065 :config
1066 (eosd-start))
1067
1068 (use-package eww
1069 :bind ("C-c a e w" . eww)
1070 :custom
1071 (eww-download-directory (file-name-as-directory
1072 (getenv "XDG_DOWNLOAD_DIR"))))
1073
1074 \f
1075 ;;; Post initialization
1076
1077 )
1078 (message "Loading %s...done (%.3fs)" user-init-file
1079 (float-time (time-subtract (current-time)
1080 b/before-user-init-time)))
1081
1082 ;;; init.el ends here