* .config/dunst/dunstrc: Update according to v1.5.0.
[~bandali/configs] / .emacs.d / init.el
... / ...
CommitLineData
1;;; init.el --- bandali's emacs configuration -*- lexical-binding: t -*-
2
3;; Copyright (C) 2018-2022 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 bandali, free software activist,
21;; computing scientist, and GNU maintainer and volunteer.
22
23;; Over the years, I've taken inspiration from configurations of many
24;; great people. Some that I can remember off the top of my head are:
25;;
26;; - https://github.com/dieggsy/dotfiles
27;; - https://github.com/dakra/dmacs
28;; - http://pages.sachachua.com/.emacs.d/Sacha.html
29;; - https://github.com/dakrone/eos
30;; - http://doc.rix.si/cce/cce.html
31;; - https://github.com/jwiegley/dot-emacs
32;; - https://github.com/wasamasa/dotemacs
33;; - https://github.com/hlissner/doom-emacs
34
35;;; Code:
36
37;; whoami
38(setq user-full-name "Amin Bandali"
39 user-mail-address "bandali@gnu.org")
40
41\f
42;;; Package management
43
44;; variables of interest:
45;; package-archive-priorities
46;; package-load-list
47;; package-pinned-packages
48
49;; (let* ((b (find-file-noselect "refinery-theme.el"))
50;; (d (with-current-buffer b (package-buffer-info))))
51;; (package-generate-description-file d "refinery-theme-pkg.el"))
52(run-with-idle-timer 0.01 nil #'require 'package)
53(with-eval-after-load 'package
54 ;; (setq
55 ;; ;; package-archives
56 ;; ;; `(,@package-archives
57 ;; ;; ("bndl" . "https://p.bndl.org/elpa/"))
58 ;; package-load-list
59 ;; '(;; GNU ELPA
60 ;; (debbugs "0.29")
61 ;; (delight "1.7")
62 ;; (emms "7.7")
63 ;; (rt-liberation "2.4")))
64(package-initialize))
65
66(setq package-archive-upload-base "/ssh:caffeine:~/www/p/elpa")
67
68\f
69;;; Initial setup
70
71;; Keep ~/.emacs.d clean.
72(defvar b/etc-dir
73 (expand-file-name
74 (convert-standard-filename "etc/") user-emacs-directory)
75 "The directory where packages place their configuration files.")
76(defvar b/var-dir
77 (expand-file-name
78 (convert-standard-filename "var/") user-emacs-directory)
79 "The directory where packages place their persistent data files.")
80(defvar b/lisp-dir
81 (expand-file-name
82 (convert-standard-filename "lisp/") user-emacs-directory)
83 "The directory where packages place their persistent data files.")
84(defun b/etc (file)
85 "Expand filename FILE relative to `b/etc-dir'."
86 (expand-file-name (convert-standard-filename file) b/etc-dir))
87(defun b/var (file)
88 "Expand filename FILE relative to `b/var-dir'."
89 (expand-file-name (convert-standard-filename file) b/var-dir))
90(defun b/lisp (file)
91 "Expand filename FILE relative to `b/lisp-dir'."
92 (expand-file-name (convert-standard-filename file) b/lisp-dir))
93
94;; Separate custom file (don't want it mixing with init.el).
95(with-eval-after-load 'custom
96 (setq custom-file (b/etc "custom.el"))
97 (when (file-exists-p custom-file)
98 (load custom-file))
99 ;; Only one custom theme at a time.
100 ;; (defadvice load-theme (before clear-previous-themes activate)
101 ;; "Clear existing theme settings instead of layering them"
102 ;; (mapc #'disable-theme custom-enabled-themes))
103 )
104
105;; Load the secrets file if it exists, otherwise show a warning.
106;; (with-demoted-errors
107;; (load (b/etc "secrets")))
108
109;; Start up emacs server:
110;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html
111(run-with-idle-timer 0.5 nil #'require 'server)
112(with-eval-after-load 'server
113 (declare-function server-edit "server")
114 (global-set-key (kbd "C-c F D") #'server-edit)
115 (declare-function server-running-p "server")
116 (or (server-running-p) (server-mode)))
117
118\f
119;;; Defaults
120
121;;;; C-level customizations
122
123(setq
124 ;; line-spacing 3
125 completion-ignore-case t
126 read-buffer-completion-ignore-case t
127 enable-recursive-minibuffers t
128 resize-mini-windows t
129 message-log-max 20000
130 mode-line-compact t
131 ;; mouse-autoselect-window t
132 scroll-conservatively 15
133 scroll-preserve-screen-position 1
134 ;; I don't feel like jumping out of my chair every now and again;
135 ;; so...don't *BEEP* at me, Emacs. =)
136 ring-bell-function 'ignore)
137
138(setq-default
139 ;; Case-sensitive search (and `dabbrev-expand').
140 ;; case-fold-search nil
141 indent-tabs-mode nil ; always use space for indentation
142 tab-width 4
143 indicate-buffer-boundaries 'left)
144
145;; Lazy-person-friendly yes/no prompts.
146(defalias 'yes-or-no-p #'y-or-n-p)
147
148(when (display-graphic-p)
149 (set-fontset-font t 'arabic "Vazir"))
150;; ;; (set-frame-font "Drafting Mono-14:weight=light" nil t)
151;; (set-frame-font "Drafting Mono:pixelsize=16" nil t)
152;; (set-face-attribute 'bold nil :weight 'semi-bold)
153
154;;;; Elisp-level customizations
155
156(with-eval-after-load 'minibuffer
157 (setq read-file-name-completion-ignore-case t))
158
159;; `startup'
160(setq auto-save-list-file-prefix (b/var "auto-save/sessions/"))
161
162(with-eval-after-load 'files
163 (setq
164 ;; backups (C-h v make-backup-files RET)
165 backup-by-copying t
166 backup-directory-alist (list (cons "." (b/var "backup/")))
167 version-control t
168 delete-old-versions t
169 ;; auto-save
170 auto-save-file-name-transforms `((".*" ,(b/var "auto-save/") t))
171 ;; insert newline at the end of files
172 ;; require-final-newline t
173 ;; open read-only file buffers in view-mode
174 ;; (enables niceties like `q' for quit)
175 view-read-only t))
176
177;; `novice'
178(setq disabled-command-function nil)
179
180;; `subr'
181;; (keyboard-translate ?\( ?\[)
182;; (keyboard-translate ?\) ?\])
183;; (keyboard-translate ?\[ ?\()
184;; (keyboard-translate ?\] ?\))
185
186(run-with-idle-timer 0.1 nil #'require 'autorevert)
187(with-eval-after-load 'autorevert
188 (setq
189 ;; auto-revert-verbose nil
190 global-auto-revert-non-file-buffers nil)
191 (global-auto-revert-mode 1))
192
193(run-with-idle-timer 0.1 nil #'require 'time)
194(with-eval-after-load 'time
195 (setq
196 display-time-default-load-average nil
197 display-time-format " %a %b %-e %-l:%M%P"
198 display-time-mail-icon '(image :type xpm
199 :file "gnus/gnus-pointer.xpm"
200 :ascent center)
201 display-time-use-mail-icon t
202 zoneinfo-style-world-list
203 `(,@zoneinfo-style-world-list
204 ("Etc/UTC" "UTC")
205 ("Asia/Tehran" "Tehran")
206 ("Australia/Melbourne" "Melbourne")))
207 (display-time-mode))
208
209(run-with-idle-timer 0.1 nil #'require 'battery)
210(with-eval-after-load 'battery
211 (setq battery-mode-line-format " %p%% %t")
212 (display-battery-mode))
213
214;; (with-eval-after-load 'fringe
215;; ;; smaller fringe
216;; (fringe-mode '(3 . 1)))
217
218(run-with-idle-timer 0.5 nil #'require 'winner)
219(with-eval-after-load 'winner
220 (winner-mode 1))
221
222(run-with-idle-timer 0.5 nil #'require 'windmove)
223(with-eval-after-load 'windmove
224 (setq windmove-wrap-around t)
225 (global-set-key (kbd "M-H") #'windmove-left)
226 (global-set-key (kbd "M-L") #'windmove-right)
227 (global-set-key (kbd "M-K") #'windmove-up)
228 (global-set-key (kbd "M-J") #'windmove-down))
229
230(with-eval-after-load 'compile
231 ;; don't display *compilation* buffer on success. based on
232 ;; https://stackoverflow.com/a/17788551, with changes to use `cl-letf'
233 ;; instead of the now obsolete `flet'.
234 (defun b/compilation-finish-function (buffer outstr)
235 (unless (string-match "finished" outstr)
236 (switch-to-buffer-other-window buffer))
237 t)
238
239 (setq compilation-finish-functions #'b/compilation-finish-function)
240
241 (require 'cl-macs)
242
243 (defadvice compilation-start
244 (around inhibit-display
245 (command &optional mode name-function highlight-regexp))
246 (if (not (string-match "^\\(find\\|grep\\)" command))
247 (cl-letf (((symbol-function 'display-buffer) #'ignore))
248 (save-window-excursion ad-do-it))
249 ad-do-it))
250 (ad-activate 'compilation-start))
251
252(with-eval-after-load 'isearch
253 (setq
254 ;; Allow scrolling in Isearch.
255 isearch-allow-scroll t
256 isearch-lazy-count t
257 ;; Search for non-ASCII characters: i’d like non-ASCII characters
258 ;; such as ‘’“”«»‹›áⓐ𝒶 to be selected when I search for their ASCII
259 ;; counterpart. Shoutout to
260 ;; http://endlessparentheses.com/new-in-emacs-25-1-easily-search-non-ascii-characters.html
261 search-default-mode #'char-fold-to-regexp))
262
263;; (with-eval-after-load 'replace
264;; ;; Uncomment to extend the above behaviour to query-replace.
265;; (setq replace-char-fold t))
266
267;; `vc'
268(global-set-key (kbd "C-x v C-=") #'vc-ediff)
269
270(with-eval-after-load 'vc-git
271 (setq vc-git-print-log-follow t
272 vc-git-show-stash 0))
273
274(with-eval-after-load 'ediff
275 (setq ediff-window-setup-function 'ediff-setup-windows-plain
276 ediff-split-window-function 'split-window-horizontally)
277 (add-hook 'ediff-after-quit-hook-internal #'winner-undo))
278
279(with-eval-after-load 'face-remap
280 (setq
281 ;; Gentler font resizing.
282 text-scale-mode-step 1.05))
283
284(run-with-idle-timer 0.4 nil #'require 'mwheel)
285(with-eval-after-load 'mwheel
286 (setq
287 mouse-wheel-scroll-amount '(1 ((shift) . 1)) ; one line at a time
288 mouse-wheel-progressive-speed nil ; don't accelerate scrolling
289 mouse-wheel-follow-mouse t)) ; scroll window under mouse
290
291(run-with-idle-timer 0.4 nil #'require 'pixel-scroll)
292(with-eval-after-load 'pixel-scroll
293 (pixel-scroll-mode 1))
294
295(with-eval-after-load 'epg-config
296 (setq
297 epg-gpg-program (executable-find "gpg")
298 ;; Ask for GPG passphrase in minibuffer.
299 ;; Will fail if gpg >= 2.1 is not available.
300 epg-pinentry-mode 'loopback))
301
302(with-eval-after-load 'auth-source
303 (setq
304 auth-sources '("~/.authinfo.gpg")
305 authinfo-hidden
306 (regexp-opt '("password" "client-secret" "token"))))
307
308(with-eval-after-load 'info
309 (setq
310 Info-directory-list
311 `(,@Info-directory-list
312 ,(expand-file-name
313 (convert-standard-filename "info/") source-directory)
314 "/usr/share/info/")))
315
316(when (display-graphic-p)
317 (with-eval-after-load 'faces
318 (let ((grey "#e7e7e7"))
319 (set-face-attribute 'fixed-pitch nil :family "Source Code Pro")
320 (set-face-attribute 'mode-line nil
321 :background grey
322 :inherit 'fixed-pitch))))
323
324(when (version< emacs-version "28")
325 ;; Manually make some `mode-line' spaces smaller. Emacs 28 (and
326 ;; above) does a terrific job at this out of the box when
327 ;; `mode-line-compact' is set to t (see above)."
328 (setq-default
329 mode-line-format
330 (mapcar
331 (lambda (x)
332 (if (and (stringp x)
333 (or (string= x " ")
334 (string= x " ")))
335 " "
336 x))
337 mode-line-format)
338 mode-line-buffer-identification
339 (propertized-buffer-identification "%10b")))
340
341\f
342;;; Useful utilities
343
344(defun b/add-elisp-section ()
345 (interactive)
346 (insert "\n")
347 (forward-line -1)
348 (insert "\n\f\n;;; "))
349
350(defun b/insert-asterism ()
351 "Insert a centred asterism."
352 (interactive)
353 (let ((asterism "* * *"))
354 (insert
355 (concat
356 "\n"
357 (make-string
358 (floor (/ (- fill-column (length asterism)) 2))
359 ?\s)
360 asterism
361 "\n"))))
362
363(defun b/start-process (program &rest args)
364 "Same as `start-process', but doesn't bother about name and buffer."
365 (let ((process-name (concat program "_process"))
366 (buffer-name (generate-new-buffer-name
367 (concat program "_output"))))
368 (apply #'start-process
369 process-name buffer-name program args)))
370
371(defun b/no-mouse-autoselect-window ()
372 "Conveniently disable `focus-follows-mouse'.
373For disabling the behaviour for certain buffers and/or modes."
374 (make-local-variable 'mouse-autoselect-window)
375 (setq mouse-autoselect-window nil))
376
377(defun b/move-indentation-or-beginning-of-line (arg)
378 "Move to the indentation or to the beginning of line."
379 (interactive "^p")
380 ;; (if (bolp)
381 ;; (back-to-indentation)
382 ;; (move-beginning-of-line arg))
383 (if (= (point)
384 (progn (back-to-indentation)
385 (point)))
386 (move-beginning-of-line arg)))
387
388(defun b/join-line-top ()
389 "Like `join-line', but join next line to the current line."
390 (interactive)
391 (join-line 1))
392
393(defun b/*scratch* ()
394 "Switch to `*scratch*' buffer, creating it if it does not
395 exist."
396 (interactive)
397 (let ((fun (if (functionp #'get-scratch-buffer-create)
398 #'get-scratch-buffer-create ; (version<= "29" emacs-version)
399 #'startup--get-buffer-create-scratch))) ; (version< emacs-version "29")
400 (switch-to-buffer (funcall fun))))
401
402(defun b/duplicate-line-or-region (&optional n)
403 "Duplicate the current line, or region (if active).
404Make N (default: 1) copies of the current line or region."
405 (interactive "*p")
406 (let ((u-r-p (use-region-p)) ; if region is active
407 (n1 (or n 1)))
408 (save-excursion
409 (let ((text
410 (if u-r-p
411 (buffer-substring (region-beginning) (region-end))
412 (prog1 (thing-at-point 'line)
413 (end-of-line)
414 (if (eobp)
415 (newline)
416 (forward-line 1))))))
417 (dotimes (_ (abs n1))
418 (insert text))))))
419
420(defun b/invert-default-face ()
421 "Invert the `default' face (swap its background and foreground).
422Effectively a very simple light/dark theme toggle switch."
423 (interactive)
424 (invert-face 'default (selected-frame))
425 (invert-face 'mode-line (selected-frame)))
426
427(defun b/export-frame ()
428 (interactive)
429 ;; TODO: ask for fn and/or take as arg
430 (let* ((fn (make-temp-file "emacs" nil ".pdf"))
431 (data (x-export-frames nil 'pdf)))
432 (with-temp-file fn
433 (insert data))
434 (kill-new fn)
435 (message fn)))
436
437\f
438;;; General key bindings
439
440(global-set-key (kbd "C-a") #'b/move-indentation-or-beginning-of-line)
441(global-set-key (kbd "C-c i") #'ielm)
442(global-set-key (kbd "C-c d") #'b/duplicate-line-or-region)
443(global-set-key (kbd "C-c j") #'b/join-line-top)
444(global-set-key (kbd "C-S-j") #'b/join-line-top)
445(global-set-key (kbd "C-c s c") #'b/*scratch*)
446(global-set-key (kbd "C-c x") #'execute-extended-command)
447(global-set-key (kbd "C-c v") #'b/invert-default-face)
448
449;; evaling and macro-expanding
450(global-set-key (kbd "C-c e b") #'eval-buffer)
451(global-set-key (kbd "C-c e e") #'eval-last-sexp)
452(global-set-key (kbd "C-c e m") #'pp-macroexpand-last-sexp)
453(global-set-key (kbd "C-c e r") #'eval-region)
454
455;; emacs things
456(global-set-key (kbd "C-c e i") #'emacs-init-time)
457(global-set-key (kbd "C-c e u") #'emacs-uptime)
458(global-set-key (kbd "C-c e v") #'emacs-version)
459
460;; finding
461(global-set-key (kbd "C-c f .") #'find-file)
462(global-set-key (kbd "C-c f d") #'find-name-dired)
463(global-set-key (kbd "C-c f l") #'find-library)
464(global-set-key (kbd "C-c f p") #'find-file-at-point)
465
466;; frames
467(global-set-key (kbd "C-c F m") #'make-frame-command)
468(global-set-key (kbd "C-c F d") #'delete-frame)
469
470;; help/describe
471(global-set-key (kbd "C-S-h F") #'describe-face)
472
473(define-key emacs-lisp-mode-map (kbd "C-<return>") #'b/add-elisp-section)
474
475(when (display-graphic-p)
476 (global-unset-key (kbd "C-z")))
477
478\f
479;;; Essential packages
480
481(add-to-list
482 'load-path
483 (expand-file-name
484 (convert-standard-filename "lisp") user-emacs-directory))
485
486;; (require 'bandali-exwm)
487
488(require 'bandali-org)
489
490;; (require 'bandali-theme)
491
492;; recently opened files
493(run-with-idle-timer 0.2 nil #'require 'recentf)
494(with-eval-after-load 'recentf
495 (setq
496 recentf-max-saved-items 2000
497 recentf-save-file (b/var "recentf-save.el"))
498 ;; (add-to-list 'recentf-keep #'file-remote-p)
499 (recentf-mode)
500
501 (defun b/recentf-open ()
502 "Use `completing-read' to \\[find-file] a recent file."
503 (interactive)
504 (find-file
505 (completing-read "Find recent file: " recentf-list)))
506 (global-set-key (kbd "C-c f r") #'b/recentf-open))
507
508;; (define-key minibuffer-local-completion-map
509;; "\t" #'minibuffer-force-complete)
510
511;; (with-eval-after-load 'icomplete
512
513;; (setq icomplete-on-del-error-function #'abort-recursive-edit)
514
515;; (defun b/icomplete-fido-backward-updir ()
516;; "Delete char before or go up directory, like `ido-mode'."
517;; (interactive)
518;; (if (and (eq (char-before) ?/)
519;; (eq (icomplete--category) 'file))
520;; (save-excursion
521;; (goto-char (1- (point)))
522;; (when (search-backward "/" (point-min) t)
523;; (delete-region (1+ (point)) (point-max))))
524;; (condition-case nil
525;; (call-interactively #'delete-backward-char)
526;; (error
527;; (when icomplete-on-del-error-function
528;; (funcall icomplete-on-del-error-function))))))
529
530;; (define-key icomplete-fido-mode-map
531;; (kbd "DEL") #'b/icomplete-fido-backward-updir))
532
533;; (fido-mode 1)
534;; (defun b/icomplete--fido-mode-setup ()
535;; "Customizations to `fido-mode''s minibuffer."
536;; (when (and icomplete-mode (icomplete-simple-completing-p))
537;; (setq-local
538;; ;; icomplete-compute-delay 0.1
539;; ;; icomplete-hide-common-prefix t
540;; icomplete-separator " · "
541;; completion-styles '(basic substring partial-completion flex))))
542;; (add-hook 'minibuffer-setup-hook #'b/icomplete--fido-mode-setup 1)
543
544(require 'bandali-eshell)
545
546(require 'bandali-ibuffer)
547
548(require 'bandali-dired)
549
550(with-eval-after-load 'help
551 (temp-buffer-resize-mode)
552 (setq help-window-select t))
553
554(with-eval-after-load 'help-mode
555 (define-key help-mode-map (kbd "p") #'backward-button)
556 (define-key help-mode-map (kbd "n") #'forward-button))
557
558(with-eval-after-load 'tramp
559 (setq tramp-auto-save-directory (b/var "tramp/auto-save/")
560 tramp-persistency-file-name (b/var "tramp/persistency.el"))
561 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
562 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
563 (add-to-list 'tramp-default-proxies-alist
564 (list (regexp-quote (system-name)) nil nil)))
565
566(with-eval-after-load 'doc-view
567 (define-key doc-view-mode-map (kbd "M-RET") #'image-previous-line))
568
569(setq shr-max-width 80)
570
571;; Email (with Gnus, message, and smtpmail)
572(require 'bandali-gnus)
573(require 'bandali-message)
574;; (with-eval-after-load 'smtpmail
575;; (setq smtpmail-queue-mail t
576;; smtpmail-queue-dir (concat b/maildir "queue/")))
577
578;; IRC (with ERC)
579(require 'bandali-erc)
580
581;; 'paste' service (aka scp + web server)
582(add-to-list 'load-path (b/lisp "scpaste"))
583(with-eval-after-load 'scpaste
584 (setq scpaste-http-destination "https://p.bndl.org"
585 scpaste-scp-destination "p:~"))
586(autoload 'scpaste "scpaste" nil t)
587(autoload 'scpaste-region "scpaste" nil t)
588(global-set-key (kbd "C-c p p") #'scpaste)
589(global-set-key (kbd "C-c p r") #'scpaste-region)
590
591\f
592;;; Editing
593
594(when (featurep 'eldoc)
595 ;; Display Lisp objects at point in the echo area.
596 (with-eval-after-load 'eldoc
597 (setq eldoc-minor-mode-string " eldoc")
598 (global-eldoc-mode)))
599
600;; highlight matching parens
601(run-with-idle-timer 0.2 nil #'require 'paren)
602(with-eval-after-load 'paren
603 (show-paren-mode))
604
605;; (run-with-idle-timer 0.2 nil #'require 'elec-pair)
606;; (with-eval-after-load 'elec-pair
607;; (electric-pair-mode))
608
609(with-eval-after-load 'simple
610 (setq
611 ;; Save what I copy into clipboard from other applications into Emacs'
612 ;; kill-ring, which would allow me to still be able to easily access
613 ;; it in case I kill (cut or copy) something else inside Emacs before
614 ;; yanking (pasting) what I'd originally intended to.
615 save-interprogram-paste-before-kill t)
616 (column-number-mode 1)
617 (line-number-mode 1))
618
619(run-with-idle-timer 0.2 nil #'require 'savehist)
620(with-eval-after-load 'savehist
621 ;; Save minibuffer history.
622 (setq savehist-file (b/var "savehist.el"))
623 (savehist-mode)
624 (add-to-list 'savehist-additional-variables 'kill-ring))
625
626;; Automatically save place in files.
627(run-with-idle-timer 0.2 nil #'require 'saveplace nil 'noerror)
628(with-eval-after-load 'saveplace
629 (setq save-place-file (b/var "save-place.el"))
630 (save-place-mode))
631
632(with-eval-after-load 'prog-mode
633 (global-prettify-symbols-mode))
634
635(add-to-list 'auto-mode-alist '("\\.*rc$" . conf-mode))
636(add-to-list 'auto-mode-alist '("\\.bashrc$" . sh-mode))
637
638(with-eval-after-load 'flyspell
639 (setq flyspell-mode-line-string " fly"))
640
641(with-eval-after-load 'text-mode
642 (add-hook 'text-mode-hook #'flyspell-mode)
643 (define-key text-mode-map (kbd "C-<return>") #'b/insert-asterism))
644
645;; ;; http://endlessparentheses.com/ispell-and-apostrophes.html
646;; (run-with-idle-timer 0.6 nil #'require 'ispell)
647;; (with-eval-after-load 'ispell
648;; ;; ’ can be part of a word.
649;; (setq ispell-local-dictionary-alist
650;; `((nil "[[:alpha:]]" "[^[:alpha:]]"
651;; "['\x2019]" nil ("-B") nil utf-8))
652;; ispell-program-name (executable-find "hunspell"))
653;; ;; Don't send ’ to the subprocess.
654;; (defun endless/replace-apostrophe (args)
655;; (cons (replace-regexp-in-string
656;; "’" "'" (car args))
657;; (cdr args)))
658;; (advice-add #'ispell-send-string :filter-args
659;; #'endless/replace-apostrophe)
660;; ;; Convert ' back to ’ from the subprocess.
661;; (defun endless/replace-quote (args)
662;; (if (not (derived-mode-p 'org-mode))
663;; args
664;; (cons (replace-regexp-in-string
665;; "'" "’" (car args))
666;; (cdr args))))
667;; (advice-add #'ispell-parse-output :filter-args
668;; #'endless/replace-quote))
669
670(with-eval-after-load 'abbrev
671 (setq abbrev-file-name (b/etc "abbrev.el")))
672(add-hook 'text-mode-hook #'abbrev-mode)
673
674\f
675;;; Programming modes
676
677(with-eval-after-load 'lisp-mode
678 (defun indent-spaces-mode ()
679 (setq indent-tabs-mode nil))
680 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
681
682(add-to-list 'load-path (b/lisp "alloy-mode"))
683(autoload 'alloy-mode "alloy-mode" nil t)
684(with-eval-after-load 'alloy-mode
685 (setq alloy-basic-offset 2)
686 ;; (defun b/alloy-simple-indent (start end)
687 ;; (interactive "r")
688 ;; ;; (if (region-active-p)
689 ;; ;; (indent-rigidly start end alloy-basic-offset)
690 ;; ;; (if (bolp)
691 ;; ;; (indent-rigidly (line-beginning-position)
692 ;; ;; (line-end-position)
693 ;; ;; alloy-basic-offset)))
694 ;; (indent-to (+ (current-column) alloy-basic-offset)))
695 (define-key alloy-mode-map (kbd "RET") #'electric-newline-and-maybe-indent)
696 ;; (define-key alloy-mode-map (kbd "TAB") #'b/alloy-simple-indent)
697 (define-key alloy-mode-map (kbd "TAB") #'indent-for-tab-command))
698(add-to-list 'auto-mode-alist '("\\.\\(als\\|dsh\\)\\'" . alloy-mode))
699(add-hook 'alloy-mode-hook (lambda nil (setq-local indent-tabs-mode nil)))
700
701;; (eval-when-compile (defvar lean-mode-map))
702;; (run-with-idle-timer 0.4 nil #'require 'lean-mode)
703;; (with-eval-after-load 'lean-mode
704;; (require 'lean-input)
705;; (setq default-input-method "Lean"
706;; lean-input-tweak-all '(lean-input-compose
707;; (lean-input-prepend "/")
708;; (lean-input-nonempty))
709;; lean-input-user-translations '(("/" "/")))
710;; (lean-input-setup)
711;; ;; local key bindings
712;; (define-key lean-mode-map (kbd "S-SPC") #'company-complete))
713
714(with-eval-after-load 'sgml-mode
715 (setq sgml-basic-offset 0))
716
717(with-eval-after-load 'css-mode
718 (setq css-indent-offset 2))
719
720;; (with-eval-after-load 'auctex
721;; (setq font-latex-fontify-sectioning 'color))
722
723(with-eval-after-load 'tex-mode
724 (cl-delete-if
725 (lambda (p) (string-match "^---?" (car p)))
726 tex--prettify-symbols-alist))
727(add-hook 'tex-mode-hook #'auto-fill-mode)
728(add-hook 'tex-mode-hook #'flyspell-mode)
729
730(run-with-idle-timer 0.5 nil #'require 'cmake-mode)
731(with-eval-after-load 'cmake-mode
732 ;; (setq cmake-tab-width 4)
733 (add-to-list 'load-path (b/lisp "cmake-font-lock"))
734 (run-with-idle-timer 0.5 nil #'require 'cmake-font-lock))
735
736\f
737;;; Emacs enhancements & auxiliary packages
738
739(with-eval-after-load 'nsm
740 (setq nsm-settings-file (b/var "nsm-settings.el")))
741
742(with-eval-after-load 'man
743 (setq Man-width 80))
744
745;; ,----
746;; | make pretty boxed quotes like this
747;; `----
748(run-with-idle-timer 0.6 nil #'require 'boxquote)
749(with-eval-after-load 'boxquote
750 (defvar b/boxquote-prefix-map)
751 (define-prefix-command 'b/boxquote-prefix-map)
752 (global-set-key (kbd "C-c q") 'b/boxquote-prefix-map)
753 (define-key b/boxquote-prefix-map (kbd "b") #'boxquote-buffer)
754 (define-key b/boxquote-prefix-map (kbd "B") #'boxquote-insert-buffer)
755 (define-key b/boxquote-prefix-map (kbd "d") #'boxquote-defun)
756 (define-key b/boxquote-prefix-map (kbd "F") #'boxquote-insert-file)
757 (define-key b/boxquote-prefix-map (kbd "hf") #'boxquote-describe-function)
758 (define-key b/boxquote-prefix-map (kbd "hk") #'boxquote-describe-key)
759 (define-key b/boxquote-prefix-map (kbd "hv") #'boxquote-describe-variable)
760 (define-key b/boxquote-prefix-map (kbd "hw") #'boxquote-where-is)
761 (define-key b/boxquote-prefix-map (kbd "k") #'boxquote-kill)
762 (define-key b/boxquote-prefix-map (kbd "p") #'boxquote-paragraph)
763 (define-key b/boxquote-prefix-map (kbd "q") #'boxquote-boxquote)
764 (define-key b/boxquote-prefix-map (kbd "r") #'boxquote-region)
765 (define-key b/boxquote-prefix-map (kbd "s") #'boxquote-shell-command)
766 (define-key b/boxquote-prefix-map (kbd "t") #'boxquote-text)
767 (define-key b/boxquote-prefix-map (kbd "T") #'boxquote-title)
768 (define-key b/boxquote-prefix-map (kbd "u") #'boxquote-unbox)
769 (define-key b/boxquote-prefix-map (kbd "U") #'boxquote-unbox-region)
770 (define-key b/boxquote-prefix-map (kbd "y") #'boxquote-yank)
771 (define-key b/boxquote-prefix-map (kbd "M-q") #'boxquote-fill-paragraph)
772 (define-key b/boxquote-prefix-map (kbd "M-w") #'boxquote-kill-ring-save))
773
774(add-to-list 'load-path (b/lisp "hl-todo"))
775(run-with-idle-timer 0.5 nil #'require 'hl-todo)
776(with-eval-after-load 'hl-todo
777 ;; Highlight TODO in buffers.
778 (global-hl-todo-mode))
779
780;; `debbugs'
781(global-set-key (kbd "C-c D d") #'debbugs-gnu)
782(global-set-key (kbd "C-c D b") #'debbugs-gnu-bugs)
783(global-set-key (kbd "C-c D e") ; bug-gnu-emacs
784 (lambda ()
785 (interactive)
786 (setq debbugs-gnu-current-suppress t)
787 (debbugs-gnu debbugs-gnu-default-severities
788 '("emacs"))))
789(global-set-key (kbd "C-c D g") ; bug-gnuzilla
790 (lambda ()
791 (interactive)
792 (setq debbugs-gnu-current-suppress t)
793 (debbugs-gnu debbugs-gnu-default-severities
794 '("gnuzilla"))))
795
796(with-eval-after-load 'url
797 (setq url-configuration-directory (b/var "url/configuration/")))
798
799(with-eval-after-load 'url-cache
800 (setq url-cache-directory (b/var "url/cache/")))
801
802(with-eval-after-load 'eww
803 (setq
804 eww-download-directory
805 (file-name-as-directory (getenv "XDG_DOWNLOAD_DIR"))))
806(global-set-key (kbd "C-c e w") #'eww)
807
808;; (with-eval-after-load 'org-ref
809;; (setq
810;; reftex-default-bibliography '("~/usr/org/references.bib")
811;; org-ref-default-bibliography '("~/usr/org/references.bib")
812;; org-ref-bibliography-notes "~/usr/org/notes.org"
813;; org-ref-pdf-directory "~/usr/org/bibtex-pdfs/"))
814
815(run-with-idle-timer
816 0.2 nil #'require 'display-fill-column-indicator nil 'noerror)
817(with-eval-after-load 'display-fill-column-indicator
818 (global-display-fill-column-indicator-mode 1))
819
820(with-eval-after-load 'window
821 (setq split-width-threshold 150)
822 (global-set-key (kbd "C-c w s l")
823 (lambda ()
824 (interactive)
825 (split-window-right)
826 (other-window 1)))
827 (global-set-key (kbd "C-c w s j")
828 (lambda ()
829 (interactive)
830 (split-window-below)
831 (other-window 1)))
832 (global-set-key (kbd "C-c w q") #'quit-window))
833
834;; Uncomment to disable reftex-cite's default choice of previous word.
835;; (with-eval-after-load 'reftex
836;; (require 'reftex-cite)
837;; (defun reftex-get-bibkey-default ()
838;; "If the cursor is in a citation macro, return the word before
839;; the macro."
840;; (let* ((macro (reftex-what-macro 1)))
841;; (save-excursion
842;; (when (and macro (string-match "cite" (car macro)))
843;; (goto-char (cdr macro)))
844;; (reftex-this-word)))))
845(add-hook 'latex-mode-hook #'reftex-mode)
846
847(add-to-list 'load-path (b/lisp "dmenu"))
848(with-eval-after-load 'dmenu
849 (setq dmenu-prompt-string "run: "
850 dmenu-save-file (b/var "dmenu-items")))
851(autoload 'dmenu "dmenu" nil t)
852
853(run-with-idle-timer 0.5 nil #'require 'delight)
854(with-eval-after-load 'delight
855 (delight 'auto-fill-function " f" "simple")
856 (delight 'abbrev-mode "" "abbrev")
857 (delight 'mml-mode " mml" "mml"))
858
859(require 'bandali-po)
860
861(with-eval-after-load 'emms
862 (setq emms-directory (b/var "emms")))
863
864(add-to-list 'load-path (b/lisp "ffs"))
865(run-with-idle-timer 0.5 nil #'require 'ffs)
866(with-eval-after-load 'ffs
867 (global-set-key (kbd "C-c f s") #'ffs))
868
869;;; init.el ends here