75ec3a3450e4ca36c78548e406e14f1230a1aaa0
[~bandali/configs] / init.el
1 ;;; init.el --- bandali's emacs configuration -*- lexical-binding: t -*-
2
3 ;; Copyright (C) 2018-2020 Amin Bandali <bandali@gnu.org>
4
5 ;; This program is free software: you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, either version 3 of the License, or
8 ;; (at your option) any later version.
9
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
14
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18 ;;; Commentary:
19
20 ;; GNU Emacs configuration of Amin Bandali, computer scientist,
21 ;; Free Software activist, and GNU maintainer & webmaster. Packages
22 ;; are installed through using Borg for a fully reproducible setup.
23
24 ;; Over the years, I've taken inspiration from configurations of many
25 ;; great people. Some that I can remember off the top of my head are:
26 ;;
27 ;; - https://github.com/dieggsy/dotfiles
28 ;; - https://github.com/dakra/dmacs
29 ;; - http://pages.sachachua.com/.emacs.d/Sacha.html
30 ;; - https://github.com/dakrone/eos
31 ;; - http://doc.rix.si/cce/cce.html
32 ;; - https://github.com/jwiegley/dot-emacs
33 ;; - https://github.com/wasamasa/dotemacs
34 ;; - https://github.com/hlissner/doom-emacs
35
36 ;;; Code:
37
38 ;;; Emacs initialization
39
40 (defvar b/before-user-init-time (current-time)
41 "Value of `current-time' when Emacs begins loading `user-init-file'.")
42 (defvar b/emacs-initialized nil
43 "Whether Emacs has been initialized.")
44
45 (when (not (bound-and-true-p b/emacs-initialized))
46 (message "Loading Emacs...done (%.3fs)"
47 (float-time (time-subtract b/before-user-init-time
48 before-init-time))))
49
50 ;; temporarily increase `gc-cons-threshhold' and `gc-cons-percentage'
51 ;; during startup to reduce garbage collection frequency. clearing
52 ;; `file-name-handler-alist' seems to help reduce startup time too.
53 (defvar b/gc-cons-threshold gc-cons-threshold)
54 (defvar b/gc-cons-percentage gc-cons-percentage)
55 (defvar b/file-name-handler-alist file-name-handler-alist)
56 (setq gc-cons-threshold (* 30 1024 1024) ; 30 MiB
57 gc-cons-percentage 0.6
58 file-name-handler-alist nil
59 ;; sidesteps a bug when profiling with esup
60 esup-child-profile-require-level 0)
61
62 ;; set them back to their defaults once we're done initializing
63 (defun b/post-init ()
64 "My post-initialize function, run after loading `user-init-file'."
65 (setq b/emacs-initialized t
66 gc-cons-threshold b/gc-cons-threshold
67 gc-cons-percentage b/gc-cons-percentage
68 file-name-handler-alist b/file-name-handler-alist)
69 (when (featurep 'exwm-workspace)
70 (with-eval-after-load 'exwm-workspace
71 (setq-default
72 mode-line-format
73 (append
74 mode-line-format
75 '((:eval
76 (format
77 "[%s]" (number-to-string
78 exwm-workspace-current-index))))))))
79
80 ;; make some mode-line spaces smaller
81 (csetq
82 mode-line-format
83 (mapcar
84 (lambda (x)
85 (if (and (stringp x) (or (string= x " ") (string= x " ")))
86 " "
87 x))
88 mode-line-format)
89 mode-line-buffer-identification
90 (propertized-buffer-identification "%10b")))
91 (add-hook 'after-init-hook #'b/post-init)
92
93 ;; increase number of lines kept in *Messages* log
94 (setq message-log-max 20000)
95
96 ;; optionally, uncomment to supress some byte-compiler warnings
97 ;; (see C-h v byte-compile-warnings RET for more info)
98 ;; (setq byte-compile-warnings
99 ;; '(not free-vars unresolved noruntime lexical make-local))
100
101 \f
102 ;;; whoami
103
104 (setq user-full-name "Amin Bandali"
105 user-mail-address "bandali@gnu.org")
106
107 \f
108 ;;; Package management
109
110 ;; variables of interest:
111 ;; package-archive-priorities
112 ;; package-load-list
113 ;; package-pinned-packages
114
115 ;; (let* ((b (find-file-noselect "refinery-theme.el"))
116 ;; (d (with-current-buffer b (package-buffer-info))))
117 ;; (package-generate-description-file d "refinery-theme-pkg.el"))
118 (run-with-idle-timer 0.01 nil #'require 'package)
119 (with-eval-after-load 'package
120 (when (= (length package-archives) 1)
121 (csetq
122 package-archives
123 `(,@package-archives
124 ;; ("bndl" . "https://p.bndl.org/elpa/")
125 ("org" . "https://orgmode.org/elpa/"))
126 package-load-list
127 '(;; GNU ELPA
128 (ivy "0.13.1")
129 (counsel "0.13.1")
130 (swiper "0.13.1")
131 (debbugs "0.26")
132 (delight "1.7")
133 (ebdb "0.6.19")
134 (orgalist "1.12")
135 (rt-liberation "1.31")
136 (yasnippet "0.14.0")
137 ;; bndl
138 (refinery-theme "0.1.1")
139 ;; Org ELPA
140 (org-plus-contrib "20200921"))))
141 (package-initialize))
142
143 (csetq package-archive-upload-base "/ssh:caffeine:~/www/p/elpa")
144
145 \f
146 ;;; Initial setup
147
148 ;; keep ~/.emacs.d clean
149 (defvar b/etc-dir
150 (expand-file-name
151 (convert-standard-filename "etc/") user-emacs-directory)
152 "The directory where packages place their configuration files.")
153 (defvar b/var-dir
154 (expand-file-name
155 (convert-standard-filename "var/") user-emacs-directory)
156 "The directory where packages place their persistent data files.")
157 (defvar b/lisp-dir
158 (expand-file-name
159 (convert-standard-filename "lisp/") user-emacs-directory)
160 "The directory where packages place their persistent data files.")
161 (defun b/etc (file)
162 "Expand filename FILE relative to `b/etc-dir'."
163 (expand-file-name (convert-standard-filename file) b/etc-dir))
164 (defun b/var (file)
165 "Expand filename FILE relative to `b/var-dir'."
166 (expand-file-name (convert-standard-filename file) b/var-dir))
167 (defun b/lisp (file)
168 "Expand filename FILE relative to `b/lisp-dir'."
169 (expand-file-name (convert-standard-filename file) b/lisp-dir))
170
171 (csetq
172 auto-save-list-file-prefix (b/var "auto-save/sessions/")
173 nsm-settings-file (b/var "nsm-settings.el"))
174
175 ;; separate custom file (don't want it mixing with init.el)
176 (with-eval-after-load 'custom
177 (setq custom-file (b/etc "custom.el"))
178 (when (file-exists-p custom-file)
179 (load custom-file))
180 ;; while at it, treat themes as safe
181 ;; (setf custom-safe-themes t)
182 ;; only one custom theme at a time
183 (comment
184 (defadvice load-theme (before clear-previous-themes activate)
185 "Clear existing theme settings instead of layering them"
186 (mapc #'disable-theme custom-enabled-themes))))
187
188 ;; load the secrets file if it exists, otherwise show a warning
189 (comment
190 (with-demoted-errors
191 (load (b/etc "secrets"))))
192
193 ;; start up emacs server. see
194 ;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server
195 (run-with-idle-timer 0.5 nil #'require 'server)
196 (with-eval-after-load 'server
197 (declare-function server-edit "server")
198 (global-set-key (kbd "C-c F D") #'server-edit)
199 (declare-function server-running-p "server")
200 (or (server-running-p) (server-mode)))
201
202 \f
203 ;;; Defaults
204
205 ;;;; C-level customizations
206
207 (csetq
208 ;; minibuffer
209 enable-recursive-minibuffers t
210 resize-mini-windows t
211 ;; more useful frame titles
212 ;; frame-title-format '("" invocation-name " - "
213 ;; (:eval
214 ;; (if (buffer-file-name)
215 ;; (abbreviate-file-name (buffer-file-name))
216 ;; "%b")))
217 ;; i don't feel like jumping out of my chair every now and again; so
218 ;; don't BEEP! at me, emacs
219 ring-bell-function 'ignore
220 ;; better scrolling
221 ;; scroll-margin 1
222 ;; scroll-conservatively 10000
223 scroll-step 1
224 scroll-conservatively 101
225 scroll-preserve-screen-position 1
226 ;; focus follows mouse
227 mouse-autoselect-window t)
228
229 (setq-default
230 ;; always use space for indentation
231 indent-tabs-mode nil
232 tab-width 4
233 ;; case-sensitive search (and `dabbrev-expand')
234 ;; case-fold-search nil
235 ;; cursor shape
236 cursor-type t)
237
238 (set-fontset-font t 'arabic "Vazir")
239
240 ;; unicode support
241 (comment
242 (dolist (ft (fontset-list))
243 (set-fontset-font
244 ft
245 'unicode
246 (font-spec :name "Source Code Pro" :size 14))
247 (set-fontset-font
248 ft
249 'unicode
250 (font-spec :name "DejaVu Sans Mono")
251 nil
252 'append)
253 ;; (set-fontset-font
254 ;; ft
255 ;; 'unicode
256 ;; (font-spec
257 ;; :name "Symbola monospacified for DejaVu Sans Mono")
258 ;; nil
259 ;; 'append)
260 ;; (set-fontset-font
261 ;; ft
262 ;; #x2115 ; ℕ
263 ;; (font-spec :name "DejaVu Sans Mono")
264 ;; nil
265 ;; 'append)
266 (set-fontset-font
267 ft
268 (cons ?Α ?ω)
269 (font-spec :name "DejaVu Sans Mono" :size 14)
270 nil
271 'prepend)))
272
273 ;;;; Elisp-level customizations
274
275 ;; startup
276 ;; don't need to see the startup echo area message
277 (advice-add #'display-startup-echo-area-message :override #'ignore)
278 (csetq
279 ;; i want *scratch* as my startup buffer
280 initial-buffer-choice t
281 ;; i don't need the default hint
282 initial-scratch-message nil
283 ;; use customizable text-mode as major mode for *scratch*
284 ;; (initial-major-mode 'text-mode)
285 ;; inhibit buffer list when more than 2 files are loaded
286 inhibit-startup-buffer-menu t
287 ;; don't need to see the startup screen or echo area message
288 inhibit-startup-screen t
289 inhibit-startup-echo-area-message user-login-name)
290
291 ;; files
292 (csetq
293 ;; backups (C-h v make-backup-files RET)
294 backup-by-copying t
295 backup-directory-alist (list (cons "." (b/var "backup/")))
296 version-control t
297 delete-old-versions t
298 ;; auto-save
299 auto-save-file-name-transforms `((".*" ,(b/var "auto-save/") t))
300 ;; insert newline at the end of files
301 require-final-newline t
302 ;; open read-only file buffers in view-mode
303 ;; (enables niceties like `q' for quit)
304 view-read-only t)
305
306 ;; novice
307 ;; disable disabled commands
308 (csetq disabled-command-function nil)
309
310 ;; lazy-person-friendly yes/no prompts
311 (defalias 'yes-or-no-p #'y-or-n-p)
312
313 ;; autorevert: enable automatic reloading of changed buffers and files
314 (csetq auto-revert-verbose nil
315 global-auto-revert-non-file-buffers nil)
316 (require 'autorevert)
317 (global-auto-revert-mode 1)
318
319 ;; time and battery in mode-line
320 (csetq
321 display-time-default-load-average nil
322 display-time-format " %a %b %-e %-l:%M%P"
323 display-time-mail-icon '(image :type xpm
324 :file "gnus/gnus-pointer.xpm"
325 :ascent center)
326 display-time-use-mail-icon t)
327 (require 'time)
328 (display-time-mode)
329
330 (csetq battery-mode-line-format " %p%% %t")
331 (require 'battery)
332 (display-battery-mode)
333
334 (require 'fringe)
335 ;; smaller fringe
336 ;; (fringe-mode '(3 . 1))
337 (fringe-mode nil)
338
339 (require 'winner)
340 ;; enable winner-mode (C-h f winner-mode RET)
341 (winner-mode 1)
342
343 (with-eval-after-load 'compile
344 ;; don't display *compilation* buffer on success. based on
345 ;; https://stackoverflow.com/a/17788551, with changes to use `cl-letf'
346 ;; instead of the now obsolete `flet'.
347 (defun b/compilation-finish-function (buffer outstr)
348 (unless (string-match "finished" outstr)
349 (switch-to-buffer-other-window buffer))
350 t)
351
352 (setq compilation-finish-functions #'b/compilation-finish-function)
353
354 (require 'cl-macs)
355
356 (defadvice compilation-start
357 (around inhibit-display
358 (command &optional mode name-function highlight-regexp))
359 (if (not (string-match "^\\(find\\|grep\\)" command))
360 (cl-letf (((symbol-function 'display-buffer) #'ignore))
361 (save-window-excursion ad-do-it))
362 ad-do-it))
363 (ad-activate 'compilation-start))
364
365 ;; isearch
366 (csetq
367 ;; allow scrolling in Isearch
368 isearch-allow-scroll t
369 ;; search for non-ASCII characters: i’d like non-ASCII characters such
370 ;; as ‘’“”«»‹›áⓐ𝒶 to be selected when i search for their ASCII
371 ;; counterpart. shoutout to
372 ;; http://endlessparentheses.com/new-in-emacs-25-1-easily-search-non-ascii-characters.html
373 search-default-mode #'char-fold-to-regexp)
374
375 ;; replace
376 ;; uncomment to extend the above behaviour to query-replace
377 ;; (csetq replace-char-fold t)
378
379 ;; vc
380 (global-set-key (kbd "C-x v C-=") #'vc-ediff)
381
382 (with-eval-after-load 'vc-git
383 (csetq vc-git-print-log-follow t
384 vc-git-show-stash 0))
385
386 (csetq ediff-window-setup-function 'ediff-setup-windows-plain
387 ediff-split-window-function 'split-window-horizontally)
388 (with-eval-after-load 'ediff
389 (add-hook 'ediff-after-quit-hook-internal #'winner-undo))
390
391 ;; face-remap
392 (csetq
393 ;; gentler font resizing
394 text-scale-mode-step 1.05)
395
396 (run-with-idle-timer 0.4 nil #'require 'mwheel)
397 (csetq mouse-wheel-scroll-amount '(1 ((shift) . 1)) ; one line at a time
398 mouse-wheel-progressive-speed nil ; don't accelerate scrolling
399 mouse-wheel-follow-mouse t) ; scroll window under mouse
400
401 (run-with-idle-timer 0.4 nil #'require 'pixel-scroll)
402 (with-eval-after-load 'pixel-scroll
403 (pixel-scroll-mode 1))
404
405 ;; epg-config
406 (csetq
407 epg-gpg-program (executable-find "gpg")
408 ;; ask for GPG passphrase in minibuffer
409 ;; this will fail if gpg>=2.1 is not available
410 epg-pinentry-mode 'loopback)
411
412 ;; (require 'pinentry)
413 ;; workaround for systemd-based distros:
414 ;; (setq pinentry--socket-dir server-socket-dir)
415 ;; (pinentry-start)
416
417 ;; auth-source
418 (csetq
419 auth-sources '("~/.authinfo.gpg")
420 authinfo-hidden (regexp-opt '("password" "client-secret" "token")))
421
422 \f
423 ;;; General key bindings
424
425 (global-set-key (kbd "C-a") #'b/move-indentation-or-beginning-of-line)
426 (global-set-key (kbd "C-c a i") #'ielm)
427 (global-set-key (kbd "C-c d") #'b/duplicate-line-or-region)
428 (global-set-key (kbd "C-S-j") #'b/join-line-top)
429 (global-set-key (kbd "C-c x") #'execute-extended-command)
430
431 ;; evaling and macro-expanding
432 (global-set-key (kbd "C-c e b") #'eval-buffer)
433 (global-set-key (kbd "C-c e e") #'eval-last-sexp)
434 (global-set-key (kbd "C-c e p") #'pp-macroexpand-last-sexp)
435 (global-set-key (kbd "C-c e r") #'eval-region)
436
437 ;; emacs things
438 (global-set-key (kbd "C-c e i") #'emacs-init-time)
439 (global-set-key (kbd "C-c e u") #'emacs-uptime)
440 (global-set-key (kbd "C-c e v") #'emacs-version)
441
442 ;; finding
443 (global-set-key (kbd "C-c f .") #'find-file)
444 (global-set-key (kbd "C-c f d") #'find-name-dired)
445 (global-set-key (kbd "C-c f l") #'find-library)
446
447 ;; frames
448 (global-set-key (kbd "C-c F m") #'make-frame-command)
449 (global-set-key (kbd "C-c F d") #'delete-frame)
450
451 ;; help/describe
452 (global-set-key (kbd "C-S-h C") #'describe-char)
453 (global-set-key (kbd "C-S-h F") #'describe-face)
454
455 ;; (global-set-key (kbd "C-x k") #'b/kill-current-buffer)
456 ;; (global-set-key (kbd "C-x K") #'kill-buffer)
457 ;; (global-set-key (kbd "C-x s") #'save-buffer)
458 ;; (global-set-key (kbd "C-x S") #'save-some-buffers)
459
460 (define-key emacs-lisp-mode-map (kbd "<C-return>") #'b/add-elisp-section)
461
462 (when (display-graphic-p)
463 (global-unset-key (kbd "C-z")))
464
465 \f
466 ;;; Essential packages
467
468 ;; (require 'bandali-exwm)
469
470 (require 'bandali-org)
471
472 (require 'bandali-theme)
473
474 ;; (require 'bandali-magit)
475
476 ;; recently opened files
477 (csetq recentf-max-saved-items 2000
478 recentf-save-file (b/var "recentf-save.el"))
479 (run-with-idle-timer 0.2 nil #'require 'recentf)
480 (with-eval-after-load 'recentf
481 ;; (add-to-list 'recentf-keep #'file-remote-p)
482 (recentf-mode))
483
484 ;; needed for history for counsel
485 (csetq amx-save-file (b/var "amx-save.el"))
486 (add-to-list 'load-path (b/lisp "s"))
487 (add-to-list 'load-path (b/lisp "amx"))
488 (run-with-idle-timer 0.3 nil #'require 'amx)
489 (with-eval-after-load 'amx
490 (amx-mode))
491
492 (require 'bandali-ivy)
493
494 (require 'bandali-eshell)
495
496 (require 'bandali-ibuffer)
497
498 ;; outline
499 ;; (with-eval-after-load 'outline
500 ;; (when (featurep 'which-key)
501 ;; (which-key-add-key-based-replacements
502 ;; "C-c @" "outline"
503 ;; "s-O" "outline"))
504 ;; (define-key outline-minor-mode-map (kbd "<s-tab>")
505 ;; #'outline-toggle-children)
506 ;; (define-key outline-minor-mode-map (kbd "M-p")
507 ;; #'outline-previous-visible-heading)
508 ;; (define-key outline-minor-mode-map (kbd "M-n")
509 ;; #'outline-next-visible-heading)
510 ;; (defvar b/outline-prefix-map)
511 ;; (define-prefix-command 'b/outline-prefix-map)
512 ;; (define-key outline-minor-mode-map (kbd "s-O")
513 ;; 'b/outline-prefix-map)
514 ;; (define-key b/outline-prefix-map (kbd "TAB")
515 ;; #'outline-toggle-children)
516 ;; (define-key b/outline-prefix-map (kbd "a")
517 ;; #'outline-hide-body)
518 ;; (define-key b/outline-prefix-map (kbd "H")
519 ;; #'outline-hide-body)
520 ;; (define-key b/outline-prefix-map (kbd "S")
521 ;; #'outline-show-all)
522 ;; (define-key b/outline-prefix-map (kbd "h")
523 ;; #'outline-hide-subtree)
524 ;; (define-key b/outline-prefix-map (kbd "s")
525 ;; #'outline-show-subtree))
526 ;; (add-hook 'prog-mode-hook #'outline-minor-mode)
527
528 (require 'bandali-dired)
529
530 (with-eval-after-load 'help
531 (temp-buffer-resize-mode)
532 (csetq help-window-select t))
533
534 (with-eval-after-load 'help-mode
535 ;; local key bindings
536 (define-key help-mode-map (kbd "p") #'backward-button)
537 (define-key help-mode-map (kbd "n") #'forward-button))
538
539 (with-eval-after-load 'tramp
540 (csetq tramp-auto-save-directory (b/var "tramp/auto-save/")
541 tramp-persistency-file-name (b/var "tramp/persistency.el"))
542 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
543 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
544 (add-to-list 'tramp-default-proxies-alist
545 (list (regexp-quote (system-name)) nil nil)))
546
547 (with-eval-after-load 'doc-view
548 (define-key doc-view-mode-map (kbd "M-RET") #'image-previous-line))
549
550 (csetq shr-max-width 80)
551
552 ;; Email (with Gnus, message, and EBDB)
553 (require 'bandali-gnus)
554 (with-eval-after-load 'sendmail
555 (csetq sendmail-program (executable-find "msmtp")
556 ;; message-sendmail-extra-arguments '("-v" "-d")
557 mail-specify-envelope-from t
558 mail-envelope-from 'header))
559 (require 'bandali-message)
560 (require 'bandali-ebdb)
561
562 ;; IRC (with ERC)
563 (require 'bandali-erc)
564
565 (add-to-list 'load-path (b/lisp "scpaste"))
566 (with-eval-after-load 'scpaste
567 (csetq scpaste-http-destination "https://p.bndl.org"
568 scpaste-scp-destination "p:~"))
569 (autoload 'scpaste "scpaste" nil t)
570 (autoload 'scpaste-region "scpaste" nil t)
571 (global-set-key (kbd "C-c a p p") #'scpaste)
572 (global-set-key (kbd "C-c a p r") #'scpaste-region)
573
574 \f
575 ;;; Editing
576
577 ;; display Lisp objects at point in the echo area
578 (when (version< "25" emacs-version)
579 (with-eval-after-load 'eldoc
580 (csetq eldoc-minor-mode-string " eldoc")
581 (global-eldoc-mode)))
582
583 ;; highlight matching parens
584 (require 'paren)
585 (show-paren-mode)
586
587 ;; (require 'elec-pair)
588 ;; (electric-pair-mode)
589
590 (csetq
591 ;; Save what I copy into clipboard from other applications into Emacs'
592 ;; kill-ring, which would allow me to still be able to easily access
593 ;; it in case I kill (cut or copy) something else inside Emacs before
594 ;; yanking (pasting) what I'd originally intended to.
595 save-interprogram-paste-before-kill t)
596 (with-eval-after-load 'simple
597 (column-number-mode 1))
598
599 ;; save minibuffer history
600 (require 'savehist)
601 (csetq savehist-file (b/var "savehist.el"))
602 (savehist-mode)
603 (add-to-list 'savehist-additional-variables 'kill-ring)
604
605 ;; automatically save place in files
606 (when (version< "25" emacs-version)
607 (csetq save-place-file (b/var "save-place.el"))
608 (save-place-mode))
609
610 (defun indicate-buffer-boundaries-left ()
611 (csetq indicate-buffer-boundaries 'left))
612 (with-eval-after-load 'prog-mode
613 (global-prettify-symbols-mode))
614 (add-hook 'prog-mode-hook #'indicate-buffer-boundaries-left)
615
616 (define-key text-mode-map (kbd "C-<return>") #'b/insert-asterism)
617 (add-hook 'text-mode-hook #'indicate-buffer-boundaries-left)
618 (add-hook 'text-mode-hook #'flyspell-mode)
619
620 (add-to-list 'auto-mode-alist '("\\.*rc$" . conf-mode))
621
622 (add-to-list 'auto-mode-alist '("\\.bashrc$" . sh-mode))
623
624 (with-eval-after-load 'flyspell
625 (csetq flyspell-mode-line-string " fly"))
626
627 ;; flycheck
628 ;; (run-with-idle-timer 0.6 nil #'require 'flycheck)
629 ;; (with-eval-after-load 'flycheck
630 ;; (csetq
631 ;; ;; Use the load-path from running Emacs when checking elisp files
632 ;; flycheck-emacs-lisp-load-path 'inherit
633 ;; ;; Only flycheck when I actually save the buffer
634 ;; flycheck-check-syntax-automatically '(mode-enabled save)
635 ;; flycheck-mode-line-prefix "flyc"))
636 ;; (define-key flycheck-mode-map (kbd "M-P") #'flycheck-previous-error)
637 ;; (define-key flycheck-mode-map (kbd "M-N") #'flycheck-next-error)
638 ;; (add-hook 'prog-mode-hook #'flycheck-mode)
639
640 ;; ispell
641 ;; http://endlessparentheses.com/ispell-and-apostrophes.html
642 ;; (run-with-idle-timer 0.6 nil #'require 'ispell)
643 ;; (with-eval-after-load 'ispell
644 ;; ;; ’ can be part of a word
645 ;; (csetq ispell-local-dictionary-alist
646 ;; `((nil "[[:alpha:]]" "[^[:alpha:]]"
647 ;; "['\x2019]" nil ("-B") nil utf-8))
648 ;; ispell-program-name (executable-find "hunspell"))
649 ;; ;; don't send ’ to the subprocess
650 ;; (defun endless/replace-apostrophe (args)
651 ;; (cons (replace-regexp-in-string
652 ;; "’" "'" (car args))
653 ;; (cdr args)))
654 ;; (advice-add #'ispell-send-string :filter-args
655 ;; #'endless/replace-apostrophe)
656 ;; ;; convert ' back to ’ from the subprocess
657 ;; (defun endless/replace-quote (args)
658 ;; (if (not (derived-mode-p 'org-mode))
659 ;; args
660 ;; (cons (replace-regexp-in-string
661 ;; "'" "’" (car args))
662 ;; (cdr args))))
663 ;; (advice-add #'ispell-parse-output :filter-args
664 ;; #'endless/replace-quote))
665
666 ;; abbrev
667 (csetq abbrev-file-name (b/etc "abbrev.el"))
668 (add-hook 'text-mode-hook #'abbrev-mode)
669
670 \f
671 ;;; Programming modes
672
673 (with-eval-after-load 'lisp-mode
674 (defun indent-spaces-mode ()
675 (setq indent-tabs-mode nil))
676 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
677
678 ;; alloy
679 (add-to-list 'load-path (b/lisp "alloy-mode"))
680 (autoload 'alloy-mode "alloy-mode" nil t)
681 (with-eval-after-load 'alloy-mode
682 (csetq alloy-basic-offset 2)
683 ;; (defun b/alloy-simple-indent (start end)
684 ;; (interactive "r")
685 ;; ;; (if (region-active-p)
686 ;; ;; (indent-rigidly start end alloy-basic-offset)
687 ;; ;; (if (bolp)
688 ;; ;; (indent-rigidly (line-beginning-position)
689 ;; ;; (line-end-position)
690 ;; ;; alloy-basic-offset)))
691 ;; (indent-to (+ (current-column) alloy-basic-offset)))
692 ;; local key bindings
693 (define-key alloy-mode-map (kbd "RET") #'electric-newline-and-maybe-indent)
694 ;; (define-key alloy-mode-map (kbd "TAB") #'b/alloy-simple-indent)
695 (define-key alloy-mode-map (kbd "TAB") #'indent-for-tab-command))
696 (add-to-list 'auto-mode-alist '("\\.\\(als\\|dsh\\)\\'" . alloy-mode))
697 (add-hook 'alloy-mode-hook (lambda nil (setq-local indent-tabs-mode nil)))
698
699 ;; lean
700 ;; (eval-when-compile (defvar lean-mode-map))
701 ;; (run-with-idle-timer 0.4 nil #'require 'lean-mode)
702 ;; (with-eval-after-load 'lean-mode
703 ;; (require 'lean-input)
704 ;; (csetq default-input-method "Lean"
705 ;; lean-input-tweak-all '(lean-input-compose
706 ;; (lean-input-prepend "/")
707 ;; (lean-input-nonempty))
708 ;; lean-input-user-translations '(("/" "/")))
709 ;; (lean-input-setup)
710 ;; ;; local key bindings
711 ;; (define-key lean-mode-map (kbd "S-SPC") #'company-complete))
712
713 (with-eval-after-load 'sgml-mode
714 (csetq sgml-basic-offset 0))
715
716 (with-eval-after-load 'css-mode
717 (csetq css-indent-offset 2))
718
719 ;; po-mode
720 ;; (add-hook 'po-mode-hook (lambda nil (run-with-timer 0.1 nil 'View-exit)))
721
722 ;; auctex
723 ;; (csetq font-latex-fontify-sectioning 'color)
724
725 (with-eval-after-load 'tex-mode
726 (cl-delete-if
727 (lambda (p) (string-match "^---?" (car p)))
728 tex--prettify-symbols-alist))
729 (add-hook 'tex-mode-hook #'auto-fill-mode)
730 (add-hook 'tex-mode-hook #'flyspell-mode)
731
732 \f
733 ;;; Emacs enhancements & auxiliary packages
734
735 (with-eval-after-load 'man
736 (csetq Man-width 80))
737
738 (defun b/*scratch* ()
739 "Switch to `*scratch*' buffer, creating it if it does not exist."
740 (interactive)
741 (switch-to-buffer
742 (or (get-buffer "*scratch*")
743 (with-current-buffer (get-buffer-create "*scratch*")
744 (set-buffer-major-mode (current-buffer))
745 (current-buffer)))))
746 (global-set-key (kbd "C-c s") #'b/*scratch*)
747
748 ;; ,----
749 ;; | make pretty boxed quotes like this
750 ;; `----
751 (add-to-list 'load-path (b/lisp "boxquote"))
752 (run-with-idle-timer 0.6 nil #'require 'boxquote)
753 (with-eval-after-load 'boxquote
754 (defvar b/boxquote-prefix-map)
755 (define-prefix-command 'b/boxquote-prefix-map)
756 (global-set-key (kbd "C-c q") 'b/boxquote-prefix-map)
757 (define-key b/boxquote-prefix-map (kbd "b") #'boxquote-buffer)
758 (define-key b/boxquote-prefix-map (kbd "B") #'boxquote-insert-buffer)
759 (define-key b/boxquote-prefix-map (kbd "d") #'boxquote-defun)
760 (define-key b/boxquote-prefix-map (kbd "F") #'boxquote-insert-file)
761 (define-key b/boxquote-prefix-map (kbd "hf") #'boxquote-describe-function)
762 (define-key b/boxquote-prefix-map (kbd "hk") #'boxquote-describe-key)
763 (define-key b/boxquote-prefix-map (kbd "hv") #'boxquote-describe-variable)
764 (define-key b/boxquote-prefix-map (kbd "hw") #'boxquote-where-is)
765 (define-key b/boxquote-prefix-map (kbd "k") #'boxquote-kill)
766 (define-key b/boxquote-prefix-map (kbd "p") #'boxquote-paragraph)
767 (define-key b/boxquote-prefix-map (kbd "q") #'boxquote-boxquote)
768 (define-key b/boxquote-prefix-map (kbd "r") #'boxquote-region)
769 (define-key b/boxquote-prefix-map (kbd "s") #'boxquote-shell-command)
770 (define-key b/boxquote-prefix-map (kbd "t") #'boxquote-text)
771 (define-key b/boxquote-prefix-map (kbd "T") #'boxquote-title)
772 (define-key b/boxquote-prefix-map (kbd "u") #'boxquote-unbox)
773 (define-key b/boxquote-prefix-map (kbd "U") #'boxquote-unbox-region)
774 (define-key b/boxquote-prefix-map (kbd "y") #'boxquote-yank)
775 (define-key b/boxquote-prefix-map (kbd "M-q") #'boxquote-fill-paragraph)
776 (define-key b/boxquote-prefix-map (kbd "M-w") #'boxquote-kill-ring-save))
777
778 (add-to-list 'load-path (b/lisp "hl-todo"))
779 (run-with-idle-timer 0.5 nil #'require 'hl-todo)
780 (with-eval-after-load 'hl-todo
781 ;; highlight TODOs in buffers
782 (global-hl-todo-mode))
783
784 (add-to-list 'load-path (b/lisp "page-break-lines"))
785 (run-with-idle-timer 0.5 nil #'require 'page-break-lines)
786 (with-eval-after-load 'page-break-lines
787 (csetq page-break-lines-max-width fill-column)
788 (global-page-break-lines-mode))
789
790 ;; expand-region
791 (global-set-key (kbd "C-=") #'er/expand-region)
792
793 (run-with-idle-timer 0.6 nil #'require 'yasnippet)
794 (with-eval-after-load 'yasnippet
795 (declare-function yas-reload-all
796 "yasnippet" (&optional no-jit interactive))
797 (declare-function yas-maybe-expand-abbrev-key-filter
798 "yasnippet" (cmd))
799
800 (defconst yas-verbosity-cur yas-verbosity)
801 (setq yas-verbosity 2)
802 (csetq yas-snippet-dirs `(,(b/etc "yasnippet/snippets")))
803 (add-to-list 'yas-snippet-dirs "~/src/git/guix/etc/snippets" t)
804 (yas-reload-all)
805 (setq yas-verbosity yas-verbosity-cur)
806
807 (defun b/yas-maybe-expand-abbrev-key-filter (cmd)
808 (when (and (yas-maybe-expand-abbrev-key-filter cmd)
809 (not (bound-and-true-p git-commit-mode)))
810 cmd))
811 (defconst b/yas-maybe-expand
812 '(menu-item "" yas-expand
813 :filter b/yas-maybe-expand-abbrev-key-filter))
814 (define-key yas-minor-mode-map (kbd "SPC") b/yas-maybe-expand)
815
816 (yas-global-mode))
817
818 ;; debbugs
819 (global-set-key (kbd "C-c D d") #'debbugs-gnu)
820 (global-set-key (kbd "C-c D b") #'debbugs-gnu-bugs)
821 (global-set-key (kbd "C-c D e") ; bug-gnu-emacs
822 (lambda ()
823 (interactive)
824 (setq debbugs-gnu-current-suppress t)
825 (debbugs-gnu debbugs-gnu-default-severities
826 '("emacs"))))
827 (global-set-key (kbd "C-c D g") ; bug-gnuzilla
828 (lambda ()
829 (interactive)
830 (setq debbugs-gnu-current-suppress t)
831 (debbugs-gnu debbugs-gnu-default-severities
832 '("gnuzilla"))))
833 (global-set-key (kbd "C-c D G b") ; bug-guix
834 (lambda ()
835 (interactive)
836 (setq debbugs-gnu-current-suppress t)
837 (debbugs-gnu debbugs-gnu-default-severities
838 '("guix"))))
839 (global-set-key (kbd "C-c D G p") ; guix-patches
840 (lambda ()
841 (interactive)
842 (setq debbugs-gnu-current-suppress t)
843 (debbugs-gnu debbugs-gnu-default-severities
844 '("guix-patches"))))
845
846 ;; url and url-cache
847 (csetq
848 url-configuration-directory (b/var "url/configuration/")
849 url-cache-directory (b/var "url/cache/"))
850
851 ;; eww
852 (csetq eww-download-directory (file-name-as-directory
853 (getenv "XDG_DOWNLOAD_DIR")))
854 (global-set-key (kbd "C-c a e w") #'eww)
855
856 ;; ;; org-ref
857 ;; (csetq
858 ;; reftex-default-bibliography '("~/usr/org/references.bib")
859 ;; org-ref-default-bibliography '("~/usr/org/references.bib")
860 ;; org-ref-bibliography-notes "~/usr/org/notes.org"
861 ;; org-ref-pdf-directory "~/usr/org/bibtex-pdfs/")
862
863 ;; fill-column-indicator ?
864
865 ;; window
866 (csetq split-width-threshold 150)
867 (global-set-key (kbd "C-c w s l")
868 (lambda ()
869 (interactive)
870 (split-window-right)
871 (other-window 1)))
872 (global-set-key (kbd "C-c w s j")
873 (lambda ()
874 (interactive)
875 (split-window-below)
876 (other-window 1)))
877 (global-set-key (kbd "C-c w q") #'quit-window)
878
879 (run-with-idle-timer 0.6 nil #'require 'windmove)
880 (global-set-key (kbd "C-c w h") #'windmove-left)
881 (global-set-key (kbd "C-c w j") #'windmove-down)
882 (global-set-key (kbd "C-c w k") #'windmove-up)
883 (global-set-key (kbd "C-c w l") #'windmove-right)
884 (global-set-key (kbd "C-c w H") #'windmove-swap-states-left)
885 (global-set-key (kbd "C-c w J") #'windmove-swap-states-down)
886 (global-set-key (kbd "C-c w K") #'windmove-swap-states-up)
887 (global-set-key (kbd "C-c w L") #'windmove-swap-states-right)
888
889 ;; pass
890 ;; (global-set-key (kbd "C-c a p") #'pass)
891 ;; (add-hook 'pass-mode-hook #'View-exit)
892
893 ;; reftex
894 ;; uncomment to disable reftex-cite's default choice of previous word
895 ;; (with-eval-after-load 'reftex
896 ;; (require 'reftex-cite)
897 ;; (defun reftex-get-bibkey-default ()
898 ;; "If the cursor is in a citation macro, return the word before the macro."
899 ;; (let* ((macro (reftex-what-macro 1)))
900 ;; (save-excursion
901 ;; (when (and macro (string-match "cite" (car macro)))
902 ;; (goto-char (cdr macro)))
903 ;; (reftex-this-word)))))
904 (add-hook 'latex-mode-hook #'reftex-mode)
905
906 ;; dmenu
907 ;; (csetq
908 ;; dmenu-prompt-string "run: "
909 ;; dmenu-save-file (b/var "dmenu-items"))
910
911 ;; eosd ?
912
913 ;; delight
914 (run-with-idle-timer 0.5 nil #'require 'delight)
915 (with-eval-after-load 'delight
916 (delight 'auto-fill-function " f" "simple")
917 (delight 'abbrev-mode "" "abbrev")
918 (delight 'page-break-lines-mode "" "page-break-lines")
919 (delight 'ivy-mode "" "ivy")
920 (delight 'counsel-mode "" "counsel")
921 (delight 'mml-mode " mml" "mml")
922 (delight 'yas-minor-mode "" "yasnippet"))
923
924 \f
925 ;;; Post initialization
926
927 (message "Loading %s...done (%.3fs)" user-init-file
928 (float-time (time-subtract (current-time)
929 b/before-user-init-time)))
930
931 ;;; init.el ends here