* init.el: Add b/join-line-top for joining the next line to this one
[~bandali/configs] / init.el
... / ...
CommitLineData
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;;; comment macro
99
100;; useful for commenting out multiple sexps at a time
101(defmacro comment (&rest _)
102 "Comment out one or more s-expressions."
103 (declare (indent defun))
104 nil)
105
106\f
107;;; Package management
108
109(progn ; `borg'
110 (add-to-list 'load-path
111 (expand-file-name "lib/borg" user-emacs-directory))
112 (require 'borg)
113 (borg-initialize)
114 (setq borg-rewrite-urls-alist
115 '(("git@github.com:" . "https://github.com/")
116 ("git@gitlab.com:" . "https://gitlab.com/"))))
117
118;; use-package
119(if nil ; set to t when need to debug init
120 (progn
121 (setq use-package-verbose t
122 use-package-expand-minimally nil
123 use-package-compute-statistics t
124 debug-on-error t)
125 (require 'use-package))
126 (setq use-package-verbose nil
127 use-package-expand-minimally t))
128
129(setq use-package-always-defer t)
130(require 'bind-key)
131
132\f
133;;; Initial setup
134
135;; keep ~/.emacs.d clean
136(use-package no-littering
137 :demand
138 :config
139 (defalias 'b/etc 'no-littering-expand-etc-file-name)
140 (defalias 'b/var 'no-littering-expand-var-file-name))
141
142(use-package auto-compile
143 :demand
144 :config
145 (auto-compile-on-load-mode)
146 (auto-compile-on-save-mode)
147 (setq auto-compile-display-buffer nil)
148 (setq auto-compile-mode-line-counter t)
149 (setq auto-compile-source-recreate-deletes-dest t)
150 (setq auto-compile-toggle-deletes-nonlib-dest t)
151 (setq auto-compile-update-autoloads t))
152
153;; separate custom file (don't want it mixing with init.el)
154(use-package custom
155 :no-require
156 :config
157 (setq custom-file (b/etc "custom.el"))
158 (when (file-exists-p custom-file)
159 (load custom-file))
160 ;; while at it, treat themes as safe
161 (setf custom-safe-themes t)
162 ;; only one custom theme at a time
163 (comment
164 (defadvice load-theme (before clear-previous-themes activate)
165 "Clear existing theme settings instead of layering them"
166 (mapc #'disable-theme custom-enabled-themes))))
167
168;; load the secrets file if it exists, otherwise show a warning
169(comment
170 (with-demoted-errors
171 (load (b/etc "secrets"))))
172
173;; start up emacs server. see
174;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server
175(use-package server
176 :defer 0.5
177 :config
178 (declare-function server-edit "server")
179 (bind-key "C-c F D" 'server-edit)
180 (declare-function server-running-p "server")
181 (or (server-running-p) (server-mode)))
182
183\f
184;;; Useful utilities
185
186(defmacro b/setq-every (value &rest vars)
187 "Set all the variables from VARS to value VALUE."
188 (declare (indent defun) (debug t))
189 `(progn ,@(mapcar (lambda (x) (list 'setq x value)) vars)))
190
191(defun b/start-process (program &rest args)
192 "Same as `start-process', but doesn't bother about name and buffer."
193 (let ((process-name (concat program "_process"))
194 (buffer-name (generate-new-buffer-name
195 (concat program "_output"))))
196 (apply #'start-process
197 process-name buffer-name program args)))
198
199(defun b/dired-start-process (program &optional args)
200 "Open current file with a PROGRAM."
201 ;; Shell command looks like this: "program [ARGS]... FILE" (ARGS can
202 ;; be nil, so remove it).
203 (declare-function dired-get-file-for-visit "dired")
204 (apply #'b/start-process
205 program
206 (remove nil (list args (dired-get-file-for-visit)))))
207
208(defun b/add-elisp-section ()
209 (interactive)
210 (insert "\n")
211 (forward-line -1)
212 (insert "\n\f\n;;; "))
213
214;; (defvar b/fill-column 47
215;; "My custom `fill-column'.")
216
217(defconst b/asterism "* * *")
218
219(defun b/insert-asterism ()
220 "Insert a centred asterism."
221 (interactive)
222 (insert
223 (concat
224 "\n\n"
225 (make-string (floor (/ (- fill-column (length b/asterism)) 2))
226 ?\s)
227 b/asterism
228 "\n\n")))
229
230(defun b/no-mouse-autoselect-window ()
231 "Conveniently disable `focus-follows-mouse'.
232For disabling the behaviour for certain buffers and/or modes."
233 (make-local-variable 'mouse-autoselect-window)
234 (setq mouse-autoselect-window nil))
235
236(defun b/kill-current-buffer ()
237 "Kill the current buffer."
238 ;; also see https://redd.it/64xb3q
239 (interactive)
240 (kill-buffer (current-buffer)))
241
242(defun b/move-indentation-or-beginning-of-line (arg)
243 "Move to the indentation or to the beginning of line."
244 (interactive "^p")
245 ;; (if (bolp)
246 ;; (back-to-indentation)
247 ;; (move-beginning-of-line arg))
248 (if (= (point)
249 (progn (back-to-indentation)
250 (point)))
251 (move-beginning-of-line arg)))
252
253(defun b/join-line-top ()
254 "Like `join-line', but join next line to the current line."
255 (interactive)
256 (join-line 1))
257
258\f
259;;; Defaults
260
261;;;; C-level customizations
262
263(setq
264 ;; minibuffer
265 enable-recursive-minibuffers t
266 resize-mini-windows t
267 ;; more useful frame titles
268 frame-title-format '("" invocation-name " - "
269 (:eval
270 (if (buffer-file-name)
271 (abbreviate-file-name (buffer-file-name))
272 "%b")))
273 ;; i don't feel like jumping out of my chair every now and again; so
274 ;; don't BEEP! at me, emacs
275 ring-bell-function 'ignore
276 ;; better scrolling
277 ;; scroll-margin 1
278 ;; scroll-conservatively 10000
279 scroll-step 1
280 scroll-conservatively 10
281 scroll-preserve-screen-position 1
282 ;; focus follows mouse
283 mouse-autoselect-window t)
284
285(setq-default
286 ;; always use space for indentation
287 indent-tabs-mode nil
288 tab-width 4
289 ;; cursor shape
290 cursor-type t)
291
292;; unicode support
293(comment
294 (dolist (ft (fontset-list))
295 (set-fontset-font
296 ft
297 'unicode
298 (font-spec :name "Source Code Pro" :size 14))
299 (set-fontset-font
300 ft
301 'unicode
302 (font-spec :name "DejaVu Sans Mono")
303 nil
304 'append)
305 ;; (set-fontset-font
306 ;; ft
307 ;; 'unicode
308 ;; (font-spec
309 ;; :name "Symbola monospacified for DejaVu Sans Mono")
310 ;; nil
311 ;; 'append)
312 ;; (set-fontset-font
313 ;; ft
314 ;; #x2115 ; ℕ
315 ;; (font-spec :name "DejaVu Sans Mono")
316 ;; nil
317 ;; 'append)
318 (set-fontset-font
319 ft
320 (cons ?Α ?ω)
321 (font-spec :name "DejaVu Sans Mono" :size 14)
322 nil
323 'prepend)))
324
325;;;; Elisp-level customizations
326
327(use-package startup
328 :no-require
329 :demand
330 :config
331 ;; don't need to see the startup echo area message
332 (advice-add #'display-startup-echo-area-message :override #'ignore)
333 :custom
334 ;; i want *scratch* as my startup buffer
335 (initial-buffer-choice t)
336 ;; i don't need the default hint
337 (initial-scratch-message nil)
338 ;; use customizable text-mode as major mode for *scratch*
339 ;; (initial-major-mode 'text-mode)
340 ;; inhibit buffer list when more than 2 files are loaded
341 (inhibit-startup-buffer-menu t)
342 ;; don't need to see the startup screen or echo area message
343 (inhibit-startup-screen t)
344 (inhibit-startup-echo-area-message user-login-name))
345
346(use-package files
347 :no-require
348 :demand
349 :custom
350 ;; backups (C-h v make-backup-files RET)
351 (backup-by-copying t)
352 (version-control t)
353 (delete-old-versions t)
354
355 ;; auto-save
356 (auto-save-file-name-transforms
357 `((".*" ,(b/var "auto-save/") t)))
358
359 ;; insert newline at the end of files
360 (require-final-newline t)
361
362 ;; open read-only file buffers in view-mode
363 ;; (enables niceties like `q' for quit)
364 (view-read-only t))
365
366;; disable disabled commands
367(setq disabled-command-function nil)
368
369;; lazy-person-friendly yes/no prompts
370(defalias 'yes-or-no-p #'y-or-n-p)
371
372;; enable automatic reloading of changed buffers and files
373(use-package autorevert
374 :demand
375 :config
376 (global-auto-revert-mode 1)
377 :custom
378 (auto-revert-verbose nil)
379 (global-auto-revert-non-file-buffers nil))
380
381;; time and battery in mode-line
382(use-package time
383 :demand
384 :config
385 (display-time-mode)
386 :custom
387 (display-time-default-load-average nil)
388 (display-time-format " %a %b %-e %-l:%M%P")
389 (display-time-mail-icon '(image :type xpm :file "gnus/gnus-pointer.xpm" :ascent center))
390 (display-time-use-mail-icon t))
391
392(use-package battery
393 :demand
394 :config
395 (display-battery-mode)
396 :custom
397 (battery-mode-line-format "%p%% %t"))
398
399(use-package fringe
400 :demand
401 :config
402 ;; smaller fringe
403 ;; (fringe-mode '(3 . 1))
404 (fringe-mode nil))
405
406(use-package winner
407 :demand
408 :config
409 ;; enable winner-mode (C-h f winner-mode RET)
410 (winner-mode 1))
411
412(use-package compile
413 :config
414 ;; don't display *compilation* buffer on success. based on
415 ;; https://stackoverflow.com/a/17788551, with changes to use `cl-letf'
416 ;; instead of the now obsolete `flet'.
417 (defun b/compilation-finish-function (buffer outstr)
418 (unless (string-match "finished" outstr)
419 (switch-to-buffer-other-window buffer))
420 t)
421
422 (setq compilation-finish-functions #'b/compilation-finish-function)
423
424 (require 'cl-macs)
425
426 (defadvice compilation-start
427 (around inhibit-display
428 (command &optional mode name-function highlight-regexp))
429 (if (not (string-match "^\\(find\\|grep\\)" command))
430 (cl-letf (((symbol-function 'display-buffer) #'ignore))
431 (save-window-excursion ad-do-it))
432 ad-do-it))
433 (ad-activate 'compilation-start))
434
435(use-package isearch
436 :custom
437 ;; allow scrolling in Isearch
438 (isearch-allow-scroll t)
439 ;; search for non-ASCII characters: i’d like non-ASCII characters such
440 ;; as ‘’“”«»‹›áⓐ𝒶 to be selected when i search for their ASCII
441 ;; counterpart. shoutout to
442 ;; http://endlessparentheses.com/new-in-emacs-25-1-easily-search-non-ascii-characters.html
443 (search-default-mode #'char-fold-to-regexp))
444
445;; uncomment to extend the above behaviour to query-replace
446(comment
447 (use-package replace
448 :custom
449 (replace-char-fold t)))
450
451(use-package vc
452 :bind ("C-x v C-=" . vc-ediff))
453
454(use-package vc-git
455 :after vc
456 :custom
457 (vc-git-print-log-follow t))
458
459(use-package ediff
460 :config (add-hook 'ediff-after-quit-hook-internal 'winner-undo)
461 :custom ((ediff-window-setup-function 'ediff-setup-windows-plain)
462 (ediff-split-window-function 'split-window-horizontally)))
463
464(use-package face-remap
465 :custom
466 ;; gentler font resizing
467 (text-scale-mode-step 1.05))
468
469(use-package mwheel
470 :defer 0.4
471 :config
472 (setq mouse-wheel-scroll-amount '(1 ((shift) . 1)) ; one line at a time
473 mouse-wheel-progressive-speed nil ; don't accelerate scrolling
474 mouse-wheel-follow-mouse t)) ; scroll window under mouse
475
476(use-package pixel-scroll
477 :defer 0.4
478 :config (pixel-scroll-mode 1))
479
480(use-package epg-config
481 :config
482 ;; ask for GPG passphrase in minibuffer
483 ;; this will fail if gpg>=2.1 is not available
484 (setq epg-pinentry-mode 'loopback)
485 :custom
486 (epg-gpg-program (executable-find "gpg")))
487
488(use-package epg
489 :after epg-config)
490
491(use-package pinentry
492 :disabled
493 :demand
494 :after (epa epg server)
495 :config
496 ;; workaround for systemd-based distros:
497 ;; (setq pinentry--socket-dir server-socket-dir)
498 (pinentry-start))
499
500(use-package auth-source
501 :custom
502 (auth-sources '("~/.authinfo.gpg"))
503 (authinfo-hidden (regexp-opt '("password" "client-secret" "token"))))
504
505\f
506;;; General bindings
507
508(bind-keys
509 ("C-a" . b/move-indentation-or-beginning-of-line)
510 ("C-c a i" . ielm)
511
512 ("C-c e b" . eval-buffer)
513 ("C-c e e" . eval-last-sexp)
514 ("C-c e p" . pp-macroexpand-last-sexp)
515 ("C-c e r" . eval-region)
516
517 ("C-c e i" . emacs-init-time)
518 ("C-c e u" . emacs-uptime)
519 ("C-c e v" . emacs-version)
520
521 ("C-c f ." . find-file)
522 ("C-c f d" . find-name-dired)
523 ("C-c f l" . find-library)
524
525 ("C-c F m" . make-frame-command)
526 ("C-c F d" . delete-frame)
527
528 ("C-S-h C" . describe-char)
529 ("C-S-h F" . describe-face)
530
531 ("C-S-j" . b/join-line-top)
532
533 ("C-c x" . execute-extended-command)
534
535 ("C-x k" . b/kill-current-buffer)
536 ("C-x K" . kill-buffer)
537 ("C-x s" . save-buffer)
538 ("C-x S" . save-some-buffers)
539
540 :map emacs-lisp-mode-map
541 ("<C-return>" . b/add-elisp-section))
542
543(when (display-graphic-p)
544 (unbind-key "C-z" global-map))
545
546(bind-keys
547 ;; for back and forward mouse keys
548 ("<XF86Back>" . previous-buffer)
549 ("<mouse-8>" . previous-buffer)
550 ;; ("<drag-mouse-8>" . previous-buffer)
551 ("<XF86Forward>" . next-buffer)
552 ("<mouse-9>" . next-buffer)
553 ;; ("<drag-mouse-9>" . next-buffer)
554 ;; ("<drag-mouse-2>" . kill-this-buffer)
555 ;; ("<drag-mouse-3>" . switch-to-buffer)
556 )
557
558\f
559;;; Essential packages
560
561(add-to-list
562 'load-path
563 (expand-file-name
564 (convert-standard-filename "lisp") user-emacs-directory))
565
566(when b/exwm-p
567 (require 'bandali-exwm))
568
569(require 'bandali-org)
570
571;; *the* right way to do git
572(use-package magit
573 :bind (("C-x g" . magit-status)
574 ("C-c g g" . magit-status)
575 ("C-c g b" . magit-blame-addition)
576 ("C-c g l" . magit-log-buffer-file))
577 :config
578 (declare-function magit-add-section-hook "magit-section"
579 (hook function &optional at append local))
580 (magit-add-section-hook 'magit-status-sections-hook
581 'magit-insert-modules
582 'magit-insert-stashes
583 'append)
584 ;; (magit-add-section-hook 'magit-status-sections-hook
585 ;; 'magit-insert-ignored-files
586 ;; 'magit-insert-untracked-files
587 ;; 'append)
588 (setq magit-repository-directories '(("~/.emacs.d/" . 0)
589 ("~/src/git/" . 2)))
590 (nconc magit-section-initial-visibility-alist
591 '(([unpulled status] . show)
592 ([unpushed status] . show)))
593 (declare-function magit-display-buffer-fullframe-status-v1 "magit-mode" (buffer))
594 :custom
595 (magit-diff-refine-hunk t)
596 (magit-display-buffer-function #'magit-display-buffer-fullframe-status-v1)
597 ;; (magit-completing-read-function 'magit-ido-completing-read)
598 :custom-face (magit-diff-file-heading ((t (:weight normal)))))
599
600;; recently opened files
601(use-package recentf
602 :defer 0.2
603 ;; :config
604 ;; (add-to-list 'recentf-exclude "^/\\(?:ssh\\|su\\|sudo\\)?:")
605 :config
606 (recentf-mode)
607 :custom
608 (recentf-max-saved-items 2000))
609
610;; needed for history for counsel
611(use-package amx
612 :defer 0.3
613 :config
614 (amx-mode))
615
616;; (require 'bandali-ido)
617(require 'bandali-ivy)
618
619(require 'bandali-eshell)
620
621(require 'bandali-ibuffer)
622
623(use-package outline
624 :disabled
625 :hook (prog-mode . outline-minor-mode)
626 :bind
627 (:map
628 outline-minor-mode-map
629 ("<s-tab>" . outline-toggle-children)
630 ("M-p" . outline-previous-visible-heading)
631 ("M-n" . outline-next-visible-heading)
632 :prefix-map b/outline-prefix-map
633 :prefix "s-O"
634 ("TAB" . outline-toggle-children)
635 ("a" . outline-hide-body)
636 ("H" . outline-hide-body)
637 ("S" . outline-show-all)
638 ("h" . outline-hide-subtree)
639 ("s" . outline-show-subtree)))
640
641(use-package ls-lisp
642 :custom (ls-lisp-dirs-first t))
643
644(require 'bandali-dired)
645
646(use-package help
647 :config
648 (temp-buffer-resize-mode)
649 (setq help-window-select t))
650
651(use-package tramp
652 :config
653 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
654 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
655 (add-to-list 'tramp-default-proxies-alist
656 (list (regexp-quote (system-name)) nil nil)))
657
658(use-package doc-view
659 :bind (:map doc-view-mode-map
660 ("M-RET" . image-previous-line)))
661
662;; Email (with Gnus, message, and EBDB)
663(require 'bandali-gnus)
664(use-package sendmail
665 :config
666 (setq sendmail-program (executable-find "msmtp")
667 ;; message-sendmail-extra-arguments '("-v" "-d")
668 mail-specify-envelope-from t
669 mail-envelope-from 'header))
670(require 'bandali-message)
671(require 'bandali-ebdb)
672
673;; IRC (with ERC and ZNC)
674(require 'bandali-erc)
675
676(use-package scpaste
677 :config
678 (setq scpaste-http-destination "https://p.bndl.org"
679 scpaste-scp-destination "p:~"))
680
681\f
682;;; Editing
683
684;; highlight uncommitted changes in the left fringe
685(use-package diff-hl
686 :defer 0.6
687 :config
688 (setq diff-hl-draw-borders nil)
689 (global-diff-hl-mode)
690 :hook
691 ((magit-pre-refresh . diff-hl-magit-pre-refresh)
692 (magit-post-refresh . diff-hl-magit-post-refresh)))
693
694;; display Lisp objects at point in the echo area
695(use-package eldoc
696 :when (version< "25" emacs-version)
697 :config (global-eldoc-mode))
698
699;; highlight matching parens
700(use-package paren
701 :demand
702 :config (show-paren-mode))
703
704(use-package elec-pair
705 :demand
706 :config (electric-pair-mode))
707
708(use-package simple
709 :config (column-number-mode)
710 :custom
711 ;; Save what I copy into clipboard from other applications into Emacs'
712 ;; kill-ring, which would allow me to still be able to easily access
713 ;; it in case I kill (cut or copy) something else inside Emacs before
714 ;; yanking (pasting) what I'd originally intended to.
715 (save-interprogram-paste-before-kill t))
716
717;; save minibuffer history
718(use-package savehist
719 :demand
720 :config
721 (savehist-mode)
722 (add-to-list 'savehist-additional-variables 'kill-ring))
723
724;; automatically save place in files
725(use-package saveplace
726 :when (version< "25" emacs-version)
727 :config (save-place-mode))
728
729(use-package prog-mode
730 :config (global-prettify-symbols-mode)
731 (defun indicate-buffer-boundaries-left ()
732 (setq indicate-buffer-boundaries 'left))
733 (add-hook 'prog-mode-hook #'indicate-buffer-boundaries-left))
734
735(use-package text-mode
736 :bind (:map text-mode-map ("C-*" . b/insert-asterism))
737 :hook ((text-mode . indicate-buffer-boundaries-left)
738 (text-mode . flyspell-mode)))
739
740(use-package conf-mode
741 :mode "\\.*rc$")
742
743(use-package sh-script
744 :mode ("\\.bashrc$" . sh-mode))
745
746(use-package company
747 :disabled
748 :bind
749 (:map company-active-map
750 ([tab] . company-complete-common-or-cycle)
751 ([escape] . company-abort)
752 ("C-p" . company-select-previous-or-abort)
753 ("C-n" . company-select-next-or-abort))
754 :custom
755 (company-minimum-prefix-length 1)
756 (company-selection-wrap-around t)
757 (company-dabbrev-char-regexp "\\sw\\|\\s_\\|[-_]")
758 (company-dabbrev-downcase nil)
759 (company-dabbrev-ignore-case nil)
760 ;; :config
761 ;; (global-company-mode t)
762 )
763
764(use-package flycheck
765 :disabled
766 :defer 0.6
767 :hook (prog-mode . flycheck-mode)
768 :bind
769 (:map flycheck-mode-map
770 ("M-P" . flycheck-previous-error)
771 ("M-N" . flycheck-next-error))
772 :config
773 ;; Use the load-path from running Emacs when checking elisp files
774 (setq flycheck-emacs-lisp-load-path 'inherit)
775
776 ;; Only flycheck when I actually save the buffer
777 (setq flycheck-check-syntax-automatically '(mode-enabled save))
778 :custom (flycheck-mode-line-prefix "flyc"))
779
780;; (use-package flyspell)
781
782;; http://endlessparentheses.com/ispell-and-apostrophes.html
783(use-package ispell
784 :disabled
785 :defer 0.6
786 :config
787 ;; ’ can be part of a word
788 (setq ispell-local-dictionary-alist
789 `((nil "[[:alpha:]]" "[^[:alpha:]]"
790 "['\x2019]" nil ("-B") nil utf-8))
791 ispell-program-name (executable-find "hunspell"))
792 ;; don't send ’ to the subprocess
793 (defun endless/replace-apostrophe (args)
794 (cons (replace-regexp-in-string
795 "’" "'" (car args))
796 (cdr args)))
797 (advice-add #'ispell-send-string :filter-args
798 #'endless/replace-apostrophe)
799
800 ;; convert ' back to ’ from the subprocess
801 (defun endless/replace-quote (args)
802 (if (not (derived-mode-p 'org-mode))
803 args
804 (cons (replace-regexp-in-string
805 "'" "’" (car args))
806 (cdr args))))
807 (advice-add #'ispell-parse-output :filter-args
808 #'endless/replace-quote))
809
810(use-package abbrev
811 :hook (text-mode . abbrev-mode))
812
813\f
814;;; Programming modes
815
816(use-package lisp-mode
817 :config
818 (defun indent-spaces-mode ()
819 (setq indent-tabs-mode nil))
820 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
821
822(use-package reveal
823 :hook (emacs-lisp-mode . reveal-mode))
824
825;; (use-package elisp-mode)
826
827(use-package alloy-mode
828 :mode "\\.\\(als\\|dsh\\)\\'"
829 :config
830 (setq alloy-basic-offset 2)
831 ;; (defun b/alloy-simple-indent (start end)
832 ;; (interactive "r")
833 ;; ;; (if (region-active-p)
834 ;; ;; (indent-rigidly start end alloy-basic-offset)
835 ;; ;; (if (bolp)
836 ;; ;; (indent-rigidly (line-beginning-position)
837 ;; ;; (line-end-position)
838 ;; ;; alloy-basic-offset)))
839 ;; (indent-to (+ (current-column) alloy-basic-offset)))
840 :bind (:map alloy-mode-map
841 ("RET" . electric-newline-and-maybe-indent)
842 ;; ("TAB" . b/alloy-simple-indent)
843 ("TAB" . indent-for-tab-command))
844 :hook (alloy-mode . (lambda () (setq-local indent-tabs-mode nil))))
845
846(use-package lean-mode
847 :disabled
848 :defer 0.4
849 :init (eval-when-compile (defvar lean-mode-map))
850 :bind (:map lean-mode-map
851 ("S-SPC" . company-complete))
852 :config
853 (require 'lean-input)
854 (setq default-input-method "Lean"
855 lean-input-tweak-all '(lean-input-compose
856 (lean-input-prepend "/")
857 (lean-input-nonempty))
858 lean-input-user-translations '(("/" "/")))
859 (lean-input-setup))
860
861;; (use-package mhtml-mode)
862
863(use-package sgml-mode
864 :config
865 (setq sgml-basic-offset 0))
866
867(use-package css-mode
868 :config
869 (setq css-indent-offset 2))
870
871(use-package emmet-mode
872 :after (:any mhtml-mode css-mode sgml-mode)
873 :bind* (("C-)" . emmet-next-edit-point)
874 ("C-(" . emmet-prev-edit-point))
875 :config
876 (unbind-key "C-j" emmet-mode-keymap)
877 (setq emmet-move-cursor-between-quotes t)
878 :hook (css-mode html-mode sgml-mode))
879
880(use-package geiser
881 :disabled)
882
883(use-package geiser-guile
884 :disabled
885 :config
886 (setq geiser-guile-load-path "~/src/git/guix"))
887
888(use-package guix
889 :disabled)
890
891(use-package auctex
892 :disabled
893 :custom
894 (font-latex-fontify-sectioning 'color))
895
896(use-package go-mode
897 :disabled)
898
899(use-package po-mode
900 :disabled
901 :hook
902 (po-mode . (lambda () (run-with-timer 0.1 nil 'View-exit))))
903
904(use-package tex-mode
905 :config
906 (cl-delete-if
907 (lambda (p) (string-match "^---?" (car p)))
908 tex--prettify-symbols-alist)
909 :hook ((tex-mode . auto-fill-mode)
910 (tex-mode . flyspell-mode)))
911
912;; (use-package george-mode
913;; :straight (:host nil :repo "https://git.shemshak.org/amin/george-mode")
914;; :mode "\\.grg\\'")
915
916\f
917;;; Theme
918
919(comment
920(add-to-list 'custom-theme-load-path
921 (expand-file-name
922 (convert-standard-filename "lisp") user-emacs-directory))
923(load-theme 'tangomod t)
924
925(use-package smart-mode-line
926 :commands (sml/apply-theme)
927 :demand
928 :config
929 ;; thanks, but no thnaks; don't make fixed-width fills.
930 (defun sml/fill-for-buffer-identification () "")
931 (setq sml/theme 'tangomod)
932 (sml/setup)
933 (smart-mode-line-enable))
934
935(use-package doom-modeline
936 :disabled
937 :demand
938 :hook (after-init . doom-modeline-init)
939 :custom
940 (doom-modeline-buffer-file-name-style 'relative-to-project))
941
942(use-package doom-themes)
943
944(use-package moody
945 :disabled
946 :demand
947 :config
948 (setq x-underline-at-descent-line t)
949 (let ((line (face-attribute 'mode-line :underline)))
950 (set-face-attribute 'mode-line nil :overline line)
951 (set-face-attribute 'mode-line-inactive nil :overline line)
952 (set-face-attribute 'mode-line-inactive nil :underline line)
953 (set-face-attribute 'mode-line nil :box nil)
954 (set-face-attribute 'mode-line-inactive nil :box nil)
955 (set-face-attribute 'mode-line-inactive nil :background "#e1e1e1")) ; d3d7cf
956 (moody-replace-mode-line-buffer-identification)
957 (moody-replace-vc-mode))
958
959(use-package mini-modeline
960 :disabled
961 :demand
962 :config (mini-modeline-mode))
963
964(defvar b/org-mode-font-lock-keywords
965 '(("[ \t]*\\(#\\+\\(BEGIN\\|END\\|begin\\|end\\)_\\(\\S-+\\)\\)[ \t]*\\([^\n:]*\\)"
966 (1 '(:foreground "#5a5b5a" :background "#292b2b") t) ; directive
967 (3 '(:foreground "#81a2be" :background "#292b2b") t) ; kind
968 (4 '(:foreground "#c5c8c6") t))) ; title
969 "For use with the `doom-tomorrow-night' theme.")
970
971(defun b/lights-on ()
972 "Enable my favourite light theme."
973 (interactive)
974 (mapc #'disable-theme custom-enabled-themes)
975 (load-theme 'tangomod t)
976 (when (featurep 'smart-mode-line)
977 (sml/apply-theme 'tangomod))
978 (font-lock-remove-keywords
979 'org-mode b/org-mode-font-lock-keywords)
980 (when (featurep 'erc-hl-nicks)
981 (erc-hl-nicks-reset-face-table))
982 (when (featurep 'exwm-systemtray)
983 (exwm-systemtray--refresh)))
984
985(defun b/lights-off ()
986 "Go dark."
987 (interactive)
988 (mapc #'disable-theme custom-enabled-themes)
989 (load-theme 'doom-one t)
990 (when (featurep 'smart-mode-line)
991 (sml/apply-theme 'automatic))
992 (font-lock-add-keywords
993 'org-mode b/org-mode-font-lock-keywords t)
994 (when (featurep 'erc-hl-nicks)
995 (erc-hl-nicks-reset-face-table))
996 (when (featurep 'exwm-systemtray)
997 (exwm-systemtray--refresh)))
998
999(bind-keys
1000 ("C-c t d" . b/lights-off)
1001 ("C-c t l" . b/lights-on))
1002
1003\f
1004;;; Emacs enhancements & auxiliary packages
1005
1006(use-package man
1007 :config (setq Man-width 80))
1008
1009(use-package which-key
1010 :defer 0.4
1011 :config
1012 (which-key-add-key-based-replacements
1013 ;; prefixes for global prefixes and minor modes
1014 "C-c @" "outline"
1015 "C-c !" "flycheck"
1016 "C-x RET" "coding system"
1017 "C-x 8" "unicode"
1018 "C-x @" "event modifiers"
1019 "C-x a" "abbrev/expand"
1020 "C-x r" "rectangle/register/bookmark"
1021 "C-x t" "tabs"
1022 "C-x v" "version control"
1023 "C-x X" "edebug"
1024 "C-x C-a" "edebug"
1025 "C-x C-k" "kmacro"
1026 ;; prefixes for my personal bindings
1027 "C-c &" "yasnippet"
1028 "C-c a" "applications"
1029 "C-c a e" "erc"
1030 "C-c a o" "org"
1031 "C-c a s" "shells"
1032 "C-c b" "buffers"
1033 "C-c c" "compile-and-comments"
1034 "C-c e" "eval"
1035 "C-c f" "files"
1036 "C-c F" "frames"
1037 "C-c g" "magit"
1038 "C-S-h" "help(ful)"
1039 "C-c m" "multiple-cursors"
1040 "C-c p" "projectile"
1041 "C-c p s" "projectile/search"
1042 "C-c p x" "projectile/execute"
1043 "C-c p 4" "projectile/other-window"
1044 "C-c q" "boxquote"
1045 "C-c t" "themes"
1046 ;; "s-O" "outline"
1047 )
1048
1049 ;; prefixes for major modes
1050 (which-key-add-major-mode-key-based-replacements 'message-mode
1051 "C-c f n" "footnote")
1052 (which-key-add-major-mode-key-based-replacements 'org-mode
1053 "C-c C-v" "org-babel")
1054
1055 (which-key-mode)
1056 :custom
1057 (which-key-add-column-padding 5)
1058 (which-key-max-description-length 32))
1059
1060(use-package crux ; results in Waiting for git... [2 times]
1061 :defer 0.4
1062 :bind (("C-c d" . crux-duplicate-current-line-or-region)
1063 ("C-c M-d" . crux-duplicate-and-comment-current-line-or-region)
1064 ("C-c f C" . crux-copy-file-preserve-attributes)
1065 ("C-c f D" . crux-delete-file-and-buffer)
1066 ("C-c f R" . crux-rename-file-and-buffer)
1067 ("C-c j" . crux-top-join-line)
1068 ("C-S-j" . crux-top-join-line)))
1069
1070(use-package mwim
1071 :bind (("C-a" . mwim-beginning-of-code-or-line)
1072 ("C-e" . mwim-end-of-code-or-line)
1073 ("<home>" . mwim-beginning-of-line-or-code)
1074 ("<end>" . mwim-end-of-line-or-code)))
1075
1076(use-package projectile
1077 :disabled
1078 :defer 0.5
1079 :bind-keymap ("C-c p" . projectile-command-map)
1080 :config
1081 (projectile-mode)
1082
1083 (defun b/projectile-mode-line-fun ()
1084 "Report project name and type in the modeline."
1085 (let ((project-name (projectile-project-name))
1086 (project-type (projectile-project-type)))
1087 (format "%s%s"
1088 projectile-mode-line-prefix
1089 (if project-type
1090 (format ":%s" project-type)
1091 ""))))
1092 (setq projectile-mode-line-function 'b/projectile-mode-line-fun)
1093
1094 (defun my-projectile-invalidate-cache (&rest _args)
1095 ;; ignore the args to `magit-checkout'
1096 (projectile-invalidate-cache nil))
1097
1098 (eval-after-load 'magit-branch
1099 '(progn
1100 (advice-add 'magit-checkout
1101 :after #'my-projectile-invalidate-cache)
1102 (advice-add 'magit-branch-and-checkout
1103 :after #'my-projectile-invalidate-cache)))
1104 :custom
1105 (projectile-completion-system 'ivy)
1106 (projectile-mode-line-prefix " proj"))
1107
1108(use-package helpful
1109 :defer 0.6
1110 :bind
1111 (("C-S-h c" . helpful-command)
1112 ("C-S-h f" . helpful-callable) ; helpful-function
1113 ("C-S-h v" . helpful-variable)
1114 ("C-S-h k" . helpful-key)
1115 ("C-S-h p" . helpful-at-point)))
1116
1117(use-package unkillable-scratch
1118 :defer 0.6
1119 :config
1120 (unkillable-scratch 1)
1121 :custom
1122 (unkillable-buffers '("^\\*scratch\\*$" "^\\*Messages\\*$")))
1123
1124;; ,----
1125;; | make pretty boxed quotes like this
1126;; `----
1127(use-package boxquote
1128 :defer 0.6
1129 :bind
1130 (:prefix-map b/boxquote-prefix-map
1131 :prefix "C-c q"
1132 ("b" . boxquote-buffer)
1133 ("B" . boxquote-insert-buffer)
1134 ("d" . boxquote-defun)
1135 ("F" . boxquote-insert-file)
1136 ("hf" . boxquote-describe-function)
1137 ("hk" . boxquote-describe-key)
1138 ("hv" . boxquote-describe-variable)
1139 ("hw" . boxquote-where-is)
1140 ("k" . boxquote-kill)
1141 ("p" . boxquote-paragraph)
1142 ("q" . boxquote-boxquote)
1143 ("r" . boxquote-region)
1144 ("s" . boxquote-shell-command)
1145 ("t" . boxquote-text)
1146 ("T" . boxquote-title)
1147 ("u" . boxquote-unbox)
1148 ("U" . boxquote-unbox-region)
1149 ("y" . boxquote-yank)
1150 ("M-q" . boxquote-fill-paragraph)
1151 ("M-w" . boxquote-kill-ring-save)))
1152
1153(use-package orgalist
1154 ;; breaks auto-fill-mode, showing this error:
1155 ;; orgalist--boundaries: Lisp nesting exceeds ‘max-lisp-eval-depth’
1156 :disabled
1157 :after message
1158 :hook (message-mode . orgalist-mode))
1159
1160;; highlight TODOs in buffers
1161(use-package hl-todo
1162 :defer 0.5
1163 :config
1164 (global-hl-todo-mode))
1165
1166(use-package multi-term
1167 :disabled
1168 :defer 0.6
1169 :bind (("C-c a s m m" . multi-term)
1170 ("C-c a s m d" . multi-term-dedicated-toggle)
1171 ("C-c a s m p" . multi-term-prev)
1172 ("C-c a s m n" . multi-term-next)
1173 :map term-mode-map
1174 ("C-c C-j" . term-char-mode))
1175 :config
1176 (setq multi-term-program "screen"
1177 multi-term-program-switches (concat "-c"
1178 (getenv "XDG_CONFIG_HOME")
1179 "/screen/screenrc")
1180 ;; TODO: add separate bindings for connecting to existing
1181 ;; session vs. always creating a new one
1182 multi-term-dedicated-select-after-open-p t
1183 multi-term-dedicated-window-height 20
1184 multi-term-dedicated-max-window-height 30
1185 term-bind-key-alist
1186 '(("C-c C-c" . term-interrupt-subjob)
1187 ("C-c C-e" . term-send-esc)
1188 ("C-c C-j" . term-line-mode)
1189 ("C-k" . kill-line)
1190 ;; ("C-y" . term-paste)
1191 ("C-y" . term-send-raw)
1192 ("M-f" . term-send-forward-word)
1193 ("M-b" . term-send-backward-word)
1194 ("M-p" . term-send-up)
1195 ("M-n" . term-send-down)
1196 ("M-j" . term-send-raw-meta)
1197 ("M-y" . term-send-raw-meta)
1198 ("M-/" . term-send-raw-meta)
1199 ("M-0" . term-send-raw-meta)
1200 ("M-1" . term-send-raw-meta)
1201 ("M-2" . term-send-raw-meta)
1202 ("M-3" . term-send-raw-meta)
1203 ("M-4" . term-send-raw-meta)
1204 ("M-5" . term-send-raw-meta)
1205 ("M-6" . term-send-raw-meta)
1206 ("M-7" . term-send-raw-meta)
1207 ("M-8" . term-send-raw-meta)
1208 ("M-9" . term-send-raw-meta)
1209 ("<C-backspace>" . term-send-backward-kill-word)
1210 ("<M-DEL>" . term-send-backward-kill-word)
1211 ("M-d" . term-send-delete-word)
1212 ("M-," . term-send-raw)
1213 ("M-." . comint-dynamic-complete))
1214 term-unbind-key-alist
1215 '("C-z" "C-x" "C-c" "C-h"
1216 ;; "C-y"
1217 "<ESC>")))
1218
1219(use-package page-break-lines
1220 :defer 0.5
1221 :custom
1222 (page-break-lines-max-width fill-column)
1223 :config
1224 (global-page-break-lines-mode))
1225
1226(use-package expand-region
1227 :bind ("C-=" . er/expand-region))
1228
1229(use-package multiple-cursors
1230 :bind
1231 (("C-S-<mouse-1>" . mc/add-cursor-on-click)
1232 (:prefix-map b/mc-prefix-map
1233 :prefix "C-c m"
1234 ("c" . mc/edit-lines)
1235 ("n" . mc/mark-next-like-this)
1236 ("p" . mc/mark-previous-like-this)
1237 ("a" . mc/mark-all-like-this))))
1238
1239(use-package yasnippet
1240 :defer 0.6
1241 :config
1242 (defconst yas-verbosity-cur yas-verbosity)
1243 (setq yas-verbosity 2)
1244 (add-to-list 'yas-snippet-dirs "~/src/git/guix/etc/snippets" t)
1245 (yas-reload-all)
1246 (setq yas-verbosity yas-verbosity-cur)
1247
1248 (defun b/yas--maybe-expand-key-filter (cmd)
1249 (when (and (yas--maybe-expand-key-filter cmd)
1250 (not (bound-and-true-p git-commit-mode)))
1251 cmd))
1252 (defconst b/yas-maybe-expand
1253 '(menu-item "" yas-expand :filter b/yas--maybe-expand-key-filter))
1254 (define-key yas-minor-mode-map
1255 (kbd "SPC") b/yas-maybe-expand)
1256
1257 (yas-global-mode))
1258
1259(use-package debbugs
1260 :bind
1261 (("C-c D d" . debbugs-gnu)
1262 ("C-c D b" . debbugs-gnu-bugs)
1263 ("C-c D e" .
1264 (lambda ()
1265 (interactive) ; bug-gnu-emacs
1266 (setq debbugs-gnu-current-suppress t)
1267 (debbugs-gnu debbugs-gnu-default-severities '("emacs"))))
1268 ("C-c D g" . ; bug-gnuzilla
1269 (lambda ()
1270 (interactive)
1271 (setq debbugs-gnu-current-suppress t)
1272 (debbugs-gnu debbugs-gnu-default-severities '("gnuzilla"))))
1273 ("C-c D G b" . ; bug-guix
1274 (lambda ()
1275 (interactive)
1276 (setq debbugs-gnu-current-suppress t)
1277 (debbugs-gnu debbugs-gnu-default-severities '("guix"))))
1278 ("C-c D G p" . ; guix-patches
1279 (lambda ()
1280 (interactive)
1281 (setq debbugs-gnu-current-suppress t)
1282 (debbugs-gnu debbugs-gnu-default-severities '("guix-patches"))))))
1283
1284(use-package org-ref
1285 :init
1286 (b/setq-every '("~/usr/org/references.bib")
1287 reftex-default-bibliography
1288 org-ref-default-bibliography)
1289 (setq
1290 org-ref-bibliography-notes "~/usr/org/notes.org"
1291 org-ref-pdf-directory "~/usr/org/bibtex-pdfs/"))
1292
1293;; (use-package fill-column-indicator)
1294
1295(use-package window
1296 :bind
1297 (("C-c w s l" . (lambda ()
1298 (interactive)
1299 (split-window-right)
1300 (other-window 1)))
1301 ("C-c w s j" . (lambda ()
1302 (interactive)
1303 (split-window-below)
1304 (other-window 1)))
1305 ("C-c w q" . quit-window))
1306 :custom
1307 (split-width-threshold 150))
1308
1309(use-package windmove
1310 :defer 0.6
1311 :bind
1312 (("C-c w h" . windmove-left)
1313 ("C-c w j" . windmove-down)
1314 ("C-c w k" . windmove-up)
1315 ("C-c w l" . windmove-right)
1316 ("C-c w H" . windmove-swap-states-left)
1317 ("C-c w J" . windmove-swap-states-down)
1318 ("C-c w K" . windmove-swap-states-up)
1319 ("C-c w L" . windmove-swap-states-right)))
1320
1321(use-package pass
1322 :commands pass
1323 :bind ("C-c a p" . pass)
1324 :hook (pass-mode . View-exit))
1325
1326(use-package pdf-tools
1327 :defer 0.5
1328 :bind (:map pdf-view-mode-map
1329 ("<C-XF86Back>" . pdf-history-backward)
1330 ("<mouse-8>" . pdf-history-backward)
1331 ("<drag-mouse-8>" . pdf-history-backward)
1332 ("<C-XF86Forward>" . pdf-history-forward)
1333 ("<mouse-9>" . pdf-history-forward)
1334 ("<drag-mouse-9>" . pdf-history-forward)
1335 ("M-RET" . image-previous-line)
1336 ("C-s" . isearch-forward)
1337 ("s s" . isearch-forward))
1338 :config (pdf-tools-install nil t)
1339 :custom (pdf-view-resize-factor 1.05))
1340
1341(use-package org-pdftools
1342 :disabled
1343 :straight (:host github :repo "fuxialexander/org-pdftools")
1344 :demand
1345 :after org
1346 :config
1347 (with-eval-after-load 'org
1348 (require 'org-pdftools)))
1349
1350(use-package biblio)
1351
1352(use-package reftex
1353 :hook (latex-mode . reftex-mode))
1354
1355(use-package reftex-cite
1356 :after reftex
1357 :disabled ; enable to disable
1358 ; reftex-cite's default choice
1359 ; of previous word
1360 :config
1361 (defun reftex-get-bibkey-default ()
1362 "If the cursor is in a citation macro, return the word before the macro."
1363 (let* ((macro (reftex-what-macro 1)))
1364 (save-excursion
1365 (when (and macro (string-match "cite" (car macro)))
1366 (goto-char (cdr macro)))
1367 (reftex-this-word)))))
1368
1369(use-package minions
1370 :demand
1371 :config (minions-mode))
1372
1373(use-package dmenu
1374 :custom
1375 (dmenu-prompt-string "run: ")
1376 (dmenu-save-file (b/var "dmenu-items")))
1377
1378(use-package eosd
1379 ;; TODO: fix build by properly building the eosd-pixbuf.c module
1380 ;; e.g. see https://github.com/raxod502/straight.el/issues/386
1381 :disabled
1382 :straight (:host github :repo "clarete/eosd")
1383 :demand
1384 :after exwm
1385 :config
1386 (eosd-start))
1387
1388(use-package eww
1389 :bind ("C-c a e w" . eww)
1390 :custom
1391 (eww-download-directory (file-name-as-directory
1392 (getenv "XDG_DOWNLOAD_DIR"))))
1393
1394\f
1395;;; Post initialization
1396
1397)
1398(message "Loading %s...done (%.3fs)" user-init-file
1399 (float-time (time-subtract (current-time)
1400 b/before-user-init-time)))
1401
1402;;; init.el ends here