* init.el: Disable diff-hl for now, don't set case-fold-search
[~bandali/configs] / init.el
CommitLineData
33b1a7ea 1;;; init.el --- bandali's emacs configuration -*- lexical-binding: t -*-
41d290a2 2
4c05c418 3;; Copyright (C) 2018-2020 Amin Bandali <bandali@gnu.org>
41d290a2
AB
4
5;; This program is free software: you can redistribute it and/or modify
6;; it under the terms of the GNU General Public License as published by
7;; the Free Software Foundation, either version 3 of the License, or
8;; (at your option) any later version.
9
10;; This program is distributed in the hope that it will be useful,
11;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13;; GNU General Public License for more details.
14
15;; You should have received a copy of the GNU General Public License
16;; along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18;;; Commentary:
19
33b1a7ea 20;; GNU Emacs configuration of Amin Bandali, computer scientist,
92ad9675 21;; Free Software activist, and GNU maintainer & webmaster. Packages
f7910e3d 22;; are installed through using Borg for a fully reproducible setup.
b57457b2
AB
23
24;; Over the years, I've taken inspiration from configurations of many
25;; great people. Some that I can remember off the top of my head are:
26;;
27;; - https://github.com/dieggsy/dotfiles
28;; - https://github.com/dakra/dmacs
29;; - http://pages.sachachua.com/.emacs.d/Sacha.html
30;; - https://github.com/dakrone/eos
31;; - http://doc.rix.si/cce/cce.html
32;; - https://github.com/jwiegley/dot-emacs
33;; - https://github.com/wasamasa/dotemacs
34;; - https://github.com/hlissner/doom-emacs
41d290a2 35
49e9503b
AB
36;;; Code:
37
b57457b2
AB
38;;; Emacs initialization
39
dca50cf5 40(defvar b/before-user-init-time (current-time)
41d290a2 41 "Value of `current-time' when Emacs begins loading `user-init-file'.")
83364e5b
AB
42(defvar b/emacs-initialized nil
43 "Whether Emacs has been initialized.")
8b1a2f32
AB
44(defvar b/exwm-p (string= (system-name) "chaman")
45 "Whether or not we will be using `exwm'.")
83364e5b
AB
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))))
41d290a2 51
b57457b2
AB
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.
dca50cf5
AB
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)
bc58e70a 58(setq gc-cons-threshold (* 30 1024 1024) ; 30 MiB
41d290a2
AB
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
b57457b2 64;; set them back to their defaults once we're done initializing
dca50cf5 65(defun b/post-init ()
83364e5b
AB
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
e8a3b8f7 70 file-name-handler-alist b/file-name-handler-alist)
8b1a2f32
AB
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)))))))))
dca50cf5 81(add-hook 'after-init-hook #'b/post-init)
41d290a2 82
b57457b2 83;; increase number of lines kept in *Messages* log
41d290a2
AB
84(setq message-log-max 20000)
85
b57457b2
AB
86;; optionally, uncomment to supress some byte-compiler warnings
87;; (see C-h v byte-compile-warnings RET for more info)
41d290a2
AB
88;; (setq byte-compile-warnings
89;; '(not free-vars unresolved noruntime lexical make-local))
90
b57457b2
AB
91\f
92;;; whoami
93
41d290a2 94(setq user-full-name "Amin Bandali"
33b1a7ea 95 user-mail-address "bandali@gnu.org")
41d290a2 96
b57457b2 97\f
33273849
AB
98;;; Package management
99
032726b6
AB
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/"))))
33273849
AB
108
109;; use-package
41d290a2
AB
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
b57457b2
AB
123\f
124;;; Initial setup
125
126;; keep ~/.emacs.d clean
1060413b
AB
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))
41d290a2 132
032726b6
AB
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
b57457b2 144;; separate custom file (don't want it mixing with init.el)
47904cb7 145(use-package custom
60ff805e 146 :no-require
41d290a2 147 :config
dca50cf5 148 (setq custom-file (b/etc "custom.el"))
41d290a2
AB
149 (when (file-exists-p custom-file)
150 (load custom-file))
b57457b2 151 ;; while at it, treat themes as safe
60ff805e
AB
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))))
41d290a2 158
b57457b2 159;; load the secrets file if it exists, otherwise show a warning
dca50cf5
AB
160(comment
161 (with-demoted-errors
162 (load (b/etc "secrets"))))
41d290a2 163
b57457b2
AB
164;; start up emacs server. see
165;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server
47904cb7 166(use-package server
f7910e3d 167 :defer 0.5
2087ae39
AB
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)))
41d290a2 173
60ff805e 174\f
60ff805e
AB
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
bdd3a0bb 196 scroll-conservatively 101
60ff805e
AB
197 scroll-preserve-screen-position 1
198 ;; focus follows mouse
39cc9c96 199 mouse-autoselect-window t)
60ff805e
AB
200
201(setq-default
202 ;; always use space for indentation
203 indent-tabs-mode nil
204 tab-width 4
7682baf8
AB
205 ;; case-sensitive search (and `dabbrev-expand')
206 ;; case-fold-search nil
60ff805e 207 ;; cursor shape
567440fa 208 cursor-type t)
60ff805e 209
b57457b2
AB
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
60ff805e 243;;;; Elisp-level customizations
41d290a2 244
47904cb7 245(use-package startup
60ff805e
AB
246 :no-require
247 :demand
41d290a2 248 :config
60ff805e
AB
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*
2568a634 257 ;; (initial-major-mode 'text-mode)
60ff805e
AB
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))
41d290a2 263
47904cb7 264(use-package files
60ff805e
AB
265 :no-require
266 :demand
9fc30d4c 267 :custom
60ff805e
AB
268 ;; backups (C-h v make-backup-files RET)
269 (backup-by-copying t)
270 (version-control t)
271 (delete-old-versions t)
41d290a2 272
60ff805e
AB
273 ;; auto-save
274 (auto-save-file-name-transforms
275 `((".*" ,(b/var "auto-save/") t)))
41d290a2 276
60ff805e
AB
277 ;; insert newline at the end of files
278 (require-final-newline t)
b57457b2 279
60ff805e
AB
280 ;; open read-only file buffers in view-mode
281 ;; (enables niceties like `q' for quit)
282 (view-read-only t))
41d290a2 283
60ff805e
AB
284;; disable disabled commands
285(setq disabled-command-function nil)
41d290a2 286
60ff805e
AB
287;; lazy-person-friendly yes/no prompts
288(defalias 'yes-or-no-p #'y-or-n-p)
b57457b2 289
60ff805e 290;; enable automatic reloading of changed buffers and files
47904cb7 291(use-package autorevert
60ff805e
AB
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))
b57457b2
AB
298
299;; time and battery in mode-line
47904cb7 300(use-package time
e4902e0b 301 :demand
64938292
AB
302 :config
303 (display-time-mode)
304 :custom
305 (display-time-default-load-average nil)
f7910e3d 306 (display-time-format " %a %b %-e %-l:%M%P")
ad61316b
AB
307 (display-time-mail-icon '(image :type xpm :file "gnus/gnus-pointer.xpm" :ascent center))
308 (display-time-use-mail-icon t))
64938292 309
47904cb7 310(use-package battery
e4902e0b 311 :demand
64938292
AB
312 :config
313 (display-battery-mode)
314 :custom
f7910e3d 315 (battery-mode-line-format "%p%% %t"))
b57457b2 316
47904cb7 317(use-package fringe
60ff805e
AB
318 :demand
319 :config
320 ;; smaller fringe
321 ;; (fringe-mode '(3 . 1))
322 (fringe-mode nil))
41d290a2 323
47904cb7 324(use-package winner
60ff805e
AB
325 :demand
326 :config
327 ;; enable winner-mode (C-h f winner-mode RET)
328 (winner-mode 1))
41d290a2 329
47904cb7 330(use-package compile
60ff805e
AB
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'.
dca50cf5 335 (defun b/compilation-finish-function (buffer outstr)
41d290a2
AB
336 (unless (string-match "finished" outstr)
337 (switch-to-buffer-other-window buffer))
338 t)
339
dca50cf5 340 (setq compilation-finish-functions #'b/compilation-finish-function)
41d290a2
AB
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
47904cb7 353(use-package isearch
60ff805e
AB
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
47904cb7 365 (use-package replace
60ff805e
AB
366 :custom
367 (replace-char-fold t)))
b9901074 368
47904cb7 369(use-package vc
b1a5d811
AB
370 :bind ("C-x v C-=" . vc-ediff))
371
47904cb7 372(use-package vc-git
e59c8878
AB
373 :after vc
374 :custom
375 (vc-git-print-log-follow t))
376
47904cb7 377(use-package ediff
b1a5d811
AB
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
47904cb7 382(use-package face-remap
60ff805e
AB
383 :custom
384 ;; gentler font resizing
385 (text-scale-mode-step 1.05))
386
47904cb7 387(use-package mwheel
60ff805e
AB
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
47904cb7 394(use-package pixel-scroll
60ff805e
AB
395 :defer 0.4
396 :config (pixel-scroll-mode 1))
397
47904cb7 398(use-package epg-config
a89c8bd8
AB
399 :config
400 ;; ask for GPG passphrase in minibuffer
401 ;; this will fail if gpg>=2.1 is not available
97141042 402 (setq epg-pinentry-mode 'loopback)
60ff805e 403 :custom
47904cb7 404 (epg-gpg-program (executable-find "gpg")))
1d405cde 405
47904cb7
AB
406(use-package epg
407 :after epg-config)
408
a89c8bd8 409(use-package pinentry
8b1a2f32 410 :disabled
a89c8bd8
AB
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
47904cb7 418(use-package auth-source
b98dbb3d
AB
419 :custom
420 (auth-sources '("~/.authinfo.gpg"))
421 (authinfo-hidden (regexp-opt '("password" "client-secret" "token"))))
422
b57457b2
AB
423\f
424;;; General bindings
425
41d290a2 426(bind-keys
c64e010d 427 ("C-a" . b/move-indentation-or-beginning-of-line)
41d290a2 428 ("C-c a i" . ielm)
ad1f9d99 429 ("C-c d" . b/duplicate-line-or-region)
41d290a2
AB
430
431 ("C-c e b" . eval-buffer)
2a816b71 432 ("C-c e e" . eval-last-sexp)
12ff40a3 433 ("C-c e p" . pp-macroexpand-last-sexp)
41d290a2
AB
434 ("C-c e r" . eval-region)
435
436 ("C-c e i" . emacs-init-time)
437 ("C-c e u" . emacs-uptime)
dca50cf5 438 ("C-c e v" . emacs-version)
41d290a2 439
567440fa
AB
440 ("C-c f ." . find-file)
441 ("C-c f d" . find-name-dired)
442 ("C-c f l" . find-library)
443
41d290a2
AB
444 ("C-c F m" . make-frame-command)
445 ("C-c F d" . delete-frame)
41d290a2 446
41d290a2
AB
447 ("C-S-h C" . describe-char)
448 ("C-S-h F" . describe-face)
449
e5c2d147
AB
450 ("C-S-j" . b/join-line-top)
451
567440fa
AB
452 ("C-c x" . execute-extended-command)
453
a5cc22f4 454 ("C-x k" . b/kill-current-buffer)
41d290a2 455 ("C-x K" . kill-buffer)
2a816b71
AB
456 ("C-x s" . save-buffer)
457 ("C-x S" . save-some-buffers)
41d290a2 458
b57457b2 459 :map emacs-lisp-mode-map
dca50cf5 460 ("<C-return>" . b/add-elisp-section))
41d290a2
AB
461
462(when (display-graphic-p)
463 (unbind-key "C-z" global-map))
464
500004f4
AB
465(bind-keys
466 ;; for back and forward mouse keys
0365678c 467 ("<XF86Back>" . previous-buffer)
500004f4 468 ("<mouse-8>" . previous-buffer)
4bdfe6ab 469 ;; ("<drag-mouse-8>" . previous-buffer)
0365678c 470 ("<XF86Forward>" . next-buffer)
500004f4 471 ("<mouse-9>" . next-buffer)
4bdfe6ab
AB
472 ;; ("<drag-mouse-9>" . next-buffer)
473 ;; ("<drag-mouse-2>" . kill-this-buffer)
474 ;; ("<drag-mouse-3>" . switch-to-buffer)
475 )
500004f4 476
b57457b2
AB
477\f
478;;; Essential packages
479
8b1a2f32
AB
480(when b/exwm-p
481 (require 'bandali-exwm))
33273849 482
f7910e3d 483(require 'bandali-org)
41d290a2 484
9c48decc
AB
485(require 'bandali-theme)
486
b57457b2 487;; *the* right way to do git
41d290a2 488(use-package magit
2a816b71
AB
489 :bind (("C-x g" . magit-status)
490 ("C-c g g" . magit-status)
ef6c487c
AB
491 ("C-c g b" . magit-blame-addition)
492 ("C-c g l" . magit-log-buffer-file))
41d290a2 493 :config
2087ae39
AB
494 (declare-function magit-add-section-hook "magit-section"
495 (hook function &optional at append local))
41d290a2
AB
496 (magit-add-section-hook 'magit-status-sections-hook
497 'magit-insert-modules
498 'magit-insert-stashes
499 'append)
3b3615f5
AB
500 ;; (magit-add-section-hook 'magit-status-sections-hook
501 ;; 'magit-insert-ignored-files
502 ;; 'magit-insert-untracked-files
503 ;; 'append)
8a2e0eef 504 (setq magit-repository-directories '(("~/.emacs.d/" . 0)
81ea6e55 505 ("~/src/git/" . 2)))
41d290a2
AB
506 (nconc magit-section-initial-visibility-alist
507 '(([unpulled status] . show)
508 ([unpushed status] . show)))
2087ae39 509 (declare-function magit-display-buffer-fullframe-status-v1 "magit-mode" (buffer))
3fffeb0a
AB
510 :custom
511 (magit-diff-refine-hunk t)
512 (magit-display-buffer-function #'magit-display-buffer-fullframe-status-v1)
6ca3a7b1 513 ;; (magit-completing-read-function 'magit-ido-completing-read)
41d290a2
AB
514 :custom-face (magit-diff-file-heading ((t (:weight normal)))))
515
b57457b2 516;; recently opened files
47904cb7 517(use-package recentf
41d290a2 518 :defer 0.2
6b09fc8a
AB
519 :config
520 (add-to-list 'recentf-keep 'file-remote-p)
6eb104ff
AB
521 :config
522 (recentf-mode)
dca50cf5 523 :custom
1060413b 524 (recentf-max-saved-items 2000))
41d290a2 525
679463c6 526;; needed for history for counsel
6eb104ff
AB
527(use-package amx
528 :defer 0.3
529 :config
530 (amx-mode))
531
679463c6
AB
532;; (require 'bandali-ido)
533(require 'bandali-ivy)
41d290a2 534
679463c6 535(require 'bandali-eshell)
1eb20313 536;; (require 'bandali-multi-term)
41d290a2 537
679463c6 538(require 'bandali-ibuffer)
41d290a2 539
47904cb7 540(use-package outline
2e81c51a 541 :disabled
41d290a2
AB
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)
dca50cf5 549 :prefix-map b/outline-prefix-map
ed8c4fa9 550 :prefix "s-O"
41d290a2
AB
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)
1eb20313
AB
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")))
41d290a2 562
679463c6 563(require 'bandali-dired)
41d290a2 564
47904cb7 565(use-package help
6b09fc8a
AB
566 :bind
567 (:map help-mode-map
568 ("p" . backward-button)
569 ("n" . forward-button))
41d290a2
AB
570 :config
571 (temp-buffer-resize-mode)
572 (setq help-window-select t))
573
47904cb7 574(use-package tramp
41d290a2
AB
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
47904cb7 581(use-package doc-view
41d290a2
AB
582 :bind (:map doc-view-mode-map
583 ("M-RET" . image-previous-line)))
584
e2178fd3 585;; Email (with Gnus, message, and EBDB)
2087ae39 586(require 'bandali-gnus)
2087ae39
AB
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))
2087ae39 593(require 'bandali-message)
e2178fd3 594(require 'bandali-ebdb)
2087ae39 595
39c1c073
AB
596;; IRC (with ERC and ZNC)
597(require 'bandali-erc)
598
2331b5a0
AB
599(use-package scpaste
600 :config
601 (setq scpaste-http-destination "https://p.bndl.org"
602 scpaste-scp-destination "p:~"))
603
b57457b2
AB
604\f
605;;; Editing
5750405c 606
b57457b2 607;; highlight uncommitted changes in the left fringe
41d290a2 608(use-package diff-hl
7682baf8 609 :disabled
df1c9bc8 610 :defer 0.6
41d290a2
AB
611 :config
612 (setq diff-hl-draw-borders nil)
613 (global-diff-hl-mode)
5750405c
AB
614 :hook
615 ((magit-pre-refresh . diff-hl-magit-pre-refresh)
616 (magit-post-refresh . diff-hl-magit-post-refresh)))
41d290a2 617
b57457b2 618;; display Lisp objects at point in the echo area
47904cb7 619(use-package eldoc
41d290a2
AB
620 :when (version< "25" emacs-version)
621 :config (global-eldoc-mode))
622
b57457b2 623;; highlight matching parens
47904cb7 624(use-package paren
41d290a2
AB
625 :demand
626 :config (show-paren-mode))
627
47904cb7 628(use-package elec-pair
40eddfea
AB
629 :demand
630 :config (electric-pair-mode))
631
47904cb7 632(use-package simple
60ff805e
AB
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))
41d290a2 640
b57457b2 641;; save minibuffer history
47904cb7 642(use-package savehist
1060413b 643 :demand
dca50cf5
AB
644 :config
645 (savehist-mode)
1060413b 646 (add-to-list 'savehist-additional-variables 'kill-ring))
41d290a2 647
b57457b2 648;; automatically save place in files
47904cb7 649(use-package saveplace
41d290a2 650 :when (version< "25" emacs-version)
1060413b 651 :config (save-place-mode))
41d290a2 652
47904cb7 653(use-package prog-mode
41d290a2
AB
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
47904cb7 659(use-package text-mode
bc2f85e1 660 :bind (:map text-mode-map ("C-*" . b/insert-asterism))
93a86536
AB
661 :hook ((text-mode . indicate-buffer-boundaries-left)
662 (text-mode . flyspell-mode)))
41d290a2 663
47904cb7 664(use-package conf-mode
300b7363
AB
665 :mode "\\.*rc$")
666
5b990219
AB
667(use-package sh-script
668 :mode ("\\.bashrc$" . sh-mode))
300b7363 669
41d290a2 670(use-package company
ccade202 671 :disabled
41d290a2
AB
672 :bind
673 (:map company-active-map
674 ([tab] . company-complete-common-or-cycle)
d39234b9
AB
675 ([escape] . company-abort)
676 ("C-p" . company-select-previous-or-abort)
677 ("C-n" . company-select-next-or-abort))
41d290a2
AB
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)
6eb104ff
AB
684 ;; :config
685 ;; (global-company-mode t)
686 )
41d290a2
AB
687
688(use-package flycheck
fac1032c 689 :disabled
41d290a2
AB
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
54209e74
AB
701 (setq flycheck-check-syntax-automatically '(mode-enabled save))
702 :custom (flycheck-mode-line-prefix "flyc"))
703
fac1032c 704;; (use-package flyspell)
41d290a2
AB
705
706;; http://endlessparentheses.com/ispell-and-apostrophes.html
47904cb7 707(use-package ispell
fac1032c 708 :disabled
41d290a2
AB
709 :defer 0.6
710 :config
711 ;; ’ can be part of a word
712 (setq ispell-local-dictionary-alist
713 `((nil "[[:alpha:]]" "[^[:alpha:]]"
b1ed9ee8
AB
714 "['\x2019]" nil ("-B") nil utf-8))
715 ispell-program-name (executable-find "hunspell"))
41d290a2
AB
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
47904cb7 734(use-package abbrev
1060413b 735 :hook (text-mode . abbrev-mode))
54209e74 736
b57457b2
AB
737\f
738;;; Programming modes
739
47904cb7 740(use-package lisp-mode
41d290a2 741 :config
41d290a2
AB
742 (defun indent-spaces-mode ()
743 (setq indent-tabs-mode nil))
744 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
745
fac1032c
AB
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
33273849 765(use-package lean-mode
46b0569f 766 :disabled
33273849 767 :defer 0.4
46b0569f 768 :init (eval-when-compile (defvar lean-mode-map))
33273849
AB
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
47904cb7 780(use-package sgml-mode
41d290a2 781 :config
5dfaee4c 782 (setq sgml-basic-offset 0))
41d290a2 783
47904cb7 784(use-package css-mode
41d290a2
AB
785 :config
786 (setq css-indent-offset 2))
787
46b0569f
AB
788(use-package geiser
789 :disabled)
41d290a2 790
47904cb7 791(use-package geiser-guile
46b0569f 792 :disabled
41d290a2
AB
793 :config
794 (setq geiser-guile-load-path "~/src/git/guix"))
795
46b0569f
AB
796(use-package guix
797 :disabled)
41d290a2 798
47904cb7
AB
799(use-package go-mode
800 :disabled)
99473567 801
f704f564 802(use-package po-mode
46b0569f 803 :disabled
f704f564
AB
804 :hook
805 (po-mode . (lambda () (run-with-timer 0.1 nil 'View-exit))))
806
a2feb3de
AB
807(use-package auctex
808 :disabled
809 :custom
810 (font-latex-fontify-sectioning 'color))
811
47904cb7 812(use-package tex-mode
748bd8ac
AB
813 :config
814 (cl-delete-if
815 (lambda (p) (string-match "^---?" (car p)))
0758ec38
AB
816 tex--prettify-symbols-alist)
817 :hook ((tex-mode . auto-fill-mode)
3457307b 818 (tex-mode . flyspell-mode)))
748bd8ac 819
47904cb7
AB
820;; (use-package george-mode
821;; :straight (:host nil :repo "https://git.shemshak.org/amin/george-mode")
822;; :mode "\\.grg\\'")
1d01c927 823
b57457b2 824\f
b57457b2 825;;; Emacs enhancements & auxiliary packages
1eb20313 826
dca50cf5 827(use-package man
41d290a2
AB
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
41d290a2 835 "C-c !" "flycheck"
b549b760 836 "C-x RET" "coding system"
41d290a2 837 "C-x 8" "unicode"
b549b760 838 "C-x @" "event modifiers"
41d290a2
AB
839 "C-x a" "abbrev/expand"
840 "C-x r" "rectangle/register/bookmark"
b549b760 841 "C-x t" "tabs"
41d290a2 842 "C-x v" "version control"
b549b760
AB
843 "C-x X" "edebug"
844 "C-x C-a" "edebug"
845 "C-x C-k" "kmacro"
41d290a2 846 ;; prefixes for my personal bindings
b549b760 847 "C-c &" "yasnippet"
41d290a2
AB
848 "C-c a" "applications"
849 "C-c a e" "erc"
850 "C-c a o" "org"
851 "C-c a s" "shells"
2e81c51a 852 "C-c b" "buffers"
41d290a2
AB
853 "C-c c" "compile-and-comments"
854 "C-c e" "eval"
855 "C-c f" "files"
856 "C-c F" "frames"
ef6c487c 857 "C-c g" "magit"
41d290a2 858 "C-S-h" "help(ful)"
41d290a2 859 "C-c q" "boxquote"
1eb20313 860 "C-c t" "themes")
41d290a2
AB
861
862 ;; prefixes for major modes
41d290a2
AB
863 (which-key-add-major-mode-key-based-replacements 'org-mode
864 "C-c C-v" "org-babel")
41d290a2
AB
865
866 (which-key-mode)
867 :custom
868 (which-key-add-column-padding 5)
1eb20313
AB
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))
41d290a2 873
1eb20313 874;; (require 'bandali-projectile)
41d290a2
AB
875
876(use-package helpful
1eb20313 877 :disabled
41d290a2
AB
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
5b10d879
AB
886(use-package unkillable-scratch
887 :defer 0.6
888 :config
889 (unkillable-scratch 1)
890 :custom
891 (unkillable-buffers '("^\\*scratch\\*$" "^\\*Messages\\*$")))
41d290a2 892
5b10d879
AB
893;; ,----
894;; | make pretty boxed quotes like this
895;; `----
896(use-package boxquote
897 :defer 0.6
898 :bind
1eb20313
AB
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)))
41d290a2 922
41d290a2 923(use-package hl-todo
1eb20313 924 ;; highlight TODOs in buffers
41d290a2
AB
925 :defer 0.5
926 :config
927 (global-hl-todo-mode))
928
41d290a2 929(use-package page-break-lines
b57457b2 930 :defer 0.5
2f5d8190
AB
931 :custom
932 (page-break-lines-max-width fill-column)
41d290a2
AB
933 :config
934 (global-page-break-lines-mode))
935
936(use-package expand-region
937 :bind ("C-=" . er/expand-region))
938
1eb20313
AB
939(require 'bandali-yasnippet)
940
33273849 941(use-package debbugs
ba45b932
AB
942 :bind
943 (("C-c D d" . debbugs-gnu)
8cee0db4 944 ("C-c D b" . debbugs-gnu-bugs)
ba45b932
AB
945 ("C-c D e" .
946 (lambda ()
d6c37a13 947 (interactive) ; bug-gnu-emacs
ba45b932
AB
948 (setq debbugs-gnu-current-suppress t)
949 (debbugs-gnu debbugs-gnu-default-severities '("emacs"))))
d6c37a13 950 ("C-c D g" . ; bug-gnuzilla
ba45b932
AB
951 (lambda ()
952 (interactive)
953 (setq debbugs-gnu-current-suppress t)
64b53575 954 (debbugs-gnu debbugs-gnu-default-severities '("gnuzilla"))))
d6c37a13
AB
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
64b53575
AB
961 (lambda ()
962 (interactive)
963 (setq debbugs-gnu-current-suppress t)
d6c37a13 964 (debbugs-gnu debbugs-gnu-default-severities '("guix-patches"))))))
41d290a2 965
f0a2dfe1
AB
966(comment
967
41d290a2
AB
968(use-package org-ref
969 :init
dca50cf5 970 (b/setq-every '("~/usr/org/references.bib")
41d290a2
AB
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
2f5d8190
AB
977;; (use-package fill-column-indicator)
978
47904cb7 979(use-package window
ed8c4fa9 980 :bind
0b7f98f4 981 (("C-c w s l" . (lambda ()
edb03389
AB
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)))
446cb096 989 ("C-c w q" . quit-window))
92df6c4f
AB
990 :custom
991 (split-width-threshold 150))
ed8c4fa9 992
47904cb7 993(use-package windmove
ed8c4fa9
AB
994 :defer 0.6
995 :bind
2e81c51a
AB
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)))
ed8c4fa9 1004
05068e71
AB
1005(use-package pass
1006 :commands pass
1007 :bind ("C-c a p" . pass)
1008 :hook (pass-mode . View-exit))
1009
b188e798
AB
1010(use-package pdf-tools
1011 :defer 0.5
1012 :bind (:map pdf-view-mode-map
0365678c
AB
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)
4fa43cd8
AB
1019 ("M-RET" . image-previous-line)
1020 ("C-s" . isearch-forward)
1021 ("s s" . isearch-forward))
822ac360
AB
1022 :config (pdf-tools-install nil t)
1023 :custom (pdf-view-resize-factor 1.05))
b188e798 1024
62a2088e 1025(use-package org-pdftools
47904cb7 1026 :disabled
62a2088e
AB
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
9de75957
AB
1034(use-package biblio)
1035
47904cb7 1036(use-package reftex
9a5ffb33
AB
1037 :hook (latex-mode . reftex-mode))
1038
47904cb7 1039(use-package reftex-cite
9a5ffb33
AB
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
fa9943dc 1053(use-package dmenu
fa9943dc 1054 :custom
fa9943dc
AB
1055 (dmenu-prompt-string "run: ")
1056 (dmenu-save-file (b/var "dmenu-items")))
1057
996bebf6
AB
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
9ed5410e 1068(use-package eww
03745e6e 1069 :bind ("C-c a e w" . eww)
9ed5410e
AB
1070 :custom
1071 (eww-download-directory (file-name-as-directory
1072 (getenv "XDG_DOWNLOAD_DIR"))))
1073
b57457b2 1074\f
b57457b2
AB
1075;;; Post initialization
1076
8b1a2f32 1077)
41d290a2
AB
1078(message "Loading %s...done (%.3fs)" user-init-file
1079 (float-time (time-subtract (current-time)
dca50cf5 1080 b/before-user-init-time)))
41d290a2
AB
1081
1082;;; init.el ends here