e23653b3853a96de765b4cc7434850236976ced5
[~bandali/configs] / .emacs.d / init.el
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-frame-font "Source Code Pro-10.5:weight=medium" nil t)
150 ;; (set-frame-font "FreeSans" nil t)
151 (set-fontset-font t 'arabic "Vazir"))
152
153 ;;;; Elisp-level customizations
154
155 (with-eval-after-load 'minibuffer
156 (setq read-file-name-completion-ignore-case t))
157
158 ;; `startup'
159 (setq auto-save-list-file-prefix (b/var "auto-save/sessions/"))
160
161 (with-eval-after-load 'files
162 (setq
163 ;; backups (C-h v make-backup-files RET)
164 backup-by-copying t
165 backup-directory-alist (list (cons "." (b/var "backup/")))
166 version-control t
167 delete-old-versions t
168 ;; auto-save
169 auto-save-file-name-transforms `((".*" ,(b/var "auto-save/") t))
170 ;; insert newline at the end of files
171 ;; require-final-newline t
172 ;; open read-only file buffers in view-mode
173 ;; (enables niceties like `q' for quit)
174 view-read-only t))
175
176 ;; `novice'
177 (setq disabled-command-function nil)
178
179 ;; `subr'
180 ;; (keyboard-translate ?\( ?\[)
181 ;; (keyboard-translate ?\) ?\])
182 ;; (keyboard-translate ?\[ ?\()
183 ;; (keyboard-translate ?\] ?\))
184
185 (run-with-idle-timer 0.1 nil #'require 'autorevert)
186 (with-eval-after-load 'autorevert
187 (setq
188 ;; auto-revert-verbose nil
189 global-auto-revert-non-file-buffers nil)
190 (global-auto-revert-mode 1))
191
192 (run-with-idle-timer 0.1 nil #'require 'time)
193 (with-eval-after-load 'time
194 (setq
195 display-time-default-load-average nil
196 display-time-format " %a %b %-e %-l:%M%P"
197 display-time-mail-icon '(image :type xpm
198 :file "gnus/gnus-pointer.xpm"
199 :ascent center)
200 display-time-use-mail-icon t
201 zoneinfo-style-world-list
202 `(,@zoneinfo-style-world-list
203 ("Etc/UTC" "UTC")
204 ("Asia/Tehran" "Tehran")
205 ("Australia/Melbourne" "Melbourne")))
206 (display-time-mode))
207
208 (run-with-idle-timer 0.1 nil #'require 'battery)
209 (with-eval-after-load 'battery
210 (setq battery-mode-line-format " %p%% %t")
211 (display-battery-mode))
212
213 ;; (with-eval-after-load 'fringe
214 ;; ;; smaller fringe
215 ;; (fringe-mode '(3 . 1)))
216
217 (run-with-idle-timer 0.5 nil #'require 'winner)
218 (with-eval-after-load 'winner
219 (winner-mode 1))
220
221 (run-with-idle-timer 0.5 nil #'require 'windmove)
222 (with-eval-after-load 'windmove
223 (setq windmove-wrap-around t)
224 (global-set-key (kbd "M-H") #'windmove-left)
225 (global-set-key (kbd "M-L") #'windmove-right)
226 (global-set-key (kbd "M-K") #'windmove-up)
227 (global-set-key (kbd "M-J") #'windmove-down))
228
229 (with-eval-after-load 'compile
230 ;; don't display *compilation* buffer on success. based on
231 ;; https://stackoverflow.com/a/17788551, with changes to use `cl-letf'
232 ;; instead of the now obsolete `flet'.
233 (defun b/compilation-finish-function (buffer outstr)
234 (unless (string-match "finished" outstr)
235 (switch-to-buffer-other-window buffer))
236 t)
237
238 (setq compilation-finish-functions #'b/compilation-finish-function)
239
240 (require 'cl-macs)
241
242 (defadvice compilation-start
243 (around inhibit-display
244 (command &optional mode name-function highlight-regexp))
245 (if (not (string-match "^\\(find\\|grep\\)" command))
246 (cl-letf (((symbol-function 'display-buffer) #'ignore))
247 (save-window-excursion ad-do-it))
248 ad-do-it))
249 (ad-activate 'compilation-start))
250
251 (with-eval-after-load 'isearch
252 (setq
253 ;; Allow scrolling in Isearch.
254 isearch-allow-scroll t
255 isearch-lazy-count t
256 ;; Search for non-ASCII characters: i’d like non-ASCII characters
257 ;; such as ‘’“”«»‹›áⓐ𝒶 to be selected when I search for their ASCII
258 ;; counterpart. Shoutout to
259 ;; http://endlessparentheses.com/new-in-emacs-25-1-easily-search-non-ascii-characters.html
260 search-default-mode #'char-fold-to-regexp))
261
262 ;; (with-eval-after-load 'replace
263 ;; ;; Uncomment to extend the above behaviour to query-replace.
264 ;; (setq replace-char-fold t))
265
266 ;; `vc'
267 (global-set-key (kbd "C-x v C-=") #'vc-ediff)
268
269 (with-eval-after-load 'vc-git
270 (setq vc-git-print-log-follow t
271 vc-git-show-stash 0))
272
273 (with-eval-after-load 'ediff
274 (setq ediff-window-setup-function 'ediff-setup-windows-plain
275 ediff-split-window-function 'split-window-horizontally))
276
277 (with-eval-after-load 'face-remap
278 (setq
279 ;; Gentler font resizing.
280 text-scale-mode-step 1.05))
281
282 (run-with-idle-timer 0.4 nil #'require 'mwheel)
283 (with-eval-after-load 'mwheel
284 (setq
285 mouse-wheel-scroll-amount '(1 ((shift) . 1)) ; one line at a time
286 mouse-wheel-progressive-speed nil ; don't accelerate scrolling
287 mouse-wheel-follow-mouse t)) ; scroll window under mouse
288
289 (run-with-idle-timer 0.4 nil #'require 'pixel-scroll)
290 (with-eval-after-load 'pixel-scroll
291 (pixel-scroll-mode 1))
292
293 (with-eval-after-load 'epg-config
294 (setq
295 epg-gpg-program (executable-find "gpg")
296 ;; Ask for GPG passphrase in minibuffer.
297 ;; Will fail if gpg >= 2.1 is not available.
298 epg-pinentry-mode 'loopback))
299
300 (with-eval-after-load 'auth-source
301 (setq
302 auth-sources '("~/.authinfo.gpg")
303 authinfo-hidden
304 (regexp-opt '("password" "client-secret" "token"))))
305
306 (with-eval-after-load 'info
307 (setq
308 Info-directory-list
309 `(,@Info-directory-list
310 ,(expand-file-name
311 (convert-standard-filename "info/") source-directory)
312 "/usr/share/info/")))
313
314 (when (display-graphic-p)
315 (with-eval-after-load 'faces
316 (let ((grey "#e7e7e7"))
317 (set-face-attribute 'fixed-pitch nil
318 :font "Source Code Pro"
319 :weight 'medium)
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'.
373 For 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).
404 Make 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 (arg)
421 "Invert the `default' and `mode-line' faces for the current frame.
422 Swap the background and foreground for the two `default' and
423 `mode-line' faces, effectively acting like a simple light/dark
424 theme toggle. If prefix argument ARG is given, invert the faces
425 for all frames."
426 (interactive "P")
427 (let ((frame (unless arg
428 (selected-frame))))
429 (invert-face 'default frame)
430 (invert-face 'mode-line frame))
431 (when (fboundp #'exwm-systemtray--refresh-background-color)
432 (exwm-systemtray--refresh-background-color 'remap)))
433
434 (defun b/export-frame ()
435 (interactive)
436 ;; TODO: ask for fn and/or take as arg
437 (let* ((fn (make-temp-file "emacs" nil ".pdf"))
438 (data (x-export-frames nil 'pdf)))
439 (with-temp-file fn
440 (insert data))
441 (kill-new fn)
442 (message fn)))
443
444 \f
445 ;;; General key bindings
446
447 ;; (global-set-key (kbd "C-a") #'b/move-indentation-or-beginning-of-line)
448 (global-set-key (kbd "C-c i") #'ielm)
449 (global-set-key (kbd "C-c d") #'b/duplicate-line-or-region)
450 (global-set-key (kbd "C-c j") #'b/join-line-top)
451 (global-set-key (kbd "C-S-j") #'b/join-line-top)
452 (global-set-key (kbd "C-c s c") #'b/*scratch*)
453 (global-set-key (kbd "C-c x") #'execute-extended-command)
454 (global-set-key (kbd "C-c v") #'b/invert-default-face)
455
456 ;; evaling and macro-expanding
457 (global-set-key (kbd "C-c e b") #'eval-buffer)
458 (global-set-key (kbd "C-c e e") #'eval-last-sexp)
459 (global-set-key (kbd "C-c e m") #'pp-macroexpand-last-sexp)
460 (global-set-key (kbd "C-c e r") #'eval-region)
461
462 ;; emacs things
463 (global-set-key (kbd "C-c e i") #'emacs-init-time)
464 (global-set-key (kbd "C-c e u") #'emacs-uptime)
465 (global-set-key (kbd "C-c e v") #'emacs-version)
466
467 ;; finding
468 (global-set-key (kbd "C-c f .") #'find-file)
469 (global-set-key (kbd "C-c f d") #'find-name-dired)
470 (global-set-key (kbd "C-c f l") #'find-library)
471 (global-set-key (kbd "C-c f p") #'find-file-at-point)
472
473 ;; frames
474 (global-set-key (kbd "C-c F m") #'make-frame-command)
475 (global-set-key (kbd "C-c F d") #'delete-frame)
476
477 ;; help/describe
478 (global-set-key (kbd "C-S-h F") #'describe-face)
479
480 (define-key emacs-lisp-mode-map (kbd "C-<return>") #'b/add-elisp-section)
481
482 (when (display-graphic-p)
483 (global-unset-key (kbd "C-z")))
484
485 \f
486 ;;; Essential packages
487
488 (add-to-list
489 'load-path
490 (expand-file-name
491 (convert-standard-filename "lisp") user-emacs-directory))
492
493 (when
494 (and
495 (display-graphic-p)
496 ;; we're not running in another WM/DE
497 (not (getenv "XDG_CURRENT_DESKTOP"))
498 (member (system-name) '("chaman" "langa")))
499 (require 'bandali-exwm)
500 (global-set-key (kbd "C-x b") #'exwm-workspace-switch-to-buffer))
501
502 (require 'bandali-org)
503
504 ;; (require 'bandali-theme)
505
506 ;; recently opened files
507 (run-with-idle-timer 0.2 nil #'require 'recentf)
508 (with-eval-after-load 'recentf
509 (setq
510 recentf-max-saved-items 2000
511 recentf-save-file (b/var "recentf-save.el"))
512 ;; (add-to-list 'recentf-keep #'file-remote-p)
513 (recentf-mode)
514
515 (defun b/recentf-open ()
516 "Use `completing-read' to \\[find-file] a recent file."
517 (interactive)
518 (find-file
519 (completing-read "Find recent file: " recentf-list)))
520 (global-set-key (kbd "C-c f r") #'b/recentf-open))
521
522 ;; (define-key minibuffer-local-completion-map
523 ;; "\t" #'minibuffer-force-complete)
524
525 ;; (with-eval-after-load 'icomplete
526
527 ;; (setq icomplete-on-del-error-function #'abort-recursive-edit)
528
529 ;; (defun b/icomplete-fido-backward-updir ()
530 ;; "Delete char before or go up directory, like `ido-mode'."
531 ;; (interactive)
532 ;; (if (and (eq (char-before) ?/)
533 ;; (eq (icomplete--category) 'file))
534 ;; (save-excursion
535 ;; (goto-char (1- (point)))
536 ;; (when (search-backward "/" (point-min) t)
537 ;; (delete-region (1+ (point)) (point-max))))
538 ;; (condition-case nil
539 ;; (call-interactively #'delete-backward-char)
540 ;; (error
541 ;; (when icomplete-on-del-error-function
542 ;; (funcall icomplete-on-del-error-function))))))
543
544 ;; (define-key icomplete-fido-mode-map
545 ;; (kbd "DEL") #'b/icomplete-fido-backward-updir))
546
547 ;; (fido-mode 1)
548 ;; (defun b/icomplete--fido-mode-setup ()
549 ;; "Customizations to `fido-mode''s minibuffer."
550 ;; (when (and icomplete-mode (icomplete-simple-completing-p))
551 ;; (setq-local
552 ;; ;; icomplete-compute-delay 0.1
553 ;; ;; icomplete-hide-common-prefix t
554 ;; icomplete-separator " · "
555 ;; completion-styles '(basic substring partial-completion flex))))
556 ;; (add-hook 'minibuffer-setup-hook #'b/icomplete--fido-mode-setup 1)
557
558 (require 'bandali-eshell)
559
560 (require 'bandali-ibuffer)
561
562 (require 'bandali-dired)
563
564 (with-eval-after-load 'help
565 (temp-buffer-resize-mode)
566 (setq help-window-select t))
567
568 (with-eval-after-load 'help-mode
569 (define-key help-mode-map (kbd "p") #'backward-button)
570 (define-key help-mode-map (kbd "n") #'forward-button))
571
572 (with-eval-after-load 'tramp
573 (setq tramp-auto-save-directory (b/var "tramp/auto-save/")
574 tramp-persistency-file-name (b/var "tramp/persistency.el"))
575 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
576 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
577 (add-to-list 'tramp-default-proxies-alist
578 (list (regexp-quote (system-name)) nil nil)))
579
580 (with-eval-after-load 'doc-view
581 (define-key doc-view-mode-map (kbd "M-RET") #'image-previous-line))
582
583 (setq shr-max-width 80)
584
585 ;; Email (with Gnus, message, and smtpmail)
586 (require 'bandali-gnus)
587 (require 'bandali-message)
588 ;; (with-eval-after-load 'smtpmail
589 ;; (setq smtpmail-queue-mail t
590 ;; smtpmail-queue-dir (concat b/maildir "queue/")))
591
592 ;; IRC (with ERC)
593 (require 'bandali-erc)
594
595 ;; 'paste' service (aka scp + web server)
596 (add-to-list 'load-path (b/lisp "scpaste"))
597 (with-eval-after-load 'scpaste
598 (setq scpaste-http-destination "https://p.bndl.org"
599 scpaste-scp-destination "p:~"))
600 (autoload 'scpaste "scpaste" nil t)
601 (autoload 'scpaste-region "scpaste" nil t)
602 (global-set-key (kbd "C-c p p") #'scpaste)
603 (global-set-key (kbd "C-c p r") #'scpaste-region)
604
605 \f
606 ;;; Editing
607
608 (when (featurep 'eldoc)
609 ;; Display Lisp objects at point in the echo area.
610 (with-eval-after-load 'eldoc
611 (setq eldoc-minor-mode-string " eldoc")
612 (global-eldoc-mode)))
613
614 ;; highlight matching parens
615 (run-with-idle-timer 0.2 nil #'require 'paren)
616 (with-eval-after-load 'paren
617 (show-paren-mode))
618
619 ;; (run-with-idle-timer 0.2 nil #'require 'elec-pair)
620 ;; (with-eval-after-load 'elec-pair
621 ;; (electric-pair-mode))
622
623 (with-eval-after-load 'simple
624 (setq
625 ;; Save what I copy into clipboard from other applications into Emacs'
626 ;; kill-ring, which would allow me to still be able to easily access
627 ;; it in case I kill (cut or copy) something else inside Emacs before
628 ;; yanking (pasting) what I'd originally intended to.
629 save-interprogram-paste-before-kill t)
630 (column-number-mode 1)
631 (line-number-mode 1))
632
633 (run-with-idle-timer 0.2 nil #'require 'savehist)
634 (with-eval-after-load 'savehist
635 ;; Save minibuffer history.
636 (setq savehist-file (b/var "savehist.el"))
637 (savehist-mode)
638 (add-to-list 'savehist-additional-variables 'kill-ring))
639
640 ;; Automatically save place in files.
641 (run-with-idle-timer 0.2 nil #'require 'saveplace nil 'noerror)
642 (with-eval-after-load 'saveplace
643 (setq save-place-file (b/var "save-place.el"))
644 (save-place-mode))
645
646 (with-eval-after-load 'prog-mode
647 (global-prettify-symbols-mode))
648
649 (add-to-list 'auto-mode-alist '("\\.*rc$" . conf-mode))
650 (add-to-list 'auto-mode-alist '("\\.bashrc$" . sh-mode))
651
652 (with-eval-after-load 'flyspell
653 (setq flyspell-mode-line-string " fly"))
654
655 (with-eval-after-load 'text-mode
656 (add-hook 'text-mode-hook #'flyspell-mode)
657 (define-key text-mode-map (kbd "C-<return>") #'b/insert-asterism))
658
659 ;; ;; http://endlessparentheses.com/ispell-and-apostrophes.html
660 ;; (run-with-idle-timer 0.6 nil #'require 'ispell)
661 ;; (with-eval-after-load 'ispell
662 ;; ;; ’ can be part of a word.
663 ;; (setq ispell-local-dictionary-alist
664 ;; `((nil "[[:alpha:]]" "[^[:alpha:]]"
665 ;; "['\x2019]" nil ("-B") nil utf-8))
666 ;; ispell-program-name (executable-find "hunspell"))
667 ;; ;; Don't send ’ to the subprocess.
668 ;; (defun endless/replace-apostrophe (args)
669 ;; (cons (replace-regexp-in-string
670 ;; "’" "'" (car args))
671 ;; (cdr args)))
672 ;; (advice-add #'ispell-send-string :filter-args
673 ;; #'endless/replace-apostrophe)
674 ;; ;; Convert ' back to ’ from the subprocess.
675 ;; (defun endless/replace-quote (args)
676 ;; (if (not (derived-mode-p 'org-mode))
677 ;; args
678 ;; (cons (replace-regexp-in-string
679 ;; "'" "’" (car args))
680 ;; (cdr args))))
681 ;; (advice-add #'ispell-parse-output :filter-args
682 ;; #'endless/replace-quote))
683
684 (with-eval-after-load 'abbrev
685 (setq abbrev-file-name (b/etc "abbrev.el")))
686 (add-hook 'text-mode-hook #'abbrev-mode)
687
688 \f
689 ;;; Programming modes
690
691 (with-eval-after-load 'lisp-mode
692 (defun indent-spaces-mode ()
693 (setq indent-tabs-mode nil))
694 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
695
696 (add-to-list 'load-path (b/lisp "alloy-mode"))
697 (autoload 'alloy-mode "alloy-mode" nil t)
698 (with-eval-after-load 'alloy-mode
699 (setq alloy-basic-offset 2)
700 ;; (defun b/alloy-simple-indent (start end)
701 ;; (interactive "r")
702 ;; ;; (if (region-active-p)
703 ;; ;; (indent-rigidly start end alloy-basic-offset)
704 ;; ;; (if (bolp)
705 ;; ;; (indent-rigidly (line-beginning-position)
706 ;; ;; (line-end-position)
707 ;; ;; alloy-basic-offset)))
708 ;; (indent-to (+ (current-column) alloy-basic-offset)))
709 (define-key alloy-mode-map (kbd "RET") #'electric-newline-and-maybe-indent)
710 ;; (define-key alloy-mode-map (kbd "TAB") #'b/alloy-simple-indent)
711 (define-key alloy-mode-map (kbd "TAB") #'indent-for-tab-command))
712 (add-to-list 'auto-mode-alist '("\\.\\(als\\|dsh\\)\\'" . alloy-mode))
713 (add-hook 'alloy-mode-hook (lambda nil (setq-local indent-tabs-mode nil)))
714
715 ;; (eval-when-compile (defvar lean-mode-map))
716 ;; (run-with-idle-timer 0.4 nil #'require 'lean-mode)
717 ;; (with-eval-after-load 'lean-mode
718 ;; (require 'lean-input)
719 ;; (setq default-input-method "Lean"
720 ;; lean-input-tweak-all '(lean-input-compose
721 ;; (lean-input-prepend "/")
722 ;; (lean-input-nonempty))
723 ;; lean-input-user-translations '(("/" "/")))
724 ;; (lean-input-setup)
725 ;; ;; local key bindings
726 ;; (define-key lean-mode-map (kbd "S-SPC") #'company-complete))
727
728 (with-eval-after-load 'sgml-mode
729 (setq sgml-basic-offset 0))
730
731 (with-eval-after-load 'css-mode
732 (setq css-indent-offset 2))
733
734 ;; (with-eval-after-load 'auctex
735 ;; (setq font-latex-fontify-sectioning 'color))
736
737 (with-eval-after-load 'tex-mode
738 (cl-delete-if
739 (lambda (p) (string-match "^---?" (car p)))
740 tex--prettify-symbols-alist))
741 (add-hook 'tex-mode-hook #'auto-fill-mode)
742 (add-hook 'tex-mode-hook #'flyspell-mode)
743
744 (run-with-idle-timer 0.5 nil #'require 'cmake-mode)
745 (with-eval-after-load 'cmake-mode
746 ;; (setq cmake-tab-width 4)
747 (add-to-list 'load-path (b/lisp "cmake-font-lock"))
748 (run-with-idle-timer 0.5 nil #'require 'cmake-font-lock))
749
750 \f
751 ;;; Emacs enhancements & auxiliary packages
752
753 (with-eval-after-load 'nsm
754 (setq nsm-settings-file (b/var "nsm-settings.el")))
755
756 (with-eval-after-load 'man
757 (setq Man-width 80))
758
759 ;; ,----
760 ;; | make pretty boxed quotes like this
761 ;; `----
762 (run-with-idle-timer 0.6 nil #'require 'boxquote)
763 (with-eval-after-load 'boxquote
764 (defvar b/boxquote-prefix-map)
765 (define-prefix-command 'b/boxquote-prefix-map)
766 (global-set-key (kbd "C-c q") 'b/boxquote-prefix-map)
767 (define-key b/boxquote-prefix-map (kbd "b") #'boxquote-buffer)
768 (define-key b/boxquote-prefix-map (kbd "B") #'boxquote-insert-buffer)
769 (define-key b/boxquote-prefix-map (kbd "d") #'boxquote-defun)
770 (define-key b/boxquote-prefix-map (kbd "F") #'boxquote-insert-file)
771 (define-key b/boxquote-prefix-map (kbd "hf") #'boxquote-describe-function)
772 (define-key b/boxquote-prefix-map (kbd "hk") #'boxquote-describe-key)
773 (define-key b/boxquote-prefix-map (kbd "hv") #'boxquote-describe-variable)
774 (define-key b/boxquote-prefix-map (kbd "hw") #'boxquote-where-is)
775 (define-key b/boxquote-prefix-map (kbd "k") #'boxquote-kill)
776 (define-key b/boxquote-prefix-map (kbd "p") #'boxquote-paragraph)
777 (define-key b/boxquote-prefix-map (kbd "q") #'boxquote-boxquote)
778 (define-key b/boxquote-prefix-map (kbd "r") #'boxquote-region)
779 (define-key b/boxquote-prefix-map (kbd "s") #'boxquote-shell-command)
780 (define-key b/boxquote-prefix-map (kbd "t") #'boxquote-text)
781 (define-key b/boxquote-prefix-map (kbd "T") #'boxquote-title)
782 (define-key b/boxquote-prefix-map (kbd "u") #'boxquote-unbox)
783 (define-key b/boxquote-prefix-map (kbd "U") #'boxquote-unbox-region)
784 (define-key b/boxquote-prefix-map (kbd "y") #'boxquote-yank)
785 (define-key b/boxquote-prefix-map (kbd "M-q") #'boxquote-fill-paragraph)
786 (define-key b/boxquote-prefix-map (kbd "M-w") #'boxquote-kill-ring-save))
787
788 ;; `debbugs'
789 (global-set-key (kbd "C-c D d") #'debbugs-gnu)
790 (global-set-key (kbd "C-c D b") #'debbugs-gnu-bugs)
791 (global-set-key (kbd "C-c D e") ; bug-gnu-emacs
792 (lambda ()
793 (interactive)
794 (setq debbugs-gnu-current-suppress t)
795 (debbugs-gnu debbugs-gnu-default-severities
796 '("emacs"))))
797 (global-set-key (kbd "C-c D g") ; bug-gnuzilla
798 (lambda ()
799 (interactive)
800 (setq debbugs-gnu-current-suppress t)
801 (debbugs-gnu debbugs-gnu-default-severities
802 '("gnuzilla"))))
803
804 (with-eval-after-load 'url
805 (setq url-configuration-directory (b/var "url/configuration/")))
806
807 (with-eval-after-load 'url-cache
808 (setq url-cache-directory (b/var "url/cache/")))
809
810 (with-eval-after-load 'eww
811 (setq
812 eww-download-directory
813 (file-name-as-directory (getenv "XDG_DOWNLOAD_DIR"))))
814 (global-set-key (kbd "C-c e w") #'eww)
815
816 ;; (with-eval-after-load 'org-ref
817 ;; (setq
818 ;; reftex-default-bibliography '("~/usr/org/references.bib")
819 ;; org-ref-default-bibliography '("~/usr/org/references.bib")
820 ;; org-ref-bibliography-notes "~/usr/org/notes.org"
821 ;; org-ref-pdf-directory "~/usr/org/bibtex-pdfs/"))
822
823 (run-with-idle-timer
824 0.2 nil #'require 'display-fill-column-indicator nil 'noerror)
825 (with-eval-after-load 'display-fill-column-indicator
826 (global-display-fill-column-indicator-mode 1))
827
828 (with-eval-after-load 'window
829 (setq split-width-threshold 150)
830 (global-set-key (kbd "C-c w s l")
831 (lambda ()
832 (interactive)
833 (split-window-right)
834 (other-window 1)))
835 (global-set-key (kbd "C-c w s j")
836 (lambda ()
837 (interactive)
838 (split-window-below)
839 (other-window 1)))
840 (global-set-key (kbd "C-c w q") #'quit-window))
841
842 ;; Uncomment to disable reftex-cite's default choice of previous word.
843 ;; (with-eval-after-load 'reftex
844 ;; (require 'reftex-cite)
845 ;; (defun reftex-get-bibkey-default ()
846 ;; "If the cursor is in a citation macro, return the word before
847 ;; the macro."
848 ;; (let* ((macro (reftex-what-macro 1)))
849 ;; (save-excursion
850 ;; (when (and macro (string-match "cite" (car macro)))
851 ;; (goto-char (cdr macro)))
852 ;; (reftex-this-word)))))
853 (add-hook 'latex-mode-hook #'reftex-mode)
854
855 (add-to-list 'load-path (b/lisp "dmenu"))
856 (with-eval-after-load 'dmenu
857 (setq dmenu-prompt-string "run: "
858 dmenu-save-file (b/var "dmenu-items")))
859 (autoload 'dmenu "dmenu" nil t)
860
861 (run-with-idle-timer 0.5 nil #'require 'delight)
862 (with-eval-after-load 'delight
863 (delight 'auto-fill-function " f" "simple")
864 (delight 'abbrev-mode "" "abbrev")
865 (delight 'mml-mode " mml" "mml"))
866
867 (require 'bandali-po)
868
869 (with-eval-after-load 'emms
870 (setq emms-directory (b/var "emms")))
871
872 (add-to-list 'load-path (b/lisp "ffs"))
873 (run-with-idle-timer 0.5 nil #'require 'ffs)
874 (with-eval-after-load 'ffs
875 (global-set-key (kbd "C-c f s") #'ffs))
876
877 ;;; init.el ends here