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