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