1 ;;; init.el --- bandali's emacs configuration -*- lexical-binding: t -*-
3 ;; Copyright (C) 2018-2022 Amin Bandali <bandali@gnu.org>
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.
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.
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/>.
20 ;; GNU Emacs configuration of bandali, free software activist,
21 ;; computing scientist, and GNU maintainer and volunteer.
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:
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
37 ;;; Emacs initialization
39 (defvar b
/before-user-init-time
(current-time)
40 "Value of `current-time' when Emacs begins loading `user-init-file'.")
41 (defvar b
/emacs-initialized nil
42 "Whether Emacs has been initialized.")
44 (when (not (bound-and-true-p b
/emacs-initialized
))
45 (message "Loading Emacs...done (%.3fs)"
46 (float-time (time-subtract b
/before-user-init-time
49 ;; temporarily increase `gc-cons-threshhold' and `gc-cons-percentage'
50 ;; during startup to reduce garbage collection frequency. clearing
51 ;; `file-name-handler-alist' seems to help reduce startup time too.
52 (defvar b
/gc-cons-threshold gc-cons-threshold
)
53 (defvar b
/gc-cons-percentage gc-cons-percentage
)
54 (defvar b
/file-name-handler-alist file-name-handler-alist
)
55 (setq gc-cons-threshold
(* 30 1024 1024) ; 30 MiB
56 gc-cons-percentage
0.6
57 file-name-handler-alist nil
58 ;; sidesteps a bug when profiling with esup
59 esup-child-profile-require-level
0)
61 ;; set them back to their defaults once we're done initializing
63 "My post-initialize function, run after loading `user-init-file'."
64 (setq b
/emacs-initialized t
65 gc-cons-threshold b
/gc-cons-threshold
66 gc-cons-percentage b
/gc-cons-percentage
67 file-name-handler-alist b
/file-name-handler-alist
)
68 (when (featurep 'exwm-workspace
)
69 (with-eval-after-load 'exwm-workspace
76 "[%s]" (number-to-string
77 exwm-workspace-current-index
))))))))
78 (when (version< emacs-version
"28")
79 ;; manually make some mode-line spaces smaller
80 ;; (version<= "28" emacs-version) can do an awesome job at this
81 ;; out of the box if `mode-line-compact' is set to t (see below)
92 mode-line-buffer-identification
93 (propertized-buffer-identification "%10b"))))
94 (add-hook 'after-init-hook
#'b
/post-init
)
96 ;; increase number of lines kept in *Messages* log
97 (setq message-log-max
20000)
102 (setq user-full-name
"Amin Bandali"
103 user-mail-address
"bandali@gnu.org")
106 ;;; Package management
108 ;; variables of interest:
109 ;; package-archive-priorities
111 ;; package-pinned-packages
113 ;; (let* ((b (find-file-noselect "refinery-theme.el"))
114 ;; (d (with-current-buffer b (package-buffer-info))))
115 ;; (package-generate-description-file d "refinery-theme-pkg.el"))
116 (run-with-idle-timer 0.01 nil
#'require
'package
)
117 (with-eval-after-load 'package
119 ;; ;; package-archives
120 ;; ;; `(,@package-archives
121 ;; ;; ("bndl" . "https://p.bndl.org/elpa/"))
127 ;; (expand-region "0.11.0")
128 ;; (rt-liberation "2.4")
129 ;; (yasnippet "0.14.0")))
130 (package-initialize))
132 (setq package-archive-upload-base
"/ssh:caffeine:~/www/p/elpa")
137 ;; keep ~/.emacs.d clean
140 (convert-standard-filename "etc/") user-emacs-directory
)
141 "The directory where packages place their configuration files.")
144 (convert-standard-filename "var/") user-emacs-directory
)
145 "The directory where packages place their persistent data files.")
148 (convert-standard-filename "lisp/") user-emacs-directory
)
149 "The directory where packages place their persistent data files.")
151 "Expand filename FILE relative to `b/etc-dir'."
152 (expand-file-name (convert-standard-filename file
) b
/etc-dir
))
154 "Expand filename FILE relative to `b/var-dir'."
155 (expand-file-name (convert-standard-filename file
) b
/var-dir
))
157 "Expand filename FILE relative to `b/lisp-dir'."
158 (expand-file-name (convert-standard-filename file
) b
/lisp-dir
))
161 auto-save-list-file-prefix
(b/var
"auto-save/sessions/")
162 nsm-settings-file
(b/var
"nsm-settings.el"))
164 ;; separate custom file (don't want it mixing with init.el)
165 (with-eval-after-load 'custom
166 (setq custom-file
(b/etc
"custom.el"))
167 (when (file-exists-p custom-file
)
169 ;; while at it, treat themes as safe
170 ;; (setf custom-safe-themes t)
171 ;; only one custom theme at a time
172 ;; (defadvice load-theme (before clear-previous-themes activate)
173 ;; "Clear existing theme settings instead of layering them"
174 ;; (mapc #'disable-theme custom-enabled-themes))
177 ;; load the secrets file if it exists, otherwise show a warning
178 ;; (with-demoted-errors
179 ;; (load (b/etc "secrets")))
181 ;; start up emacs server. see
182 ;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server
183 (run-with-idle-timer 0.5 nil
#'require
'server
)
184 (with-eval-after-load 'server
185 (declare-function server-edit
"server")
186 (global-set-key (kbd "C-c F D") #'server-edit
)
187 (declare-function server-running-p
"server")
188 (or (server-running-p) (server-mode)))
193 ;;;; C-level customizations
197 completion-ignore-case t
198 read-buffer-completion-ignore-case t
199 enable-recursive-minibuffers t
200 resize-mini-windows t
202 ;; mouse-autoselect-window t
203 scroll-conservatively
101
204 scroll-preserve-screen-position
1
205 ;; i don't feel like jumping out of my chair every now and again;
206 ;; so...don't *BEEP* at me, emacs =)
207 ring-bell-function
'ignore
)
210 ;; case-sensitive search (and `dabbrev-expand')
211 ;; case-fold-search nil
212 ;; always use space for indentation
216 (when (display-graphic-p)
217 (set-fontset-font t
'arabic
"Vazir"))
218 ;; ;; (set-frame-font "Drafting Mono-14:weight=light" nil t)
219 ;; (set-frame-font "Drafting Mono:pixelsize=16" nil t)
220 ;; (set-face-attribute 'bold nil :weight 'semi-bold)
222 ;;;; Elisp-level customizations
224 ;; (define-key minibuffer-local-completion-map
225 ;; "\t" #'minibuffer-force-complete)
227 ;; (with-eval-after-load 'icomplete
229 ;; (setq icomplete-on-del-error-function #'abort-recursive-edit)
231 ;; (defun b/icomplete-fido-backward-updir ()
232 ;; "Delete char before or go up directory, like `ido-mode'."
234 ;; (if (and (eq (char-before) ?/)
235 ;; (eq (icomplete--category) 'file))
237 ;; (goto-char (1- (point)))
238 ;; (when (search-backward "/" (point-min) t)
239 ;; (delete-region (1+ (point)) (point-max))))
240 ;; (condition-case nil
241 ;; (call-interactively #'delete-backward-char)
243 ;; (when icomplete-on-del-error-function
244 ;; (funcall icomplete-on-del-error-function))))))
246 ;; (define-key icomplete-fido-mode-map
247 ;; (kbd "DEL") #'b/icomplete-fido-backward-updir))
250 ;; (keyboard-translate ?\( ?\[)
251 ;; (keyboard-translate ?\) ?\])
252 ;; (keyboard-translate ?\[ ?\()
253 ;; (keyboard-translate ?\] ?\))
256 (setq read-file-name-completion-ignore-case t
)
259 ;; don't need to see the startup echo area message
260 (advice-add #'display-startup-echo-area-message
:override
#'ignore
)
262 ;; i want *scratch* as my startup buffer
263 initial-buffer-choice t
264 ;; i don't need the default hint
265 initial-scratch-message nil
266 ;; use customizable text-mode as major mode for *scratch*
267 ;; (initial-major-mode 'text-mode)
268 ;; inhibit buffer list when more than 2 files are loaded
269 inhibit-startup-buffer-menu t
270 ;; don't need to see the startup screen or echo area message
271 inhibit-startup-screen t
272 inhibit-startup-echo-area-message user-login-name
)
276 ;; backups (C-h v make-backup-files RET)
278 backup-directory-alist
(list (cons "." (b/var
"backup/")))
280 delete-old-versions t
282 auto-save-file-name-transforms
`((".*" ,(b/var
"auto-save/") t
))
283 ;; insert newline at the end of files
284 ;; require-final-newline t
285 ;; open read-only file buffers in view-mode
286 ;; (enables niceties like `q' for quit)
290 ;; disable disabled commands
291 (setq disabled-command-function nil
)
293 ;; lazy-person-friendly yes/no prompts
294 (defalias 'yes-or-no-p
#'y-or-n-p
)
296 ;; autorevert: enable automatic reloading of changed buffers and files
298 ;; auto-revert-verbose nil
299 global-auto-revert-non-file-buffers nil
)
300 (require 'autorevert
)
301 (global-auto-revert-mode 1)
303 ;; time and battery in mode-line
304 (run-with-idle-timer 0.1 nil
#'require
'time
)
305 (with-eval-after-load 'time
307 display-time-default-load-average nil
308 display-time-format
" %a %b %-e %-l:%M%P"
309 display-time-mail-icon
'(image :type xpm
310 :file
"gnus/gnus-pointer.xpm"
312 display-time-use-mail-icon t
313 zoneinfo-style-world-list
314 `(,@zoneinfo-style-world-list
316 ("Asia/Tehran" "Tehran")
317 ("Australia/Melbourne" "Melbourne")))
320 (run-with-idle-timer 0.1 nil
#'require
'battery
)
321 (with-eval-after-load 'battery
322 (setq battery-mode-line-format
" %p%% %t")
323 (display-battery-mode))
325 ;; (with-eval-after-load 'fringe
327 ;; (fringe-mode '(3 . 1)))
329 ;; enable winner-mode (C-h f winner-mode RET)
333 (run-with-idle-timer 0.1 nil
#'require
'windmove
)
334 (with-eval-after-load 'windmove
335 (setq windmove-wrap-around t
)
336 (global-set-key (kbd "M-H") #'windmove-left
)
337 (global-set-key (kbd "M-L") #'windmove-right
)
338 (global-set-key (kbd "M-K") #'windmove-up
)
339 (global-set-key (kbd "M-J") #'windmove-down
))
341 (with-eval-after-load 'compile
342 ;; don't display *compilation* buffer on success. based on
343 ;; https://stackoverflow.com/a/17788551, with changes to use `cl-letf'
344 ;; instead of the now obsolete `flet'.
345 (defun b/compilation-finish-function
(buffer outstr
)
346 (unless (string-match "finished" outstr
)
347 (switch-to-buffer-other-window buffer
))
350 (setq compilation-finish-functions
#'b
/compilation-finish-function
)
354 (defadvice compilation-start
355 (around inhibit-display
356 (command &optional mode name-function highlight-regexp
))
357 (if (not (string-match "^\\(find\\|grep\\)" command
))
358 (cl-letf (((symbol-function 'display-buffer
) #'ignore
))
359 (save-window-excursion ad-do-it
))
361 (ad-activate 'compilation-start
))
365 ;; allow scrolling in Isearch
366 isearch-allow-scroll t
368 ;; search for non-ASCII characters: i’d like non-ASCII characters such
369 ;; as ‘’“”«»‹›áⓐ𝒶 to be selected when i search for their ASCII
370 ;; counterpart. shoutout to
371 ;; http://endlessparentheses.com/new-in-emacs-25-1-easily-search-non-ascii-characters.html
372 search-default-mode
#'char-fold-to-regexp
)
375 ;; uncomment to extend the above behaviour to query-replace
376 ;; (setq replace-char-fold t)
379 (global-set-key (kbd "C-x v C-=") #'vc-ediff
)
381 (with-eval-after-load 'vc-git
382 (setq vc-git-print-log-follow t
383 vc-git-show-stash
0))
385 (setq ediff-window-setup-function
'ediff-setup-windows-plain
386 ediff-split-window-function
'split-window-horizontally
)
387 (with-eval-after-load 'ediff
388 (add-hook 'ediff-after-quit-hook-internal
#'winner-undo
))
392 ;; gentler font resizing
393 text-scale-mode-step
1.05)
395 (run-with-idle-timer 0.4 nil
#'require
'mwheel
)
396 (setq mouse-wheel-scroll-amount
'(1 ((shift) .
1)) ; one line at a time
397 mouse-wheel-progressive-speed nil
; don't accelerate scrolling
398 mouse-wheel-follow-mouse t
) ; scroll window under mouse
400 (run-with-idle-timer 0.4 nil
#'require
'pixel-scroll
)
401 (with-eval-after-load 'pixel-scroll
402 (pixel-scroll-mode 1))
406 epg-gpg-program
(executable-find "gpg")
407 ;; ask for GPG passphrase in minibuffer
408 ;; this will fail if gpg>=2.1 is not available
409 epg-pinentry-mode
'loopback
)
413 auth-sources
'("~/.authinfo.gpg")
414 authinfo-hidden
(regexp-opt '("password" "client-secret" "token")))
417 (with-eval-after-load 'info
420 `(,@Info-directory-list
422 (convert-standard-filename "info/") source-directory
)
423 "/usr/share/info/")))
426 (when (display-graphic-p)
427 (with-eval-after-load 'faces
428 (let ((grey "#e7e7e7"))
429 (set-face-attribute 'fixed-pitch nil
:family
"Source Code Pro")
430 (set-face-attribute 'mode-line nil
432 :inherit
'fixed-pitch
))))
437 (defun b/add-elisp-section
()
441 (insert "\n\f\n;;; "))
443 (defun b/insert-asterism
()
444 "Insert a centred asterism."
446 (let ((asterism "* * *"))
451 (floor (/ (- fill-column
(length asterism
)) 2))
456 (defun b/start-process
(program &rest args
)
457 "Same as `start-process', but doesn't bother about name and buffer."
458 (let ((process-name (concat program
"_process"))
459 (buffer-name (generate-new-buffer-name
460 (concat program
"_output"))))
461 (apply #'start-process
462 process-name buffer-name program args
)))
464 (defun b/no-mouse-autoselect-window
()
465 "Conveniently disable `focus-follows-mouse'.
466 For disabling the behaviour for certain buffers and/or modes."
467 (make-local-variable 'mouse-autoselect-window
)
468 (setq mouse-autoselect-window nil
))
470 (defun b/kill-current-buffer
()
471 "Kill the current buffer."
472 ;; also see https://redd.it/64xb3q
474 (kill-buffer (current-buffer)))
476 (defun b/move-indentation-or-beginning-of-line
(arg)
477 "Move to the indentation or to the beginning of line."
480 ;; (back-to-indentation)
481 ;; (move-beginning-of-line arg))
483 (progn (back-to-indentation)
485 (move-beginning-of-line arg
)))
487 (defun b/join-line-top
()
488 "Like `join-line', but join next line to the current line."
492 (defun b/duplicate-line-or-region
(&optional n
)
493 "Duplicate the current line, or region (if active).
494 Make N (default: 1) copies of the current line or region."
496 (let ((u-r-p (use-region-p)) ; if region is active
501 (buffer-substring (region-beginning) (region-end))
502 (prog1 (thing-at-point 'line
)
506 (forward-line 1))))))
507 (dotimes (_ (abs n1
))
510 (defun b/invert-default-face
()
511 "Invert the `default' face (swap its background and foreground).
512 Effectively a very simple light/dark theme toggle switch."
514 (invert-face 'default
)
515 (when (display-graphic-p)
516 (invert-face 'mode-line
)))
519 ;;; General key bindings
521 (global-set-key (kbd "C-a") #'b
/move-indentation-or-beginning-of-line
)
522 (global-set-key (kbd "C-c a i") #'ielm
)
523 (global-set-key (kbd "C-c d") #'b
/duplicate-line-or-region
)
524 (global-set-key (kbd "C-c j") #'b
/join-line-top
)
525 (global-set-key (kbd "C-S-j") #'b
/join-line-top
)
526 (global-set-key (kbd "C-c x") #'execute-extended-command
)
527 (global-set-key (kbd "C-c v") #'b
/invert-default-face
)
529 ;; evaling and macro-expanding
530 (global-set-key (kbd "C-c e b") #'eval-buffer
)
531 (global-set-key (kbd "C-c e e") #'eval-last-sexp
)
532 (global-set-key (kbd "C-c e m") #'pp-macroexpand-last-sexp
)
533 (global-set-key (kbd "C-c e r") #'eval-region
)
536 (global-set-key (kbd "C-c e i") #'emacs-init-time
)
537 (global-set-key (kbd "C-c e u") #'emacs-uptime
)
538 (global-set-key (kbd "C-c e v") #'emacs-version
)
541 (global-set-key (kbd "C-c f .") #'find-file
)
542 (global-set-key (kbd "C-c f d") #'find-name-dired
)
543 (global-set-key (kbd "C-c f l") #'find-library
)
544 (global-set-key (kbd "C-c f p") #'find-file-at-point
)
547 (global-set-key (kbd "C-c F m") #'make-frame-command
)
548 (global-set-key (kbd "C-c F d") #'delete-frame
)
551 (global-set-key (kbd "C-S-h F") #'describe-face
)
553 ;; (global-set-key (kbd "C-x k") #'b/kill-current-buffer)
554 ;; (global-set-key (kbd "C-x K") #'kill-buffer)
556 (define-key emacs-lisp-mode-map
(kbd "C-<return>") #'b
/add-elisp-section
)
558 (when (display-graphic-p)
559 (global-unset-key (kbd "C-z")))
562 ;;; Essential packages
567 (convert-standard-filename "lisp") user-emacs-directory
))
569 ;; (require 'bandali-exwm)
571 (require 'bandali-org
)
573 ;; (require 'bandali-theme)
575 ;; recently opened files
576 (setq recentf-max-saved-items
2000
577 recentf-save-file
(b/var
"recentf-save.el"))
578 (run-with-idle-timer 0.2 nil
#'require
'recentf
)
579 (with-eval-after-load 'recentf
580 ;; (add-to-list 'recentf-keep #'file-remote-p)
583 (defun b/recentf-open
()
584 "Use `completing-read' to \\[find-file] a recent file."
587 (completing-read "Find recent file: " recentf-list
)))
588 (global-set-key (kbd "C-c f r") #'b
/recentf-open
))
591 ;; (defun b/icomplete--fido-mode-setup ()
592 ;; "Customizations to `fido-mode''s minibuffer."
593 ;; (when (and icomplete-mode (icomplete-simple-completing-p))
595 ;; ;; icomplete-compute-delay 0.1
596 ;; ;; icomplete-hide-common-prefix t
597 ;; icomplete-separator " · "
598 ;; completion-styles '(basic substring partial-completion flex))))
599 ;; (add-hook 'minibuffer-setup-hook #'b/icomplete--fido-mode-setup 1)
601 (require 'bandali-eshell
)
603 (require 'bandali-ibuffer
)
605 (require 'bandali-dired
)
607 (with-eval-after-load 'help
608 (temp-buffer-resize-mode)
609 (setq help-window-select t
))
611 (with-eval-after-load 'help-mode
612 ;; local key bindings
613 (define-key help-mode-map
(kbd "p") #'backward-button
)
614 (define-key help-mode-map
(kbd "n") #'forward-button
))
616 (with-eval-after-load 'tramp
617 (setq tramp-auto-save-directory
(b/var
"tramp/auto-save/")
618 tramp-persistency-file-name
(b/var
"tramp/persistency.el"))
619 (add-to-list 'tramp-default-proxies-alist
'(nil "\\`root\\'" "/ssh:%h:"))
620 (add-to-list 'tramp-default-proxies-alist
'("localhost" nil nil
))
621 (add-to-list 'tramp-default-proxies-alist
622 (list (regexp-quote (system-name)) nil nil
)))
624 (with-eval-after-load 'doc-view
625 (define-key doc-view-mode-map
(kbd "M-RET") #'image-previous-line
))
627 (setq shr-max-width
80)
629 ;; Email (with Gnus, message, and smtpmail)
630 (require 'bandali-gnus
)
631 (require 'bandali-message
)
632 ;; (with-eval-after-load 'smtpmail
633 ;; (setq smtpmail-queue-mail t
634 ;; smtpmail-queue-dir (concat b/maildir "queue/")))
637 (require 'bandali-erc
)
639 ;; 'paste' service (aka scp + web server)
640 (add-to-list 'load-path
(b/lisp
"scpaste"))
641 (with-eval-after-load 'scpaste
642 (setq scpaste-http-destination
"https://p.bndl.org"
643 scpaste-scp-destination
"p:~"))
644 (autoload 'scpaste
"scpaste" nil t
)
645 (autoload 'scpaste-region
"scpaste" nil t
)
646 (global-set-key (kbd "C-c a p p") #'scpaste
)
647 (global-set-key (kbd "C-c a p r") #'scpaste-region
)
652 ;; display Lisp objects at point in the echo area
653 (when (version< "25" emacs-version
)
654 (with-eval-after-load 'eldoc
655 (setq eldoc-minor-mode-string
" eldoc")
656 (global-eldoc-mode)))
658 ;; highlight matching parens
662 ;; (require 'elec-pair)
663 ;; (electric-pair-mode)
666 ;; Save what I copy into clipboard from other applications into Emacs'
667 ;; kill-ring, which would allow me to still be able to easily access
668 ;; it in case I kill (cut or copy) something else inside Emacs before
669 ;; yanking (pasting) what I'd originally intended to.
670 save-interprogram-paste-before-kill t
)
671 (with-eval-after-load 'simple
672 (column-number-mode 1)
673 (line-number-mode 1))
675 ;; save minibuffer history
677 (setq savehist-file
(b/var
"savehist.el"))
679 (add-to-list 'savehist-additional-variables
'kill-ring
)
681 ;; automatically save place in files
682 (when (version< "25" emacs-version
)
683 (setq save-place-file
(b/var
"save-place.el"))
686 (defun indicate-buffer-boundaries-left ()
687 (setq indicate-buffer-boundaries
'left
))
688 (with-eval-after-load 'prog-mode
689 (global-prettify-symbols-mode))
690 (add-hook 'prog-mode-hook
#'indicate-buffer-boundaries-left
)
692 (define-key text-mode-map
(kbd "C-<return>") #'b
/insert-asterism
)
693 (add-hook 'text-mode-hook
#'indicate-buffer-boundaries-left
)
694 (add-hook 'text-mode-hook
#'flyspell-mode
)
696 (add-to-list 'auto-mode-alist
'("\\.*rc$" . conf-mode
))
698 (add-to-list 'auto-mode-alist
'("\\.bashrc$" . sh-mode
))
700 (with-eval-after-load 'flyspell
701 (setq flyspell-mode-line-string
" fly"))
704 ;; http://endlessparentheses.com/ispell-and-apostrophes.html
705 ;; (run-with-idle-timer 0.6 nil #'require 'ispell)
706 ;; (with-eval-after-load 'ispell
707 ;; ;; ’ can be part of a word
708 ;; (setq ispell-local-dictionary-alist
709 ;; `((nil "[[:alpha:]]" "[^[:alpha:]]"
710 ;; "['\x2019]" nil ("-B") nil utf-8))
711 ;; ispell-program-name (executable-find "hunspell"))
712 ;; ;; don't send ’ to the subprocess
713 ;; (defun endless/replace-apostrophe (args)
714 ;; (cons (replace-regexp-in-string
715 ;; "’" "'" (car args))
717 ;; (advice-add #'ispell-send-string :filter-args
718 ;; #'endless/replace-apostrophe)
719 ;; ;; convert ' back to ’ from the subprocess
720 ;; (defun endless/replace-quote (args)
721 ;; (if (not (derived-mode-p 'org-mode))
723 ;; (cons (replace-regexp-in-string
724 ;; "'" "’" (car args))
726 ;; (advice-add #'ispell-parse-output :filter-args
727 ;; #'endless/replace-quote))
730 (setq abbrev-file-name
(b/etc
"abbrev.el"))
731 (add-hook 'text-mode-hook
#'abbrev-mode
)
734 ;;; Programming modes
736 (with-eval-after-load 'lisp-mode
737 (defun indent-spaces-mode ()
738 (setq indent-tabs-mode nil
))
739 (add-hook 'lisp-interaction-mode-hook
#'indent-spaces-mode
))
742 (add-to-list 'load-path
(b/lisp
"alloy-mode"))
743 (autoload 'alloy-mode
"alloy-mode" nil t
)
744 (with-eval-after-load 'alloy-mode
745 (setq alloy-basic-offset
2)
746 ;; (defun b/alloy-simple-indent (start end)
748 ;; ;; (if (region-active-p)
749 ;; ;; (indent-rigidly start end alloy-basic-offset)
751 ;; ;; (indent-rigidly (line-beginning-position)
752 ;; ;; (line-end-position)
753 ;; ;; alloy-basic-offset)))
754 ;; (indent-to (+ (current-column) alloy-basic-offset)))
755 ;; local key bindings
756 (define-key alloy-mode-map
(kbd "RET") #'electric-newline-and-maybe-indent
)
757 ;; (define-key alloy-mode-map (kbd "TAB") #'b/alloy-simple-indent)
758 (define-key alloy-mode-map
(kbd "TAB") #'indent-for-tab-command
))
759 (add-to-list 'auto-mode-alist
'("\\.\\(als\\|dsh\\)\\'" . alloy-mode
))
760 (add-hook 'alloy-mode-hook
(lambda nil
(setq-local indent-tabs-mode nil
)))
763 ;; (eval-when-compile (defvar lean-mode-map))
764 ;; (run-with-idle-timer 0.4 nil #'require 'lean-mode)
765 ;; (with-eval-after-load 'lean-mode
766 ;; (require 'lean-input)
767 ;; (setq default-input-method "Lean"
768 ;; lean-input-tweak-all '(lean-input-compose
769 ;; (lean-input-prepend "/")
770 ;; (lean-input-nonempty))
771 ;; lean-input-user-translations '(("/" "/")))
772 ;; (lean-input-setup)
773 ;; ;; local key bindings
774 ;; (define-key lean-mode-map (kbd "S-SPC") #'company-complete))
776 (with-eval-after-load 'sgml-mode
777 (setq sgml-basic-offset
0))
779 (with-eval-after-load 'css-mode
780 (setq css-indent-offset
2))
783 ;; (setq font-latex-fontify-sectioning 'color)
785 (with-eval-after-load 'tex-mode
787 (lambda (p) (string-match "^---?" (car p
)))
788 tex--prettify-symbols-alist
))
789 (add-hook 'tex-mode-hook
#'auto-fill-mode
)
790 (add-hook 'tex-mode-hook
#'flyspell-mode
)
792 (run-with-idle-timer 0.5 nil
#'require
'cmake-mode
)
793 (with-eval-after-load 'cmake-mode
794 (setq cmake-tab-width
4)
795 (add-to-list 'load-path
(b/lisp
"cmake-font-lock"))
796 (run-with-idle-timer 0.5 nil
#'require
'cmake-font-lock
))
799 ;;; Emacs enhancements & auxiliary packages
801 (with-eval-after-load 'man
804 (defun b/*scratch
* ()
805 "Switch to `*scratch*' buffer, creating it if it does not exist."
807 (let ((fun (if (functionp #'get-scratch-buffer-create
)
808 #'get-scratch-buffer-create
; (version<= "29" emacs-version)
809 #'startup--get-buffer-create-scratch
))) ; (version< emacs-version "29")
810 (switch-to-buffer (funcall fun
))))
811 (global-set-key (kbd "C-c s") #'b
/*scratch
*)
814 ;; | make pretty boxed quotes like this
816 (add-to-list 'load-path
(b/lisp
"boxquote"))
817 (run-with-idle-timer 0.6 nil
#'require
'boxquote
)
818 (with-eval-after-load 'boxquote
819 (defvar b
/boxquote-prefix-map
)
820 (define-prefix-command 'b
/boxquote-prefix-map
)
821 (global-set-key (kbd "C-c q") 'b
/boxquote-prefix-map
)
822 (define-key b
/boxquote-prefix-map
(kbd "b") #'boxquote-buffer
)
823 (define-key b
/boxquote-prefix-map
(kbd "B") #'boxquote-insert-buffer
)
824 (define-key b
/boxquote-prefix-map
(kbd "d") #'boxquote-defun
)
825 (define-key b
/boxquote-prefix-map
(kbd "F") #'boxquote-insert-file
)
826 (define-key b
/boxquote-prefix-map
(kbd "hf") #'boxquote-describe-function
)
827 (define-key b
/boxquote-prefix-map
(kbd "hk") #'boxquote-describe-key
)
828 (define-key b
/boxquote-prefix-map
(kbd "hv") #'boxquote-describe-variable
)
829 (define-key b
/boxquote-prefix-map
(kbd "hw") #'boxquote-where-is
)
830 (define-key b
/boxquote-prefix-map
(kbd "k") #'boxquote-kill
)
831 (define-key b
/boxquote-prefix-map
(kbd "p") #'boxquote-paragraph
)
832 (define-key b
/boxquote-prefix-map
(kbd "q") #'boxquote-boxquote
)
833 (define-key b
/boxquote-prefix-map
(kbd "r") #'boxquote-region
)
834 (define-key b
/boxquote-prefix-map
(kbd "s") #'boxquote-shell-command
)
835 (define-key b
/boxquote-prefix-map
(kbd "t") #'boxquote-text
)
836 (define-key b
/boxquote-prefix-map
(kbd "T") #'boxquote-title
)
837 (define-key b
/boxquote-prefix-map
(kbd "u") #'boxquote-unbox
)
838 (define-key b
/boxquote-prefix-map
(kbd "U") #'boxquote-unbox-region
)
839 (define-key b
/boxquote-prefix-map
(kbd "y") #'boxquote-yank
)
840 (define-key b
/boxquote-prefix-map
(kbd "M-q") #'boxquote-fill-paragraph
)
841 (define-key b
/boxquote-prefix-map
(kbd "M-w") #'boxquote-kill-ring-save
))
843 (add-to-list 'load-path
(b/lisp
"hl-todo"))
844 (run-with-idle-timer 0.5 nil
#'require
'hl-todo
)
845 (with-eval-after-load 'hl-todo
846 ;; highlight TODOs in buffers
847 (global-hl-todo-mode))
850 (global-set-key (kbd "C-=") #'er
/expand-region
)
852 (run-with-idle-timer 0.6 nil
#'require
'yasnippet
)
853 (with-eval-after-load 'yasnippet
854 (declare-function yas-reload-all
855 "yasnippet" (&optional no-jit interactive
))
856 (declare-function yas-maybe-expand-abbrev-key-filter
859 (defconst yas-verbosity-cur yas-verbosity
)
860 (setq yas-verbosity
2
861 yas-snippet-dirs
`(,(b/etc
"yasnippet/snippets")))
862 ;; (add-to-list 'yas-snippet-dirs "~/src/git/guix/etc/snippets" t)
864 (setq yas-verbosity yas-verbosity-cur
)
866 (defun b/yas-maybe-expand-abbrev-key-filter
(cmd)
867 (when (and (yas-maybe-expand-abbrev-key-filter cmd
)
868 (not (bound-and-true-p git-commit-mode
)))
870 (defconst b
/yas-maybe-expand
871 '(menu-item "" yas-expand
872 :filter b
/yas-maybe-expand-abbrev-key-filter
))
873 (define-key yas-minor-mode-map
(kbd "SPC") b
/yas-maybe-expand
)
878 (global-set-key (kbd "C-c D d") #'debbugs-gnu
)
879 (global-set-key (kbd "C-c D b") #'debbugs-gnu-bugs
)
880 (global-set-key (kbd "C-c D e") ; bug-gnu-emacs
883 (setq debbugs-gnu-current-suppress t
)
884 (debbugs-gnu debbugs-gnu-default-severities
886 (global-set-key (kbd "C-c D g") ; bug-gnuzilla
889 (setq debbugs-gnu-current-suppress t
)
890 (debbugs-gnu debbugs-gnu-default-severities
895 url-configuration-directory
(b/var
"url/configuration/")
896 url-cache-directory
(b/var
"url/cache/"))
899 (setq eww-download-directory
(file-name-as-directory
900 (getenv "XDG_DOWNLOAD_DIR")))
901 (global-set-key (kbd "C-c a e w") #'eww
)
905 ;; reftex-default-bibliography '("~/usr/org/references.bib")
906 ;; org-ref-default-bibliography '("~/usr/org/references.bib")
907 ;; org-ref-bibliography-notes "~/usr/org/notes.org"
908 ;; org-ref-pdf-directory "~/usr/org/bibtex-pdfs/")
910 ;; fill-column-indicator ?
913 (setq split-width-threshold
150)
914 (global-set-key (kbd "C-c w s l")
919 (global-set-key (kbd "C-c w s j")
924 (global-set-key (kbd "C-c w q") #'quit-window
)
927 ;; (global-set-key (kbd "C-c a p") #'pass)
928 ;; (add-hook 'pass-mode-hook #'View-exit)
931 ;; uncomment to disable reftex-cite's default choice of previous word
932 ;; (with-eval-after-load 'reftex
933 ;; (require 'reftex-cite)
934 ;; (defun reftex-get-bibkey-default ()
935 ;; "If the cursor is in a citation macro, return the word before the macro."
936 ;; (let* ((macro (reftex-what-macro 1)))
938 ;; (when (and macro (string-match "cite" (car macro)))
939 ;; (goto-char (cdr macro)))
940 ;; (reftex-this-word)))))
941 (add-hook 'latex-mode-hook
#'reftex-mode
)
944 (add-to-list 'load-path
(b/lisp
"dmenu"))
945 (with-eval-after-load 'dmenu
946 (setq dmenu-prompt-string
"run: "
947 dmenu-save-file
(b/var
"dmenu-items")))
948 (autoload 'dmenu
"dmenu" nil t
)
953 (run-with-idle-timer 0.5 nil
#'require
'delight
)
954 (with-eval-after-load 'delight
955 (delight 'auto-fill-function
" f" "simple")
956 (delight 'abbrev-mode
"" "abbrev")
957 (delight 'mml-mode
" mml" "mml")
958 (delight 'yas-minor-mode
"" "yasnippet"))
961 (require 'bandali-po
)
963 (with-eval-after-load 'emms
964 (setq emms-directory
(b/var
"emms")))
966 (add-to-list 'load-path
(b/lisp
"ffs"))
967 (run-with-idle-timer 0.5 nil
#'require
'ffs
)
968 (with-eval-after-load 'ffs
969 (global-set-key (kbd "C-c f s") #'ffs
))
971 (defun b/export-frame
()
973 ;; TODO: ask for fn and/or take as arg
974 (let* ((fn (make-temp-file "emacs" nil
".pdf"))
975 (data (x-export-frames nil
'pdf
)))
982 ;;; Post initialization
984 (message "Loading %s...done (%.3fs)" user-init-file
985 (float-time (time-subtract (current-time)
986 b
/before-user-init-time
)))
988 ;;; init.el ends here