55874ebfa34dbce90af1adc8e3596e60ffbc9bca
[~bandali/configs] / init.org
1 #+title: =aminb='s Literate Emacs Configuration
2 #+author: Amin Bandali
3 #+babel: :cache yes
4 #+property: header-args :tangle yes
5
6 * About
7 :PROPERTIES:
8 :CUSTOM_ID: about
9 :END:
10
11 This org file is my literate configuration for GNU Emacs, and is
12 tangled to [[./init.el][init.el]]. Packages are installed and managed using
13 [[https://github.com/raxod502/straight.el][straight.el]]. Over the years, I've taken inspiration from
14 configurations of many different people. Some of the configurations
15 that I can remember off the top of my head are:
16
17 - [[https://github.com/dieggsy/dotfiles][dieggsy/dotfiles]]: literate Emacs and dotfiles configuration, uses
18 straight.el for managing packages
19 - [[https://github.com/dakra/dmacs][dakra/dmacs]]: literate Emacs configuration, using Borg for managing
20 packages
21 - [[http://pages.sachachua.com/.emacs.d/Sacha.html][Sacha Chua's literate Emacs configuration]]
22 - [[https://github.com/dakrone/eos][dakrone/eos]]
23 - Ryan Rix's [[http://doc.rix.si/cce/cce.html][Complete Computing Environment]] ([[http://doc.rix.si/projects/fsem.html][about cce]])
24 - [[https://github.com/jwiegley/dot-emacs][jwiegley/dot-emacs]]: nix-based configuration
25 - [[https://github.com/wasamasa/dotemacs][wasamasa/dotemacs]]
26 - [[https://github.com/hlissner/doom-emacs][Doom Emacs]]
27
28 I'd like to have a fully reproducible Emacs setup (part of the reason
29 why I store my configuration in this repository) but unfortunately out
30 of the box, that's not achievable with =package.el=, not currently
31 anyway. So, I've opted to use =straight.el=. I also used Borg for a
32 few months, but decided to try =straight.el= which allows direct use
33 of the various package archives.
34
35 ** Installation
36
37 To use this config for your Emacs, first you need to clone this repo,
38 then tangle =init.org= into =init.el=, and optionally byte-compile
39 =init.el=.
40
41 First, clone the repository and =cd= into it:
42
43 #+begin_src sh :tangle no
44 git clone https://git.sr.ht/~bandali/dotfiles ~/.emacs.d
45 cd ~/.emacs.d
46 #+end_src
47
48 Then, decide if you would like to use a byte-compiled init file, and
49 set the following variable accordingly:
50
51 #+begin_src emacs-lisp
52 (defvar a/byte-compiled-init t
53 "If non-nil, byte-(re)compile init.el on successful tangles.")
54 #+end_src
55
56 Now, first tangle =init.org=, and only if you chose to have a
57 byte-compiled init, build init as well:
58
59 #+begin_src sh :tangle no
60 make tangle-init
61 make build-init
62 #+end_src
63
64 If you'd like to use a byte-compiled init, it's important that it be
65 recompiled whenever =init.el= is generated from an updated =init.org=.
66 Not only does my setup automatically and asynchronously tangle
67 =init.org= to =init.el= every time you edit and save =init.org= in GNU
68 Emacs, it will also invoke =make build-init= if you set
69 =a/byte-compiled-init= to =t= above, so you wouldn't have to worry
70 about manually tangling and compiling your init file whenever you
71 change it. The output of the last byte-compilation in the current
72 session is kept in a =*compilation*= buffer, which will automatically
73 be displayed if compilation fails.
74
75 * Contents :toc_1:noexport:
76
77 - [[#about][About]]
78 - [[#header][Header]]
79 - [[#initial-setup][Initial setup]]
80 - [[#core][Core]]
81 - [[#borg-essentials][Borg's =layer/essentials=]]
82 - [[#editing][Editing]]
83 - [[#syntax-spell-checking][Syntax and spell checking]]
84 - [[#programming-modes][Programming modes]]
85 - [[#emacs-enhancements][Emacs enhancements]]
86 - [[#email][Email]]
87 - [[#blogging][Blogging]]
88 - [[#post-initialization][Post initialization]]
89 - [[#footer][Footer]]
90
91 * Header
92 :PROPERTIES:
93 :CUSTOM_ID: header
94 :END:
95
96 ** First line
97
98 #+begin_src emacs-lisp :comments none
99 ;;; init.el --- Amin Bandali's Emacs config -*- lexical-binding: t; eval: (view-mode 1) -*-
100 #+end_src
101
102 Enable =view-mode=, which both makes the file read-only (as a reminder
103 that =init.el= is an auto-generated file, not supposed to be edited),
104 and provides some convenient key bindings for browsing through the
105 file.
106
107 ** License
108
109 #+begin_src emacs-lisp :comments none
110 ;; Copyright (C) 2018-2019 Amin Bandali <bandali@gnu.org>
111
112 ;; This program is free software: you can redistribute it and/or modify
113 ;; it under the terms of the GNU General Public License as published by
114 ;; the Free Software Foundation, either version 3 of the License, or
115 ;; (at your option) any later version.
116
117 ;; This program is distributed in the hope that it will be useful,
118 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
119 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
120 ;; GNU General Public License for more details.
121
122 ;; You should have received a copy of the GNU General Public License
123 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
124 #+end_src
125
126 ** Commentary
127
128 #+begin_src emacs-lisp :comments none
129 ;;; Commentary:
130
131 ;; Emacs configuration of Amin Bandali, computer scientist, functional
132 ;; programmer, and free software advocate.
133
134 ;; THIS FILE IS AUTO-GENERATED FROM `init.org'.
135 #+end_src
136
137 * Initial setup
138 :PROPERTIES:
139 :CUSTOM_ID: initial-setup
140 :END:
141
142 ** Emacs initialization
143
144 I'd like to do a couple of measurements of Emacs' startup time. First,
145 let's see how long Emacs takes to start up, before even loading
146 =init.el=, i.e. =user-init-file=:
147
148 #+begin_src emacs-lisp
149 (defvar a/before-user-init-time (current-time)
150 "Value of `current-time' when Emacs begins loading `user-init-file'.")
151 (message "Loading Emacs...done (%.3fs)"
152 (float-time (time-subtract a/before-user-init-time
153 before-init-time)))
154 #+end_src
155
156 Also, temporarily increase ~gc-cons-threshhold~ and
157 ~gc-cons-percentage~ during startup to reduce garbage collection
158 frequency. Clearing the ~file-name-handler-alist~ seems to help reduce
159 startup time as well.
160
161 #+begin_src emacs-lisp
162 (defvar a/gc-cons-threshold gc-cons-threshold)
163 (defvar a/gc-cons-percentage gc-cons-percentage)
164 (defvar a/file-name-handler-alist file-name-handler-alist)
165 (setq gc-cons-threshold (* 400 1024 1024) ; 400 MiB
166 gc-cons-percentage 0.6
167 file-name-handler-alist nil
168 ;; sidesteps a bug when profiling with esup
169 esup-child-profile-require-level 0)
170 #+end_src
171
172 Of course, we'd like to set them back to their defaults once we're
173 done initializing.
174
175 #+begin_src emacs-lisp
176 (add-hook
177 'after-init-hook
178 (lambda ()
179 (setq gc-cons-threshold a/gc-cons-threshold
180 gc-cons-percentage a/gc-cons-percentage
181 file-name-handler-alist a/file-name-handler-alist)))
182 #+end_src
183
184 Increase the number of lines kept in message logs (the =*Messages*=
185 buffer).
186
187 #+begin_src emacs-lisp
188 (setq message-log-max 20000)
189 #+end_src
190
191 Optionally, we could suppress some byte compiler warnings like below,
192 but for now I've decided to keep them enabled. See documentation for
193 ~byte-compile-warnings~ for more details.
194
195 #+begin_src emacs-lisp
196 ;; (setq byte-compile-warnings
197 ;; '(not free-vars unresolved noruntime lexical make-local))
198 #+end_src
199
200 ** whoami
201
202 #+begin_src emacs-lisp
203 (setq user-full-name "Amin Bandali"
204 user-mail-address "amin@aminb.org")
205 #+end_src
206
207 ** Package management
208
209 *** No =package.el=
210
211 I can do all my package management things with =straight.el=, and
212 don't need Emacs' built-in =package.el=. Emacs 27 lets us disable
213 =package.el= in the =early-init-file= (see [[https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=24acb31c04b4048b85311d794e600ecd7ce60d3b][here]]).
214
215 #+begin_src emacs-lisp :tangle early-init.el
216 (setq package-enable-at-startup nil)
217 #+end_src
218
219 But since Emacs 27 isn't out yet (Emacs 26 is just around the corner
220 right now), and even when released it'll be long before most distros
221 ship in their repos, I'll still put the old workaround with the
222 commented call to ~package-initialize~ here anyway.
223
224 #+begin_src emacs-lisp :tangle no
225 (setq package-enable-at-startup nil)
226 ;; (package-initialize)
227 #+end_src
228
229 Update: the above is not necessary, since =straight.el= automatically
230 does that (and more). See =straight-package-neutering-mode=.
231
232 *** =straight.el=
233
234 #+begin_quote
235 Next-generation, purely functional package manager for the Emacs
236 hacker.
237 #+end_quote
238
239 =straight.el= allows me to have a fully reproducible Emacs setup.
240
241 #+begin_src emacs-lisp
242 ;; Main engine start...
243
244 (setq straight-repository-branch "develop"
245 straight-check-for-modifications '(check-on-save find-when-checking))
246
247 (defun a/bootstrap-straight ()
248 (defvar bootstrap-version)
249 (let ((bootstrap-file
250 (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
251 (bootstrap-version 5))
252 (unless (file-exists-p bootstrap-file)
253 (with-current-buffer
254 (url-retrieve-synchronously
255 "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
256 'silent 'inhibit-cookies)
257 (goto-char (point-max))
258 (eval-print-last-sexp)))
259 (load bootstrap-file nil 'nomessage)))
260
261 ;; Solid rocket booster ignition...
262
263 (defun a/build-init ()
264 (a/bootstrap-straight)
265 (byte-compile-file "init.el"))
266
267 (a/bootstrap-straight)
268
269 ;; We have lift off!
270
271 (setq straight-use-package-by-default t)
272 #+end_src
273
274 Since we enable =straight.el='s =straight-use-package-by-default=
275 integration, we will define a =use-feature= for plain ole
276 =use-package= without any of the =straight.el= stuff.
277
278 #+begin_src emacs-lisp
279 (defmacro use-feature (name &rest args)
280 "Like `use-package', but with `straight-use-package-by-default' disabled."
281 (declare (indent defun))
282 `(use-package ,name
283 :straight nil
284 ,@args))
285 #+end_src
286
287 *** =use-package=
288
289 #+begin_quote
290 A use-package declaration for simplifying your .emacs
291 #+end_quote
292
293 [[https://github.com/jwiegley/use-package][use-package]] is an awesome utility for managing and configuring
294 packages (in our case especially the latter) in a neatly organized way
295 and without compromising on performance.
296
297 #+begin_src emacs-lisp
298 (straight-use-package 'use-package)
299 (if nil ; set to t when need to debug init
300 (progn
301 (setq use-package-verbose t
302 use-package-expand-minimally nil
303 use-package-compute-statistics t
304 debug-on-error t)
305 (require 'use-package))
306 (setq use-package-verbose nil
307 use-package-expand-minimally t))
308
309 (setq use-package-always-defer t)
310 #+end_src
311
312 *** Epkg
313
314 #+begin_quote
315 Browse the Emacsmirror package database
316 #+end_quote
317
318 Epkg provides access to a local copy of the [[https://emacsmirror.net][Emacsmirror]] package
319 database, low-level functions for querying the database, and a
320 =package.el=-like user interface for browsing the available packages.
321
322 #+begin_src emacs-lisp
323 (require 'bind-key)
324 (use-package epkg
325 :commands (epkg-list-packages epkg-describe-package)
326 :bind
327 (("C-c p e d" . epkg-describe-package)
328 ("C-c p e p" . epkg-list-packages))
329 :config
330 (setq epkg-repository "~/.emacs.d/straight/repos/epkgs/")
331 (eval-when-compile (defvar ivy-initial-inputs-alist))
332 (with-eval-after-load 'ivy
333 (add-to-list
334 'ivy-initial-inputs-alist '(epkg-describe-package . "^") t)))
335 #+end_src
336
337 ** No littering in =~/.emacs.d=
338
339 #+begin_quote
340 Help keeping ~/.emacs.d clean
341 #+end_quote
342
343 By default, even for Emacs' built-in packages, the configuration files
344 and persistent data are all over the place. Use =no-littering= to help
345 contain the mess.
346
347 #+begin_src emacs-lisp
348 (use-package no-littering
349 :demand t
350 :config
351 (savehist-mode 1)
352 (add-to-list 'savehist-additional-variables 'kill-ring)
353 (save-place-mode 1)
354 (setq auto-save-file-name-transforms
355 `((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))
356 #+end_src
357
358 ** Custom file (=custom.el=)
359
360 I'm not planning on using the custom file much, but even so, I
361 definitely don't want it mixing with =init.el=. So, here; let's give
362 it it's own file. While at it, treat themes as safe.
363
364 #+begin_src emacs-lisp
365 (use-feature custom
366 :no-require t
367 :config
368 (setq custom-file (no-littering-expand-etc-file-name "custom.el"))
369 (when (file-exists-p custom-file)
370 (load custom-file))
371 (setf custom-safe-themes t))
372 #+end_src
373
374 ** Secrets file
375
376 Load the secrets file if it exists, otherwise show a warning.
377
378 #+begin_src emacs-lisp
379 (with-demoted-errors
380 (load (no-littering-expand-etc-file-name "secrets")))
381 #+end_src
382
383 ** Better =$PATH= handling
384
385 Let's use [[https://github.com/purcell/exec-path-from-shell][exec-path-from-shell]] to make Emacs use the =$PATH= as set up
386 in my shell.
387
388 #+begin_src emacs-lisp
389 (use-package exec-path-from-shell
390 :defer 1
391 :init
392 (setq exec-path-from-shell-arguments nil
393 exec-path-from-shell-check-startup-files nil)
394 :config
395 (exec-path-from-shell-initialize)
396 ;; while we're at it, let's fix access to our running ssh-agent
397 (exec-path-from-shell-copy-env "SSH_AGENT_PID")
398 (exec-path-from-shell-copy-env "SSH_AUTH_SOCK"))
399 #+end_src
400
401 ** COMMENT Only one custom theme at a time
402
403 #+begin_src emacs-lisp
404 (defadvice load-theme (before clear-previous-themes activate)
405 "Clear existing theme settings instead of layering them"
406 (mapc #'disable-theme custom-enabled-themes))
407 #+end_src
408
409 ** Server
410
411 Start server if not already running. Alternatively, can be done by
412 issuing =emacs --daemon= in the terminal, which can be automated with
413 a systemd service or using =brew services start emacs= on macOS. I use
414 Emacs as my window manager (via EXWM), so I always start Emacs on
415 login; so starting the server from inside Emacs is good enough for me.
416
417 See [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server][Using Emacs as a Server]].
418
419 #+begin_src emacs-lisp
420 (use-feature server
421 :defer 1
422 :config (or (server-running-p) (server-mode)))
423 #+end_src
424
425 ** COMMENT Unicode support
426
427 Font stack with better unicode support, around =Ubuntu Mono= and
428 =Hack=.
429
430 #+begin_src emacs-lisp
431 (dolist (ft (fontset-list))
432 (set-fontset-font
433 ft
434 'unicode
435 (font-spec :name "Source Code Pro" :size 14))
436 (set-fontset-font
437 ft
438 'unicode
439 (font-spec :name "DejaVu Sans Mono")
440 nil
441 'append)
442 ;; (set-fontset-font
443 ;; ft
444 ;; 'unicode
445 ;; (font-spec
446 ;; :name "Symbola monospacified for DejaVu Sans Mono")
447 ;; nil
448 ;; 'append)
449 ;; (set-fontset-font
450 ;; ft
451 ;; #x2115 ; ℕ
452 ;; (font-spec :name "DejaVu Sans Mono")
453 ;; nil
454 ;; 'append)
455 (set-fontset-font
456 ft
457 (cons ?Α ?ω)
458 (font-spec :name "DejaVu Sans Mono" :size 14)
459 nil
460 'prepend))
461 #+end_src
462
463 ** Gentler font resizing
464
465 #+begin_src emacs-lisp
466 (setq text-scale-mode-step 1.05)
467 #+end_src
468
469 ** Focus follows mouse
470
471 I’d like focus to follow the mouse when I move the cursor from one
472 window to the next.
473
474 #+begin_src emacs-lisp
475 (setq mouse-autoselect-window t)
476 #+end_src
477
478 Let’s define a function to conveniently disable this for certain
479 buffers and/or modes.
480
481 #+begin_src emacs-lisp
482 (defun a/no-mouse-autoselect-window ()
483 (make-local-variable 'mouse-autoselect-window)
484 (setq mouse-autoselect-window nil))
485 #+end_src
486
487 ** Libraries
488
489 #+begin_src emacs-lisp
490 (require 'cl-lib)
491 (require 'subr-x)
492 #+end_src
493
494 ** Useful utilities
495
496 Convenience macro for =setq='ing multiple variables to the same value:
497
498 #+begin_src emacs-lisp
499 (defmacro a/setq-every (value &rest vars)
500 "Set all the variables from VARS to value VALUE."
501 (declare (indent defun) (debug t))
502 `(progn ,@(mapcar (lambda (x) (list 'setq x value)) vars)))
503 #+end_src
504
505 The following process-related stuff from [[https://github.com/alezost/emacs-config][alezost's emacs-config]].
506
507 #+begin_src emacs-lisp
508 (defun a/start-process (program &rest args)
509 "Same as `start-process', but doesn't bother about name and buffer."
510 (let ((process-name (concat program "_process"))
511 (buffer-name (generate-new-buffer-name
512 (concat program "_output"))))
513 (apply #'start-process
514 process-name buffer-name program args)))
515
516 (defun a/dired-start-process (program &optional args)
517 "Open current file with a PROGRAM."
518 ;; Shell command looks like this: "program [ARGS]... FILE" (ARGS can
519 ;; be nil, so remove it).
520 (apply #'a/start-process
521 program
522 (remove nil (list args (dired-get-file-for-visit)))))
523 #+end_src
524
525 * Core
526 :PROPERTIES:
527 :CUSTOM_ID: core
528 :END:
529
530 ** Defaults
531
532 *** Time and battery in mode-line
533
534 Enable displaying time and battery in the mode-line, since I'm not
535 using the Xfce panel anymore. Also, I don't need to see the load
536 average on a regular basis, so disable that.
537
538 Note: using =i3status= on sway at the moment, so disabling this.
539
540 #+begin_src emacs-lisp :tangle no
541 (use-package time
542 :init
543 (setq display-time-default-load-average nil)
544 :config
545 (display-time-mode))
546
547 (use-package battery
548 :config
549 (display-battery-mode))
550 #+end_src
551
552 *** Smaller fringe
553
554 Might want to set the fringe to a smaller value, especially if using
555 EXWM. I'm fine with the default for now.
556
557 #+begin_src emacs-lisp
558 ;; (fringe-mode '(3 . 1))
559 (fringe-mode nil)
560 #+end_src
561
562 *** Disable disabled commands
563
564 Emacs disables some commands by default that could persumably be
565 confusing for novice users. Let's disable that.
566
567 #+begin_src emacs-lisp
568 (setq disabled-command-function nil)
569 #+end_src
570
571 *** Kill-ring
572
573 Save what I copy into clipboard from other applications into Emacs'
574 kill-ring, which would allow me to still be able to easily access it
575 in case I kill (cut or copy) something else inside Emacs before
576 yanking (pasting) what I'd originally intended to.
577
578 #+begin_src emacs-lisp
579 (setq save-interprogram-paste-before-kill t)
580 #+end_src
581
582 *** Minibuffer
583
584 #+begin_src emacs-lisp
585 (setq enable-recursive-minibuffers t
586 resize-mini-windows t)
587 #+end_src
588
589 *** Lazy-person-friendly yes/no prompts
590
591 Lazy people would prefer to type fewer keystrokes, especially for yes
592 or no questions. I'm lazy.
593
594 #+begin_src emacs-lisp
595 (defalias 'yes-or-no-p #'y-or-n-p)
596 #+end_src
597
598 *** Startup screen and =*scratch*=
599
600 Firstly, let Emacs know that I'd like to have =*scratch*= as my
601 startup buffer.
602
603 #+begin_src emacs-lisp
604 (setq initial-buffer-choice t)
605 #+end_src
606
607 Now let's customize the =*scratch*= buffer a bit. First off, I don't
608 need the default hint.
609
610 #+begin_src emacs-lisp
611 (setq initial-scratch-message nil)
612 #+end_src
613
614 Also, let's use Text mode as the major mode, in case I want to
615 customize it (=*scratch*='s default major mode, Fundamental mode,
616 can't really be customized).
617
618 #+begin_src emacs-lisp
619 (setq initial-major-mode 'text-mode)
620 #+end_src
621
622 Inhibit the buffer list when more than 2 files are loaded.
623
624 #+begin_src emacs-lisp
625 (setq inhibit-startup-buffer-menu t)
626 #+end_src
627
628 I don't really need to see the startup screen or echo area message
629 either.
630
631 #+begin_src emacs-lisp
632 (advice-add #'display-startup-echo-area-message :override #'ignore)
633 (setq inhibit-startup-screen t
634 inhibit-startup-echo-area-message user-login-name)
635 #+end_src
636
637 *** More useful frame titles
638
639 Show either the file name or the buffer name (in case the buffer isn't
640 visiting a file). Borrowed from Emacs Prelude.
641
642 #+begin_src emacs-lisp
643 (setq frame-title-format
644 '("" invocation-name " - "
645 (:eval (if (buffer-file-name)
646 (abbreviate-file-name (buffer-file-name))
647 "%b"))))
648 #+end_src
649
650 *** Backups
651
652 Emacs' default backup settings aren't that great. Let's use more
653 sensible options. See documentation for the ~make-backup-file~
654 variable.
655
656 #+begin_src emacs-lisp
657 (setq backup-by-copying t
658 version-control t
659 delete-old-versions t)
660 #+end_src
661
662 *** Auto revert
663
664 Enable automatic reloading of changed buffers and files.
665
666 #+begin_src emacs-lisp
667 (global-auto-revert-mode 1)
668 (setq auto-revert-verbose nil
669 global-auto-revert-non-file-buffers nil)
670 #+end_src
671
672 *** Always use space for indentation
673
674 #+begin_src emacs-lisp
675 (setq-default
676 indent-tabs-mode nil
677 require-final-newline t
678 tab-width 4)
679 #+end_src
680
681 *** Winner mode
682
683 Enable =winner-mode=.
684
685 #+begin_src emacs-lisp
686 (winner-mode 1)
687 #+end_src
688
689 *** Don’t display =*compilation*= on success
690
691 Based on https://stackoverflow.com/a/17788551, with changes to use
692 =cl-letf= instead of the now obsolete =flet=.
693
694 #+begin_src emacs-lisp
695 (with-eval-after-load 'compile
696 (defun a/compilation-finish-function (buffer outstr)
697 (unless (string-match "finished" outstr)
698 (switch-to-buffer-other-window buffer))
699 t)
700
701 (setq compilation-finish-functions #'a/compilation-finish-function)
702
703 (require 'cl-macs)
704
705 (defadvice compilation-start
706 (around inhibit-display
707 (command &optional mode name-function highlight-regexp))
708 (if (not (string-match "^\\(find\\|grep\\)" command))
709 (cl-letf (((symbol-function 'display-buffer) #'ignore))
710 (save-window-excursion ad-do-it))
711 ad-do-it))
712 (ad-activate 'compilation-start))
713 #+end_src
714
715 *** Search for non-ASCII characters
716
717 I’d like non-ASCII characters such as ‘’“”«»‹›áⓐ𝒶 to be selected when
718 I search for their ASCII counterpart. Shoutout to [[http://endlessparentheses.com/new-in-emacs-25-1-easily-search-non-ascii-characters.html][endlessparentheses]]
719 for this.
720
721 #+begin_src emacs-lisp
722 (setq search-default-mode #'char-fold-to-regexp)
723
724 ;; uncomment to extend this behaviour to query-replace
725 ;; (setq replace-char-fold t)
726 #+end_src
727
728 *** Cursor shape
729
730 #+begin_src emacs-lisp
731 (setq-default cursor-type 'bar)
732 #+end_src
733
734 *** Allow scrolling in Isearch
735
736 #+begin_src emacs-lisp
737 (setq isearch-allow-scroll t)
738 #+end_src
739
740 ** Bindings
741
742 Some bindings for functions from built-in GNU Emacs packages:
743
744 #+begin_src emacs-lisp
745 (bind-keys
746 ("C-c a i" . ielm)
747
748 ("C-c e b" . eval-buffer)
749 ("C-c e r" . eval-region)
750
751 ("C-c e i" . emacs-init-time)
752 ("C-c e u" . emacs-uptime)
753
754 ("C-c F m" . make-frame-command)
755 ("C-c F d" . delete-frame)
756 ("C-c F D" . delete-other-frames)
757
758 ("C-c o" . other-window)
759
760 ("C-c Q" . save-buffers-kill-terminal)
761
762 ("C-S-h C" . describe-char)
763 ("C-S-h F" . describe-face)
764
765 ("C-x k" . kill-this-buffer)
766 ("C-x K" . kill-buffer)
767
768 ("s-p" . beginning-of-buffer)
769 ("s-n" . end-of-buffer))
770 #+end_src
771
772 While at it, let's bind a few for some =straight-*= functions too:
773
774 #+begin_src emacs-lisp
775 (bind-keys
776 :prefix-map a/straight-prefix-map
777 :prefix "C-c p s"
778 ("u" . straight-use-package)
779 ("f" . straight-freeze-versions)
780 ("t" . straight-thaw-versions)
781 ("P" . straight-prune-build)
782 ("r" . straight-get-recipe)
783 ;; M-x ^straight-.*-all$
784 ("a c" . straight-check-all)
785 ("a f" . straight-fetch-all)
786 ("a m" . straight-merge-all)
787 ("a n" . straight-normalize-all)
788 ("a F" . straight-pull-all)
789 ("a P" . straight-push-all)
790 ("a r" . straight-rebuild-all)
791 ;; M-x ^straight-.*-package$
792 ("p c" . straight-check-package)
793 ("p f" . straight-fetch-package)
794 ("p m" . straight-merge-package)
795 ("p n" . straight-normalize-package)
796 ("p F" . straight-pull-package)
797 ("p P" . straight-push-package)
798 ("p r" . straight-rebuild-package))
799 #+end_src
800
801 ** Packages
802
803 The packages in this section are absolutely essential to my everyday
804 workflow, and they play key roles in how I do my computing. They
805 immensely enhance the Emacs experience for me; both using Emacs, and
806 customizing it.
807
808 *** [[https://github.com/emacscollective/auto-compile][auto-compile]]
809
810 #+begin_src emacs-lisp
811 (use-package auto-compile
812 :demand t
813 :config
814 (auto-compile-on-load-mode)
815 (auto-compile-on-save-mode)
816 (setq auto-compile-display-buffer nil
817 auto-compile-mode-line-counter t
818 auto-compile-source-recreate-deletes-dest t
819 auto-compile-toggle-deletes-nonlib-dest t
820 auto-compile-update-autoloads t)
821 (add-hook 'auto-compile-inhibit-compile-hook
822 'auto-compile-inhibit-compile-detached-git-head))
823 #+end_src
824
825 *** [[https://orgmode.org/][Org]]
826
827 #+begin_quote
828 Org mode is for keeping notes, maintaining TODO lists, planning
829 projects, and authoring documents with a fast and effective plain-text
830 system.
831 #+end_quote
832
833 In short, my favourite way of life.
834
835 First, we have to resort to a [[https://github.com/raxod502/straight.el#installing-org-with-straightel][hack]] to be able to use the correct
836 latest version of Org from upstream.
837
838 #+begin_src emacs-lisp
839 (use-package git)
840
841 (defun org-git-version ()
842 "The Git version of org-mode.
843 Inserted by installing org-mode or when a release is made."
844 (require 'git)
845 (let ((git-repo (expand-file-name
846 "straight/repos/org/" user-emacs-directory)))
847 (string-trim
848 (git-run "describe"
849 "--match=release\*"
850 "--abbrev=6"
851 "HEAD"))))
852
853 (defun org-release ()
854 "The release version of org-mode.
855 Inserted by installing org-mode or when a release is made."
856 (require 'git)
857 (let ((git-repo (expand-file-name
858 "straight/repos/org/" user-emacs-directory)))
859 (string-trim
860 (string-remove-prefix
861 "release_"
862 (git-run "describe"
863 "--match=release\*"
864 "--abbrev=0"
865 "HEAD")))))
866
867 (provide 'org-version)
868 #+end_src
869
870 We will use the =org-plus-contrib= package to get the whole deal:
871
872 #+begin_src emacs-lisp
873 (straight-use-package 'org-plus-contrib)
874 #+end_src
875
876 And here's where my actual Org configurations begin:
877
878 #+begin_src emacs-lisp
879 (use-feature org
880 :defer 2
881 :config
882 (setq org-src-tab-acts-natively t
883 org-src-preserve-indentation nil
884 org-edit-src-content-indentation 0
885 org-email-link-description-format "Email %c: %s" ; %.30s
886 org-highlight-latex-and-related '(entities)
887 org-use-speed-commands t
888 org-startup-folded 'content
889 org-catch-invisible-edits 'show-and-error
890 org-log-done 'time)
891 (add-to-list 'org-structure-template-alist '("L" . "src emacs-lisp") t)
892 :bind (:map org-mode-map ("M-L" . org-insert-last-stored-link))
893 :hook ((org-mode . org-indent-mode)
894 (org-mode . auto-fill-mode)
895 (org-mode . flyspell-mode))
896 :custom
897 (org-latex-packages-alist '(("" "listings") ("" "color")))
898 :custom-face
899 '(org-block-begin-line ((t (:foreground "#5a5b5a" :background "#1d1f21"))))
900 '(org-block ((t (:background "#1d1f21"))))
901 '(org-latex-and-related ((t (:foreground "#b294bb")))))
902
903 (use-feature ox-latex
904 :after ox
905 :config
906 (setq org-latex-listings 'listings
907 ;; org-latex-prefer-user-labels t
908 )
909 (add-to-list 'org-latex-classes
910 '("IEEEtran" "\\documentclass[11pt]{IEEEtran}"
911 ("\\section{%s}" . "\\section*{%s}")
912 ("\\subsection{%s}" . "\\subsection*{%s}")
913 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
914 ("\\paragraph{%s}" . "\\paragraph*{%s}")
915 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
916 t)
917 (require 'ox-beamer))
918 #+end_src
919
920 **** asynchronous tangle
921
922 =a/async-babel-tangle= is a function closely inspired by [[https://github.com/dieggsy/dotfiles/tree/cc10edf7701958eff1cd94d4081da544d882a28c/emacs.d#dotfiles][dieggsy's
923 d/async-babel-tangle]] which uses [[https://github.com/jwiegley/emacs-async][async]] to asynchronously tangle an org
924 file.
925
926 #+begin_src emacs-lisp
927 (with-eval-after-load 'org
928 (defvar a/show-async-tangle-results nil
929 "Keep *emacs* async buffers around for later inspection.")
930
931 (defvar a/show-async-tangle-time nil
932 "Show the time spent tangling the file.")
933
934 (defvar a/async-tangle-post-compile
935 (when a/byte-compiled-init "make build-init")
936 "If non-nil, pass to `compile' after successful tangle.")
937
938 ;; TODO: look into why directly byte-compiling init.el causes a
939 ;; number of problems, including magit-status not loading (busy
940 ;; waiting).
941 (defvar a/async-tangle-byte-recompile nil
942 "If non-nil, byte-recompile the file on successful tangle.")
943
944 (defun a/async-babel-tangle ()
945 "Tangle org file asynchronously."
946 (interactive)
947 (let* ((file-tangle-start-time (current-time))
948 (file (buffer-file-name))
949 (file-nodir (file-name-nondirectory file))
950 ;; (async-quiet-switch "-q")
951 (file-noext (file-name-sans-extension file)))
952 (async-start
953 `(lambda ()
954 (require 'org)
955 (org-babel-tangle-file ,file))
956 (unless a/show-async-tangle-results
957 `(lambda (result)
958 (if result
959 (progn
960 ;; (setq byte-compile-warnings '(not noruntime unresolved))
961 (message "Tangled %s%s"
962 ,file-nodir
963 (if a/show-async-tangle-time
964 (format " (%.3fs)"
965 (float-time (time-subtract (current-time)
966 ',file-tangle-start-time)))
967 ""))
968 (when a/async-tangle-post-compile
969 (compile a/async-tangle-post-compile))
970 (when a/async-tangle-byte-recompile
971 (byte-recompile-file (concat ,file-noext ".el"))))
972 (message "Tangling %s failed" ,file-nodir))))))))
973
974 (add-to-list
975 'safe-local-variable-values
976 '(eval add-hook 'after-save-hook #'a/async-babel-tangle 'append 'local))
977 #+end_src
978
979 *** [[https://magit.vc/][Magit]]
980
981 #+begin_quote
982 It's Magit! A Git porcelain inside Emacs.
983 #+end_quote
984
985 Not just how I do git, but /the/ way to do git.
986
987 #+begin_src emacs-lisp
988 (use-package magit
989 :defer 2
990 :bind (("C-x g" . magit-status)
991 ("s-g s" . magit-status)
992 ("s-g l" . magit-log-buffer-file))
993 :config
994 (magit-add-section-hook 'magit-status-sections-hook
995 'magit-insert-modules
996 'magit-insert-stashes
997 'append)
998 (setq
999 magit-repository-directories '(("~/.emacs.d/" . 0)
1000 ("~/src/git/" . 1)))
1001 (nconc magit-section-initial-visibility-alist
1002 '(([unpulled status] . show)
1003 ([unpushed status] . show)))
1004 :custom-face (magit-diff-file-heading ((t (:weight normal)))))
1005 #+end_src
1006
1007 *** recentf
1008
1009 Recently opened files.
1010
1011 #+begin_src emacs-lisp
1012 (use-feature recentf
1013 :defer 0.5
1014 :config
1015 (add-to-list 'recentf-exclude "^/\\(?:ssh\\|su\\|sudo\\)?:")
1016 (setq recentf-max-saved-items 40))
1017 #+end_src
1018
1019 *** smex
1020
1021 #+begin_quote
1022 A smart M-x enhancement for Emacs.
1023 #+end_quote
1024
1025 Mostly because =counsel= needs it to remember history.
1026
1027 #+begin_src emacs-lisp
1028 (use-package smex)
1029 #+end_src
1030
1031 *** [[https://github.com/abo-abo/swiper][Ivy]] (and friends)
1032
1033 #+begin_quote
1034 Ivy - a generic completion frontend for Emacs, Swiper - isearch with
1035 an overview, and more. Oh, man!
1036 #+end_quote
1037
1038 There's no way I could top that, so I won't attempt to.
1039
1040 **** Ivy
1041
1042 #+begin_src emacs-lisp
1043 (use-package ivy
1044 :defer 0.6
1045 :bind
1046 (:map ivy-minibuffer-map
1047 ([escape] . keyboard-escape-quit)
1048 ([S-up] . ivy-previous-history-element)
1049 ([S-down] . ivy-next-history-element)
1050 ("DEL" . ivy-backward-delete-char))
1051 :config
1052 (setq ivy-wrap t)
1053 (ivy-mode 1)
1054 ;; :custom-face
1055 ;; (ivy-minibuffer-match-face-2 ((t (:background "#e99ce8" :weight semi-bold))))
1056 ;; (ivy-minibuffer-match-face-3 ((t (:background "#bbbbff" :weight semi-bold))))
1057 ;; (ivy-minibuffer-match-face-4 ((t (:background "#ffbbff" :weight semi-bold))))
1058 )
1059 #+end_src
1060
1061 **** Swiper
1062
1063 #+begin_src emacs-lisp
1064 (use-package swiper
1065 :after ivy
1066 :bind (("C-s" . swiper)
1067 ("C-r" . swiper)
1068 ("C-S-s" . isearch-forward)))
1069 #+end_src
1070
1071 **** Counsel
1072
1073 #+begin_src emacs-lisp
1074 (use-package counsel
1075 :after ivy
1076 :bind (([remap execute-extended-command] . counsel-M-x)
1077 ([remap find-file] . counsel-find-file)
1078 ("s-r" . counsel-recentf)
1079 ("C-c x" . counsel-M-x)
1080 ("C-c f ." . counsel-find-file)
1081 :map minibuffer-local-map
1082 ("C-r" . counsel-minibuffer-history))
1083 :config
1084 (counsel-mode 1)
1085 (defalias 'locate #'counsel-locate))
1086 #+end_src
1087
1088 *** eshell
1089
1090 #+begin_src emacs-lisp
1091 (use-feature eshell
1092 :defer 2
1093 :commands eshell
1094 :bind ("C-c a s e" . eshell)
1095 :config
1096 (eval-when-compile (defvar eshell-prompt-regexp))
1097 (defun a/eshell-quit-or-delete-char (arg)
1098 (interactive "p")
1099 (if (and (eolp) (looking-back eshell-prompt-regexp nil))
1100 (eshell-life-is-too-much)
1101 (delete-char arg)))
1102
1103 (defun a/eshell-clear ()
1104 (interactive)
1105 (let ((inhibit-read-only t))
1106 (erase-buffer))
1107 (eshell-send-input))
1108
1109 (defun a/eshell-setup ()
1110 (make-local-variable 'company-idle-delay)
1111 (defvar company-idle-delay)
1112 (setq company-idle-delay nil)
1113 (bind-keys :map eshell-mode-map
1114 ("C-d" . a/eshell-quit-or-delete-char)
1115 ("C-S-l" . a/eshell-clear)
1116 ("M-r" . counsel-esh-history)
1117 ([tab] . company-complete)))
1118
1119 :hook (eshell-mode . a/eshell-setup)
1120 :custom
1121 (eshell-hist-ignoredups t)
1122 (eshell-input-filter 'eshell-input-filter-initial-space))
1123 #+end_src
1124
1125 *** Ibuffer
1126
1127 #+begin_src emacs-lisp
1128 (use-feature ibuffer
1129 :bind
1130 (("C-x C-b" . ibuffer-other-window)
1131 :map ibuffer-mode-map
1132 ("P" . ibuffer-backward-filter-group)
1133 ("N" . ibuffer-forward-filter-group)
1134 ("M-p" . ibuffer-do-print)
1135 ("M-n" . ibuffer-do-shell-command-pipe-replace))
1136 :config
1137 ;; Use human readable Size column instead of original one
1138 (define-ibuffer-column size-h
1139 (:name "Size" :inline t)
1140 (cond
1141 ((> (buffer-size) 1000000) (format "%7.1fM" (/ (buffer-size) 1000000.0)))
1142 ((> (buffer-size) 100000) (format "%7.0fk" (/ (buffer-size) 1000.0)))
1143 ((> (buffer-size) 1000) (format "%7.1fk" (/ (buffer-size) 1000.0)))
1144 (t (format "%8d" (buffer-size)))))
1145 :custom
1146 (ibuffer-saved-filter-groups
1147 '(("default"
1148 ("dired" (mode . dired-mode))
1149 ("org" (mode . org-mode))
1150 ("gnus"
1151 (or
1152 (mode . gnus-group-mode)
1153 (mode . gnus-summary-mode)
1154 (mode . gnus-article-mode)
1155 ;; not really, but...
1156 (mode . message-mode)))
1157 ("web"
1158 (or
1159 (mode . web-mode)
1160 (mode . css-mode)
1161 (mode . scss-mode)
1162 (mode . js2-mode)))
1163 ("shell"
1164 (or
1165 (mode . eshell-mode)
1166 (mode . shell-mode)
1167 (mode . term-mode)))
1168 ("programming"
1169 (or
1170 (mode . python-mode)
1171 (mode . c-mode)
1172 (mode . c++-mode)
1173 (mode . java-mode)
1174 (mode . emacs-lisp-mode)
1175 (mode . scheme-mode)
1176 (mode . haskell-mode)
1177 (mode . lean-mode)))
1178 ("emacs"
1179 (or
1180 (name . "^\\*scratch\\*$")
1181 (name . "^\\*Messages\\*$"))))))
1182 (ibuffer-formats
1183 '((mark modified read-only locked " "
1184 (name 18 18 :left :elide)
1185 " "
1186 (size-h 9 -1 :right)
1187 " "
1188 (mode 16 16 :left :elide)
1189 " " filename-and-process)
1190 (mark " "
1191 (name 16 -1)
1192 " " filename)))
1193 :hook (ibuffer . (lambda () (ibuffer-switch-to-saved-filter-groups "default"))))
1194 #+end_src
1195
1196 *** Outline
1197
1198 #+begin_src emacs-lisp
1199 (use-feature outline
1200 :hook (prog-mode . outline-minor-mode)
1201 :bind
1202 (:map
1203 outline-minor-mode-map
1204 ("<s-tab>" . outline-toggle-children)
1205 ("M-p" . outline-previous-visible-heading)
1206 ("M-n" . outline-next-visible-heading)
1207 :prefix-map a/outline-prefix-map
1208 :prefix "s-o"
1209 ("TAB" . outline-toggle-children)
1210 ("a" . outline-hide-body)
1211 ("H" . outline-hide-body)
1212 ("S" . outline-show-all)
1213 ("h" . outline-hide-subtree)
1214 ("s" . outline-show-subtree)))
1215 #+end_src
1216
1217 *** Dired
1218
1219 #+begin_src emacs-lisp
1220 (use-feature ls-lisp
1221 :custom (ls-lisp-dirs-first t))
1222
1223 (use-feature dired
1224 :config
1225 (setq dired-listing-switches "-alh"
1226 ls-lisp-use-insert-directory-program nil)
1227
1228 ;; easily diff 2 marked files
1229 ;; https://oremacs.com/2017/03/18/dired-ediff/
1230 (defun dired-ediff-files ()
1231 (interactive)
1232 (require 'dired-aux)
1233 (defvar ediff-after-quit-hook-internal)
1234 (let ((files (dired-get-marked-files))
1235 (wnd (current-window-configuration)))
1236 (if (<= (length files) 2)
1237 (let ((file1 (car files))
1238 (file2 (if (cdr files)
1239 (cadr files)
1240 (read-file-name
1241 "file: "
1242 (dired-dwim-target-directory)))))
1243 (if (file-newer-than-file-p file1 file2)
1244 (ediff-files file2 file1)
1245 (ediff-files file1 file2))
1246 (add-hook 'ediff-after-quit-hook-internal
1247 (lambda ()
1248 (setq ediff-after-quit-hook-internal nil)
1249 (set-window-configuration wnd))))
1250 (error "no more than 2 files should be marked"))))
1251 :bind (:map dired-mode-map
1252 ("b" . dired-up-directory)
1253 ("e" . dired-ediff-files)
1254 ("E" . dired-toggle-read-only)
1255 ("\\" . dired-hide-details-mode)
1256 ("z" . (lambda ()
1257 (interactive)
1258 (a/dired-start-process "zathura"))))
1259 :hook (dired-mode . dired-hide-details-mode))
1260 #+end_src
1261
1262 *** Help
1263
1264 #+begin_src emacs-lisp
1265 (use-feature help
1266 :config
1267 (temp-buffer-resize-mode)
1268 (setq help-window-select t))
1269 #+end_src
1270
1271 *** Tramp
1272
1273 #+begin_src emacs-lisp
1274 (use-feature tramp
1275 :config
1276 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
1277 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
1278 (add-to-list 'tramp-default-proxies-alist
1279 (list (regexp-quote (system-name)) nil nil)))
1280 #+end_src
1281
1282 *** Dash
1283
1284 #+begin_src emacs-lisp
1285 (use-package dash
1286 :config (dash-enable-font-lock))
1287 #+end_src
1288
1289 * Editing
1290 :PROPERTIES:
1291 :CUSTOM_ID: editing
1292 :END:
1293
1294 ** =diff-hl=
1295
1296 Highlight uncommitted changes in the left fringe.
1297
1298 #+begin_src emacs-lisp
1299 (use-package diff-hl
1300 :config
1301 (setq diff-hl-draw-borders nil)
1302 (global-diff-hl-mode)
1303 :hook (magit-post-refresh . diff-hl-magit-post-refresh))
1304 #+end_src
1305
1306 ** ElDoc
1307
1308 Display Lisp objects at point in the echo area.
1309
1310 #+begin_src emacs-lisp
1311 (use-feature eldoc
1312 :when (version< "25" emacs-version)
1313 :config (global-eldoc-mode))
1314 #+end_src
1315
1316 ** paren
1317
1318 Highlight matching parens.
1319
1320 #+begin_src emacs-lisp
1321 (use-feature paren
1322 :demand
1323 :config (show-paren-mode))
1324 #+end_src
1325
1326 ** simple (for column numbers)
1327
1328 #+begin_src emacs-lisp
1329 (use-feature simple
1330 :config (column-number-mode))
1331 #+end_src
1332
1333 ** =savehist=
1334
1335 Save minibuffer history.
1336
1337 #+begin_src emacs-lisp
1338 (use-feature savehist
1339 :config (savehist-mode))
1340 #+end_src
1341
1342 ** =saveplace=
1343
1344 Automatically save place in each file.
1345
1346 #+begin_src emacs-lisp
1347 (use-feature saveplace
1348 :when (version< "25" emacs-version)
1349 :config (save-place-mode))
1350 #+end_src
1351
1352 ** =prog-mode=
1353
1354 #+begin_src emacs-lisp
1355 (use-feature prog-mode
1356 :config (global-prettify-symbols-mode)
1357 (defun indicate-buffer-boundaries-left ()
1358 (setq indicate-buffer-boundaries 'left))
1359 (add-hook 'prog-mode-hook #'indicate-buffer-boundaries-left))
1360 #+end_src
1361
1362 ** =text-mode=
1363
1364 #+begin_src emacs-lisp
1365 (use-feature text-mode
1366 :hook ((text-mode . indicate-buffer-boundaries-left)
1367 (text-mode . abbrev-mode)))
1368 #+end_src
1369
1370 ** Company
1371
1372 #+begin_src emacs-lisp
1373 (use-package company
1374 :defer 3
1375 :bind
1376 (:map company-active-map
1377 ([tab] . company-complete-common-or-cycle)
1378 ([escape] . company-abort))
1379 :custom
1380 (company-minimum-prefix-length 1)
1381 (company-selection-wrap-around t)
1382 (company-dabbrev-char-regexp "\\sw\\|\\s_\\|[-_]")
1383 (company-dabbrev-downcase nil)
1384 (company-dabbrev-ignore-case nil)
1385 :config
1386 (global-company-mode t))
1387 #+end_src
1388
1389 ** Flycheck
1390
1391 #+begin_src emacs-lisp
1392 (use-package flycheck
1393 :defer 3
1394 :hook (prog-mode . flycheck-mode)
1395 :bind
1396 (:map flycheck-mode-map
1397 ("M-P" . flycheck-previous-error)
1398 ("M-N" . flycheck-next-error))
1399 :config
1400 ;; Use the load-path from running Emacs when checking elisp files
1401 (setq flycheck-emacs-lisp-load-path 'inherit)
1402
1403 ;; Only flycheck when I actually save the buffer
1404 (setq flycheck-check-syntax-automatically '(mode-enabled save)))
1405
1406 ;; http://endlessparentheses.com/ispell-and-apostrophes.html
1407 (use-package ispell
1408 :defer 3
1409 :config
1410 ;; ’ can be part of a word
1411 (setq ispell-local-dictionary-alist
1412 `((nil "[[:alpha:]]" "[^[:alpha:]]"
1413 "['\x2019]" nil ("-B") nil utf-8)))
1414 ;; don't send ’ to the subprocess
1415 (defun endless/replace-apostrophe (args)
1416 (cons (replace-regexp-in-string
1417 "’" "'" (car args))
1418 (cdr args)))
1419 (advice-add #'ispell-send-string :filter-args
1420 #'endless/replace-apostrophe)
1421
1422 ;; convert ' back to ’ from the subprocess
1423 (defun endless/replace-quote (args)
1424 (if (not (derived-mode-p 'org-mode))
1425 args
1426 (cons (replace-regexp-in-string
1427 "'" "’" (car args))
1428 (cdr args))))
1429 (advice-add #'ispell-parse-output :filter-args
1430 #'endless/replace-quote))
1431 #+end_src
1432
1433 * Programming modes
1434 :PROPERTIES:
1435 :CUSTOM_ID: programming-modes
1436 :END:
1437
1438 ** Lisp
1439
1440 #+begin_src emacs-lisp
1441 (use-feature lisp-mode
1442 :config
1443 (add-hook 'emacs-lisp-mode-hook 'outline-minor-mode)
1444 (add-hook 'emacs-lisp-mode-hook 'reveal-mode)
1445 (defun indent-spaces-mode ()
1446 (setq indent-tabs-mode nil))
1447 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
1448 #+end_src
1449
1450 ** [[http://alloytools.org][Alloy]] (with [[https://github.com/dwwmmn/alloy-mode][alloy-mode]])
1451
1452 #+begin_src emacs-lisp
1453 (use-package alloy-mode
1454 :straight (:host github :repo "dwwmmn/alloy-mode")
1455 :config (setq alloy-basic-offset 2))
1456 #+end_src
1457
1458 ** [[https://coq.inria.fr][Coq]] (with [[https://github.com/ProofGeneral/PG][Proof General]])
1459
1460 #+begin_src emacs-lisp
1461 (use-package proof-site ; Proof General
1462 :straight proof-general)
1463 #+end_src
1464
1465 ** [[https://leanprover.github.io][Lean]] (with [[https://github.com/leanprover/lean-mode][lean-mode]])
1466
1467 #+begin_src emacs-lisp
1468 (eval-when-compile (defvar lean-mode-map))
1469 (use-package lean-mode
1470 :defer 1
1471 :bind (:map lean-mode-map
1472 ("S-SPC" . company-complete))
1473 :config
1474 (require 'lean-input)
1475 (setq default-input-method "Lean"
1476 lean-input-tweak-all '(lean-input-compose
1477 (lean-input-prepend "/")
1478 (lean-input-nonempty))
1479 lean-input-user-translations '(("/" "/")))
1480 (lean-input-setup))
1481 #+end_src
1482
1483 ** Haskell
1484
1485 *** [[https://github.com/haskell/haskell-mode][haskell-mode]]
1486
1487 #+begin_src emacs-lisp
1488 (use-package haskell-mode
1489 :config
1490 (setq haskell-indentation-layout-offset 4
1491 haskell-indentation-left-offset 4
1492 flycheck-checker 'haskell-hlint
1493 flycheck-disabled-checkers '(haskell-stack-ghc haskell-ghc)))
1494 #+end_src
1495
1496 *** [[https://github.com/jyp/dante][dante]]
1497
1498 #+begin_src emacs-lisp
1499 (use-package dante
1500 :after haskell-mode
1501 :commands dante-mode
1502 :hook (haskell-mode . dante-mode))
1503 #+end_src
1504
1505 *** [[https://github.com/mpickering/hlint-refactor-mode][hlint-refactor]]
1506
1507 Emacs bindings for [[https://github.com/ndmitchell/hlint][hlint]]'s refactor option. This requires the refact
1508 executable from [[https://github.com/mpickering/apply-refact][apply-refact]].
1509
1510 #+begin_src emacs-lisp
1511 (use-package hlint-refactor
1512 :after haskell-mode
1513 :bind (:map hlint-refactor-mode-map
1514 ("C-c l b" . hlint-refactor-refactor-buffer)
1515 ("C-c l r" . hlint-refactor-refactor-at-point))
1516 :hook (haskell-mode . hlint-refactor-mode))
1517 #+end_src
1518
1519 *** [[https://github.com/flycheck/flycheck-haskell][flycheck-haskell]]
1520
1521 #+begin_src emacs-lisp
1522 (use-package flycheck-haskell
1523 :after haskell-mode)
1524 #+end_src
1525
1526 *** [[https://github.com/ndmitchell/hlint/blob/20e116a043f2073c57b17b24ae6364b5e433ba7e/data/hs-lint.el][hs-lint.el]]
1527 :PROPERTIES:
1528 :header-args+: :tangle lisp/hs-lint.el :mkdirp yes
1529 :END:
1530
1531 Currently using =flycheck-haskell= with the =haskell-hlint= checker
1532 instead.
1533
1534 #+begin_src emacs-lisp :tangle no
1535 ;;; hs-lint.el --- minor mode for HLint code checking
1536
1537 ;; Copyright 2009 (C) Alex Ott
1538 ;;
1539 ;; Author: Alex Ott <alexott@gmail.com>
1540 ;; Keywords: haskell, lint, HLint
1541 ;; Requirements:
1542 ;; Status: distributed under terms of GPL2 or above
1543
1544 ;; Typical message from HLint looks like:
1545 ;;
1546 ;; /Users/ott/projects/lang-exp/haskell/test.hs:52:1: Eta reduce
1547 ;; Found:
1548 ;; count1 p l = length (filter p l)
1549 ;; Why not:
1550 ;; count1 p = length . filter p
1551
1552
1553 (require 'compile)
1554
1555 (defgroup hs-lint nil
1556 "Run HLint as inferior of Emacs, parse error messages."
1557 :group 'tools
1558 :group 'haskell)
1559
1560 (defcustom hs-lint-command "hlint"
1561 "The default hs-lint command for \\[hlint]."
1562 :type 'string
1563 :group 'hs-lint)
1564
1565 (defcustom hs-lint-save-files t
1566 "Save modified files when run HLint or no (ask user)"
1567 :type 'boolean
1568 :group 'hs-lint)
1569
1570 (defcustom hs-lint-replace-with-suggestions nil
1571 "Replace user's code with suggested replacements"
1572 :type 'boolean
1573 :group 'hs-lint)
1574
1575 (defcustom hs-lint-replace-without-ask nil
1576 "Replace user's code with suggested replacements automatically"
1577 :type 'boolean
1578 :group 'hs-lint)
1579
1580 (defun hs-lint-process-setup ()
1581 "Setup compilation variables and buffer for `hlint'."
1582 (run-hooks 'hs-lint-setup-hook))
1583
1584 ;; regex for replace suggestions
1585 ;;
1586 ;; ^\(.*?\):\([0-9]+\):\([0-9]+\): .*
1587 ;; Found:
1588 ;; \s +\(.*\)
1589 ;; Why not:
1590 ;; \s +\(.*\)
1591
1592 (defvar hs-lint-regex
1593 "^\\(.*?\\):\\([0-9]+\\):\\([0-9]+\\): .*[\n\C-m]Found:[\n\C-m]\\s +\\(.*\\)[\n\C-m]Why not:[\n\C-m]\\s +\\(.*\\)[\n\C-m]"
1594 "Regex for HLint messages")
1595
1596 (defun make-short-string (str maxlen)
1597 (if (< (length str) maxlen)
1598 str
1599 (concat (substring str 0 (- maxlen 3)) "...")))
1600
1601 (defun hs-lint-replace-suggestions ()
1602 "Perform actual replacement of suggestions"
1603 (goto-char (point-min))
1604 (while (re-search-forward hs-lint-regex nil t)
1605 (let* ((fname (match-string 1))
1606 (fline (string-to-number (match-string 2)))
1607 (old-code (match-string 4))
1608 (new-code (match-string 5))
1609 (msg (concat "Replace '" (make-short-string old-code 30)
1610 "' with '" (make-short-string new-code 30) "'"))
1611 (bline 0)
1612 (eline 0)
1613 (spos 0)
1614 (new-old-code ""))
1615 (save-excursion
1616 (switch-to-buffer (get-file-buffer fname))
1617 (goto-char (point-min))
1618 (forward-line (1- fline))
1619 (beginning-of-line)
1620 (setf bline (point))
1621 (when (or hs-lint-replace-without-ask
1622 (yes-or-no-p msg))
1623 (end-of-line)
1624 (setf eline (point))
1625 (beginning-of-line)
1626 (setf old-code (regexp-quote old-code))
1627 (while (string-match "\\\\ " old-code spos)
1628 (setf new-old-code (concat new-old-code
1629 (substring old-code spos (match-beginning 0))
1630 "\\ *"))
1631 (setf spos (match-end 0)))
1632 (setf new-old-code (concat new-old-code (substring old-code spos)))
1633 (remove-text-properties bline eline '(composition nil))
1634 (when (re-search-forward new-old-code eline t)
1635 (replace-match new-code nil t)))))))
1636
1637 (defun hs-lint-finish-hook (buf msg)
1638 "Function, that is executed at the end of HLint execution"
1639 (if hs-lint-replace-with-suggestions
1640 (hs-lint-replace-suggestions)
1641 (next-error 1 t)))
1642
1643 (define-compilation-mode hs-lint-mode "HLint"
1644 "Mode for check Haskell source code."
1645 (set (make-local-variable 'compilation-process-setup-function)
1646 'hs-lint-process-setup)
1647 (set (make-local-variable 'compilation-disable-input) t)
1648 (set (make-local-variable 'compilation-scroll-output) nil)
1649 (set (make-local-variable 'compilation-finish-functions)
1650 (list 'hs-lint-finish-hook))
1651 )
1652
1653 (defun hs-lint ()
1654 "Run HLint for current buffer with haskell source"
1655 (interactive)
1656 (save-some-buffers hs-lint-save-files)
1657 (compilation-start (concat hs-lint-command " \"" buffer-file-name "\"")
1658 'hs-lint-mode))
1659
1660 (provide 'hs-lint)
1661 ;;; hs-lint.el ends here
1662 #+end_src
1663
1664 #+begin_src emacs-lisp :tangle no
1665 (use-package hs-lint
1666 :load-path "lisp/"
1667 :bind (:map haskell-mode-map
1668 ("C-c l l" . hs-lint)))
1669 #+end_src
1670
1671 ** Web
1672
1673 *** SGML and HTML
1674
1675 #+begin_src emacs-lisp
1676 (use-package sgml-mode
1677 :config
1678 (setq sgml-basic-offset 2))
1679 #+end_src
1680
1681 *** CSS and SCSS
1682
1683 #+begin_src emacs-lisp
1684 (use-package css-mode
1685 :config
1686 (setq css-indent-offset 2))
1687 #+end_src
1688
1689 *** Web mode
1690
1691 #+begin_src emacs-lisp
1692 (use-package web-mode
1693 :mode "\\.html\\'"
1694 :config
1695 (a/setq-every 2
1696 web-mode-code-indent-offset
1697 web-mode-css-indent-offset
1698 web-mode-markup-indent-offset))
1699 #+end_src
1700
1701 *** Emmet mode
1702
1703 #+begin_src emacs-lisp
1704 (use-package emmet-mode
1705 :after (:any web-mode css-mode sgml-mode)
1706 :bind* (("C-)" . emmet-next-edit-point)
1707 ("C-(" . emmet-prev-edit-point))
1708 :config
1709 (unbind-key "C-j" emmet-mode-keymap)
1710 (setq emmet-move-cursor-between-quotes t)
1711 :hook (web-mode css-mode html-mode sgml-mode))
1712 #+end_src
1713
1714 ** Java
1715
1716 *** COMMENT meghanada
1717
1718 #+begin_src emacs-lisp
1719 (use-package meghanada
1720 :bind
1721 (:map meghanada-mode-map
1722 (("C-M-o" . meghanada-optimize-import)
1723 ("C-M-t" . meghanada-import-all)))
1724 :hook (java-mode . meghanada-mode))
1725 #+end_src
1726
1727 *** COMMENT lsp-java
1728
1729 #+begin_comment
1730 dependencies:
1731
1732 ace-window
1733 avy
1734 bui
1735 company-lsp
1736 dap-mode
1737 lsp-java
1738 lsp-mode
1739 lsp-ui
1740 pfuture
1741 tree-mode
1742 treemacs
1743 #+end_comment
1744
1745 #+begin_src emacs-lisp
1746 (use-package treemacs
1747 :config (setq treemacs-never-persist t))
1748
1749 (use-package yasnippet
1750 :config
1751 ;; (yas-global-mode)
1752 )
1753
1754 (use-package lsp-mode
1755 :init (setq lsp-eldoc-render-all nil
1756 lsp-highlight-symbol-at-point nil)
1757 )
1758
1759 (use-package hydra)
1760
1761 (use-package company-lsp
1762 :after company
1763 :config
1764 (setq company-lsp-cache-candidates t
1765 company-lsp-async t))
1766
1767 (use-package lsp-ui
1768 :config
1769 (setq lsp-ui-sideline-update-mode 'point))
1770
1771 (use-package lsp-java
1772 :config
1773 (add-hook 'java-mode-hook
1774 (lambda ()
1775 (setq-local company-backends (list 'company-lsp))))
1776
1777 (add-hook 'java-mode-hook 'lsp-java-enable)
1778 (add-hook 'java-mode-hook 'flycheck-mode)
1779 (add-hook 'java-mode-hook 'company-mode)
1780 (add-hook 'java-mode-hook 'lsp-ui-mode))
1781
1782 (use-package dap-mode
1783 :after lsp-mode
1784 :config
1785 (dap-mode t)
1786 (dap-ui-mode t))
1787
1788 (use-package dap-java
1789 :after (lsp-java))
1790
1791 (use-package lsp-java-treemacs
1792 :after (treemacs))
1793 #+end_src
1794
1795 *** eclim
1796
1797 #+begin_src emacs-lisp
1798 (use-package eclim
1799 :bind (:map eclim-mode-map ("S-SPC" . company-complete))
1800 :hook ((java-mode . eclim-mode)
1801 (eclim-mode . (lambda ()
1802 (make-local-variable 'company-idle-delay)
1803 (defvar company-idle-delay)
1804 ;; (setq company-idle-delay 0.7)
1805 (setq company-idle-delay nil))))
1806 :custom
1807 (eclim-auto-save nil)
1808 ;; (eclimd-default-workspace "~/src/eclipse-workspace-exp")
1809 (eclim-executable "~/.p2/pool/plugins/org.eclim_2.8.0/bin/eclim")
1810 (eclim-eclipse-dirs '("~/usr/eclipse/dsl-2018-09/eclipse")))
1811 #+end_src
1812
1813 ** geiser
1814
1815 #+begin_src emacs-lisp
1816 (use-package geiser)
1817
1818 (use-feature geiser-guile
1819 :config
1820 (setq geiser-guile-load-path "~/src/git/guix"))
1821 #+end_src
1822
1823 ** guix
1824
1825 #+begin_src emacs-lisp
1826 (use-package guix)
1827 #+end_src
1828
1829 * Emacs enhancements
1830 :PROPERTIES:
1831 :CUSTOM_ID: emacs-enhancements
1832 :END:
1833
1834 ** man
1835
1836 #+begin_src emacs-lisp
1837 (use-feature man
1838 :config (setq Man-width 80))
1839 #+end_src
1840
1841 ** [[https://github.com/justbur/emacs-which-key][which-key]]
1842
1843 #+begin_quote
1844 Emacs package that displays available keybindings in popup
1845 #+end_quote
1846
1847 #+begin_src emacs-lisp
1848 (use-package which-key
1849 :defer 1
1850 :config
1851 (which-key-add-key-based-replacements
1852 ;; prefixes for global prefixes and minor modes
1853 "C-c @" "outline"
1854 "C-c !" "flycheck"
1855 "C-c 8" "typo"
1856 "C-c 8 -" "typo/dashes"
1857 "C-c 8 <" "typo/left-brackets"
1858 "C-c 8 >" "typo/right-brackets"
1859 "C-x 8" "unicode"
1860 "C-x a" "abbrev/expand"
1861 "C-x r" "rectangle/register/bookmark"
1862 "C-x v" "version control"
1863 ;; prefixes for my personal bindings
1864 "C-c a" "applications"
1865 "C-c a s" "shells"
1866 "C-c p" "package-management"
1867 "C-c p e" "package-management/epkg"
1868 "C-c p s" "straight.el"
1869 "C-c psa" "all"
1870 "C-c psp" "package"
1871 "C-c c" "compile-and-comments"
1872 "C-c e" "eval"
1873 "C-c f" "files"
1874 "C-c F" "frames"
1875 "C-S-h" "help(ful)"
1876 "C-c m" "multiple-cursors"
1877 "C-c P" "projectile"
1878 "C-c P s" "projectile/search"
1879 "C-c P x" "projectile/execute"
1880 "C-c P 4" "projectile/other-window"
1881 "C-c q" "boxquote"
1882 "s-g" "magit"
1883 "s-o" "outline"
1884 "s-t" "themes")
1885
1886 ;; prefixes for major modes
1887 (which-key-add-major-mode-key-based-replacements 'message-mode
1888 "C-c f" "footnote")
1889 (which-key-add-major-mode-key-based-replacements 'org-mode
1890 "C-c C-v" "org-babel")
1891 (which-key-add-major-mode-key-based-replacements 'web-mode
1892 "C-c C-a" "web/attributes"
1893 "C-c C-b" "web/blocks"
1894 "C-c C-d" "web/dom"
1895 "C-c C-e" "web/element"
1896 "C-c C-t" "web/tags")
1897
1898 (which-key-mode)
1899 :custom
1900 (which-key-add-column-padding 5)
1901 (which-key-max-description-length 32))
1902 #+end_src
1903
1904 ** theme
1905
1906 #+begin_src emacs-lisp
1907 (add-to-list 'custom-theme-load-path "~/.emacs.d/lisp")
1908 (load-theme 'tangomod t)
1909 #+end_src
1910
1911 ** smart-mode-line
1912
1913 #+begin_src emacs-lisp
1914 (use-package smart-mode-line
1915 :commands (sml/apply-theme)
1916 :demand
1917 :config
1918 (sml/setup))
1919 #+end_src
1920
1921 ** doom-themes
1922
1923 #+begin_src emacs-lisp
1924 (use-package doom-themes)
1925 #+end_src
1926
1927 ** theme helper functions
1928
1929 #+begin_src emacs-lisp
1930 (defvar a/org-mode-font-lock-keywords
1931 '(("[ \t]*\\(#\\+\\(BEGIN\\|END\\|begin\\|end\\)_\\(\\S-+\\)\\)[ \t]*\\([^\n:]*\\)"
1932 (1 '(:foreground "#5a5b5a" :background "#292b2b") t) ; directive
1933 (3 '(:foreground "#81a2be" :background "#292b2b") t) ; kind
1934 (4 '(:foreground "#c5c8c6") t)))) ; title
1935
1936 (defun a/lights-on ()
1937 "Enable my favourite light theme."
1938 (interactive)
1939 (mapc #'disable-theme custom-enabled-themes)
1940 (load-theme 'tangomod t)
1941 (sml/apply-theme 'automatic)
1942 (font-lock-remove-keywords
1943 'org-mode a/org-mode-font-lock-keywords))
1944
1945 (defun a/lights-off ()
1946 "Go dark."
1947 (interactive)
1948 (mapc #'disable-theme custom-enabled-themes)
1949 (load-theme 'doom-tomorrow-night t)
1950 (sml/apply-theme 'automatic)
1951 (font-lock-add-keywords
1952 'org-mode a/org-mode-font-lock-keywords t))
1953
1954 (bind-keys
1955 ("s-t d" . a/lights-off)
1956 ("s-t l" . a/lights-on))
1957 #+end_src
1958
1959 ** [[https://github.com/bbatsov/crux][crux]]
1960
1961 #+begin_src emacs-lisp
1962 (use-package crux ; results in Waiting for git... [2 times]
1963 :defer 1
1964 :bind (("C-c b k" . crux-kill-other-buffers)
1965 ("C-c d" . crux-duplicate-current-line-or-region)
1966 ("C-c D" . crux-duplicate-and-comment-current-line-or-region)
1967 ("C-c f c" . crux-copy-file-preserve-attributes)
1968 ("C-c f d" . crux-delete-file-and-buffer)
1969 ("C-c f r" . crux-rename-file-and-buffer)
1970 ("C-c j" . crux-top-join-line)
1971 ("C-S-j" . crux-top-join-line)))
1972 #+end_src
1973
1974 ** [[https://github.com/alezost/mwim.el][mwim]]
1975
1976 #+begin_src emacs-lisp
1977 (use-package mwim
1978 :bind (("C-a" . mwim-beginning-of-code-or-line)
1979 ("C-e" . mwim-end-of-code-or-line)
1980 ("<home>" . mwim-beginning-of-line-or-code)
1981 ("<end>" . mwim-end-of-line-or-code)))
1982 #+end_src
1983
1984 ** projectile
1985
1986 #+begin_src emacs-lisp
1987 (use-package projectile
1988 :bind-keymap ("C-c P" . projectile-command-map)
1989 :config
1990 (projectile-mode)
1991
1992 (defun my-projectile-invalidate-cache (&rest _args)
1993 ;; ignore the args to `magit-checkout'
1994 (projectile-invalidate-cache nil))
1995
1996 (eval-after-load 'magit-branch
1997 '(progn
1998 (advice-add 'magit-checkout
1999 :after #'my-projectile-invalidate-cache)
2000 (advice-add 'magit-branch-and-checkout
2001 :after #'my-projectile-invalidate-cache)))
2002 :custom (projectile-completion-system 'ivy))
2003 #+end_src
2004
2005 ** [[https://github.com/Wilfred/helpful][helpful]]
2006
2007 #+begin_src emacs-lisp
2008 (use-package helpful
2009 :defer 3
2010 :bind
2011 (("C-S-h c" . helpful-command)
2012 ("C-S-h f" . helpful-callable) ; helpful-function
2013 ("C-S-h v" . helpful-variable)
2014 ("C-S-h k" . helpful-key)
2015 ("C-S-h p" . helpful-at-point)))
2016 #+end_src
2017
2018 ** [[https://github.com/EricCrosson/unkillable-scratch][unkillable-scratch]]
2019
2020 Make =*scratch*= and =*Messages*= unkillable.
2021
2022 #+begin_src emacs-lisp
2023 (use-package unkillable-scratch
2024 :defer 3
2025 :config
2026 (unkillable-scratch 1)
2027 :custom
2028 (unkillable-buffers '("^\\*scratch\\*$" "^\\*Messages\\*$")))
2029 #+end_src
2030
2031 ** [[https://github.com/davep/boxquote.el][boxquote.el]]
2032
2033 #+begin_example
2034 ,----
2035 | make pretty boxed quotes like this
2036 `----
2037 #+end_example
2038
2039 #+begin_src emacs-lisp
2040 (use-package boxquote
2041 :defer 3
2042 :bind
2043 (:prefix-map a/boxquote-prefix-map
2044 :prefix "C-c q"
2045 ("b" . boxquote-buffer)
2046 ("B" . boxquote-insert-buffer)
2047 ("d" . boxquote-defun)
2048 ("F" . boxquote-insert-file)
2049 ("hf" . boxquote-describe-function)
2050 ("hk" . boxquote-describe-key)
2051 ("hv" . boxquote-describe-variable)
2052 ("hw" . boxquote-where-is)
2053 ("k" . boxquote-kill)
2054 ("p" . boxquote-paragraph)
2055 ("q" . boxquote-boxquote)
2056 ("r" . boxquote-region)
2057 ("s" . boxquote-shell-command)
2058 ("t" . boxquote-text)
2059 ("T" . boxquote-title)
2060 ("u" . boxquote-unbox)
2061 ("U" . boxquote-unbox-region)
2062 ("y" . boxquote-yank)
2063 ("M-q" . boxquote-fill-paragraph)
2064 ("M-w" . boxquote-kill-ring-save)))
2065 #+end_src
2066
2067 Also see [[https://www.emacswiki.org/emacs/rebox2][rebox2]].
2068
2069 ** orgalist
2070
2071 #+begin_src emacs-lisp
2072 (use-package orgalist
2073 :after message
2074 :hook (message-mode . orgalist-mode))
2075 #+end_src
2076
2077 ** typo.el
2078
2079 #+begin_src emacs-lisp
2080 (use-package typo
2081 :defer 2
2082 :config
2083 (typo-global-mode 1)
2084 :hook (text-mode . typo-mode))
2085 #+end_src
2086
2087 ** hl-todo
2088
2089 #+begin_src emacs-lisp
2090 (use-package hl-todo
2091 :defer 4
2092 :config
2093 (global-hl-todo-mode))
2094 #+end_src
2095
2096 ** shrink-path
2097
2098 #+begin_src emacs-lisp
2099 (use-package shrink-path
2100 :defer 2
2101 :after eshell
2102 :config
2103 (defun +eshell/prompt ()
2104 (let ((base/dir (shrink-path-prompt default-directory)))
2105 (concat (propertize (car base/dir)
2106 'face 'font-lock-comment-face)
2107 (propertize (cdr base/dir)
2108 'face 'font-lock-constant-face)
2109 (propertize (+eshell--current-git-branch)
2110 'face 'font-lock-function-name-face)
2111 "\n"
2112 ;; "λ"
2113 ;; (propertize "λ" 'face 'eshell-prompt)
2114 ;; needed for the input text to not have prompt face
2115 (propertize "λ " 'face 'default))))
2116
2117 (defun +eshell--current-git-branch ()
2118 (let ((branch (car (loop for match in (split-string (shell-command-to-string "git branch") "\n")
2119 when (string-match "^\*" match)
2120 collect match))))
2121 (if (not (eq branch nil))
2122 (concat " " (substring branch 2))
2123 "")))
2124 (setq eshell-prompt-regexp "\\(.*\n\\)*λ "
2125 eshell-prompt-function #'+eshell/prompt))
2126 #+end_src
2127
2128 ** [[https://github.com/peterwvj/eshell-up][eshell-up]]
2129
2130 #+begin_src emacs-lisp
2131 (use-package eshell-up
2132 :after eshell
2133 :commands eshell-up)
2134 #+end_src
2135
2136 ** multi-term
2137
2138 #+begin_src emacs-lisp
2139 (use-package multi-term
2140 :defer 3
2141 :bind (("C-c a s m" . multi-term-dedicated-toggle)
2142 :map term-mode-map
2143 ("C-c C-j" . term-char-mode)
2144 :map term-raw-map
2145 ("C-c C-j" . term-line-mode))
2146 :config
2147 (setq multi-term-program "/bin/screen"
2148 ;; TODO: add separate bindings for connecting to existing
2149 ;; session vs. always creating a new one
2150 multi-term-dedicated-select-after-open-p t
2151 multi-term-dedicated-window-height 20
2152 multi-term-dedicated-max-window-height 30
2153 term-bind-key-alist
2154 '(("C-c C-c" . term-interrupt-subjob)
2155 ("C-c C-e" . term-send-esc)
2156 ("C-k" . kill-line)
2157 ("C-y" . term-paste)
2158 ("M-f" . term-send-forward-word)
2159 ("M-b" . term-send-backward-word)
2160 ("M-p" . term-send-up)
2161 ("M-n" . term-send-down)
2162 ("<C-backspace>" . term-send-backward-kill-word)
2163 ("<M-DEL>" . term-send-backward-kill-word)
2164 ("M-d" . term-send-delete-word)
2165 ("M-," . term-send-raw)
2166 ("M-." . comint-dynamic-complete))
2167 term-unbind-key-alist
2168 '("C-z" "C-x" "C-c" "C-h" "C-y" "<ESC>")))
2169 #+end_src
2170
2171 ** page-break-lines
2172
2173 #+begin_src emacs-lisp
2174 (use-package page-break-lines
2175 :config
2176 (global-page-break-lines-mode))
2177 #+end_src
2178
2179 ** expand-region
2180
2181 #+begin_src emacs-lisp
2182 (use-package expand-region
2183 :bind ("C-=" . er/expand-region))
2184 #+end_src
2185
2186 ** multiple-cursors
2187
2188 #+begin_src emacs-lisp
2189 (use-package multiple-cursors
2190 :bind
2191 (("C-S-<mouse-1>" . mc/add-cursor-on-click)
2192 (:prefix-map a/mc-prefix-map
2193 :prefix "C-c m"
2194 ("c" . mc/edit-lines)
2195 ("n" . mc/mark-next-like-this)
2196 ("p" . mc/mark-previous-like-this)
2197 ("a" . mc/mark-all-like-this))))
2198 #+end_src
2199
2200 ** forge
2201
2202 #+begin_src emacs-lisp
2203 (use-package forge
2204 :after magit
2205 :demand)
2206 #+end_src
2207
2208 ** yasnippet
2209
2210 #+begin_src emacs-lisp
2211 (use-package yasnippet
2212 :defer 3
2213 :config
2214 (defconst yas-verbosity-cur yas-verbosity)
2215 (setq yas-verbosity 2)
2216 (add-to-list 'yas-snippet-dirs "~/src/git/guix/etc/snippets")
2217 (yas-reload-all)
2218 (setq yas-verbosity yas-verbosity-cur)
2219 :hook
2220 (text-mode . yas-minor-mode))
2221 #+end_src
2222
2223 * Email
2224 :PROPERTIES:
2225 :CUSTOM_ID: email
2226 :END:
2227
2228 #+begin_src emacs-lisp
2229 (defvar a/maildir (expand-file-name "~/mail/"))
2230 (with-eval-after-load 'recentf
2231 (add-to-list 'recentf-exclude a/maildir))
2232 #+end_src
2233
2234 ** Gnus
2235
2236 #+begin_src emacs-lisp
2237 (setq
2238 a/gnus-init-file (no-littering-expand-etc-file-name "gnus")
2239 mail-user-agent 'gnus-user-agent
2240 read-mail-command 'gnus)
2241
2242 (use-feature gnus
2243 :bind (("s-m" . gnus)
2244 ("s-M" . gnus-unplugged))
2245 :init
2246 (setq
2247 gnus-select-method '(nnnil "")
2248 gnus-secondary-select-methods
2249 '((nnimap "amin"
2250 (nnimap-stream plain)
2251 (nnimap-address "127.0.0.1")
2252 (nnimap-server-port 143)
2253 (nnimap-authenticator plain)
2254 (nnimap-user "amin@aminb.org"))
2255 (nnimap "uwaterloo"
2256 (nnimap-stream plain)
2257 (nnimap-address "127.0.0.1")
2258 (nnimap-server-port 143)
2259 (nnimap-authenticator plain)
2260 (nnimap-user "abandali@uwaterloo.ca")))
2261 gnus-message-archive-group "nnimap+amin:Sent"
2262 gnus-parameters
2263 '(("gnu.*"
2264 (gcc-self . t)))
2265 gnus-large-newsgroup 50
2266 gnus-home-directory (no-littering-expand-var-file-name "gnus/")
2267 gnus-directory (concat gnus-home-directory "news/")
2268 message-directory (concat gnus-home-directory "mail/")
2269 nndraft-directory (concat gnus-home-directory "drafts/")
2270 gnus-save-newsrc-file nil
2271 gnus-read-newsrc-file nil
2272 gnus-interactive-exit nil
2273 gnus-gcc-mark-as-read t)
2274 :config
2275 (require 'ebdb)
2276 (require 'ebdb-mua)
2277 (require 'ebdb-gnus))
2278
2279 (use-feature gnus-art
2280 :config
2281 (setq
2282 gnus-visible-headers
2283 (concat gnus-visible-headers "\\|^List-Id:\\|^X-RT-Originator:\\|^User-Agent:")
2284 gnus-sorted-header-list
2285 '("^From:" "^Subject:" "^Summary:" "^Keywords:"
2286 "^Followup-To:" "^To:" "^Cc:" "X-RT-Originator"
2287 "^Newsgroups:" "List-Id:" "^Organization:"
2288 "^User-Agent:" "^Date:")
2289 ;; local-lapsed article dates
2290 ;; from https://www.emacswiki.org/emacs/GnusFormatting#toc11
2291 gnus-article-date-headers '(user-defined)
2292 gnus-article-time-format
2293 (lambda (time)
2294 (let* ((date (format-time-string "%a, %d %b %Y %T %z" time))
2295 (local (article-make-date-line date 'local))
2296 (combined-lapsed (article-make-date-line date
2297 'combined-lapsed))
2298 (lapsed (progn
2299 (string-match " (.+" combined-lapsed)
2300 (match-string 0 combined-lapsed))))
2301 (concat local lapsed))))
2302 (bind-keys
2303 :map gnus-article-mode-map
2304 ("r" . gnus-article-reply-with-original)
2305 ("R" . gnus-article-wide-reply-with-original)
2306 ("M-L" . org-store-link)))
2307
2308 (use-feature gnus-sum
2309 :bind (:map gnus-summary-mode-map
2310 :prefix-map a/gnus-summary-prefix-map
2311 :prefix "v"
2312 ("r" . gnus-summary-reply)
2313 ("w" . gnus-summary-wide-reply)
2314 ("v" . gnus-summary-show-raw-article))
2315 :config
2316 (bind-keys
2317 :map gnus-summary-mode-map
2318 ("r" . gnus-summary-reply-with-original)
2319 ("R" . gnus-summary-wide-reply-with-original)
2320 ("M-L" . org-store-link))
2321 :hook (gnus-summary-mode . a/no-mouse-autoselect-window))
2322
2323 (use-feature gnus-msg
2324 :config
2325 (setq gnus-posting-styles
2326 '((".*"
2327 (address "amin@aminb.org")
2328 (body "\nBest,\namin\n")
2329 (eval (setq a/message-cite-say-hi t)))
2330 ("gnu.*"
2331 (address "bandali@gnu.org"))
2332 ((header "subject" "ThankCRM")
2333 (to "webmasters-comment@gnu.org")
2334 (body "\nAdded to 2019supporters.html.\n\nMoving to campaigns.\n\n-amin\n")
2335 (eval (setq a/message-cite-say-hi nil)))
2336 ("nnimap\\+uwaterloo:.*"
2337 (address "abandali@uwaterloo.ca")
2338 (gcc "\"nnimap+uwaterloo:Sent Items\"")))))
2339
2340 (use-feature gnus-topic
2341 :hook (gnus-group-mode . gnus-topic-mode))
2342
2343 (use-feature gnus-agent
2344 :config
2345 (setq gnus-agent-synchronize-flags 'ask)
2346 :hook (gnus-group-mode . gnus-agent-mode))
2347
2348 (use-feature gnus-group
2349 :config
2350 (setq gnus-permanently-visible-groups "\\((INBOX\\|gnu$\\)"))
2351
2352 (use-feature mm-decode
2353 :config
2354 (setq mm-discouraged-alternatives '("text/html" "text/richtext")))
2355 #+end_src
2356
2357 ** sendmail
2358
2359 #+begin_src emacs-lisp
2360 (use-feature sendmail
2361 :config
2362 (setq sendmail-program "/usr/bin/msmtp"
2363 ;; message-sendmail-extra-arguments '("-v" "-d")
2364 mail-specify-envelope-from t
2365 mail-envelope-from 'header))
2366 #+end_src
2367
2368 ** message
2369
2370 #+begin_src emacs-lisp
2371 (use-feature message
2372 :config
2373 (defconst a/message-cite-style-format "On %Y-%m-%d %l:%M %p, %N wrote:")
2374 (defconst message-cite-style-bandali
2375 '((message-cite-function 'message-cite-original)
2376 (message-citation-line-function 'message-insert-formatted-citation-line)
2377 (message-cite-reply-position 'traditional)
2378 (message-yank-prefix "> ")
2379 (message-yank-cited-prefix ">")
2380 (message-yank-empty-prefix ">")
2381 (message-citation-line-format
2382 (if a/message-cite-say-hi
2383 (concat "Hi %F,\n\n" a/message-cite-style-format)
2384 a/message-cite-style-format)))
2385 "Citation style based on Mozilla Thunderbird's. Use with message-cite-style.")
2386 (setq message-cite-style 'message-cite-style-bandali
2387 message-kill-buffer-on-exit t
2388 message-send-mail-function 'message-send-mail-with-sendmail
2389 message-sendmail-envelope-from 'header
2390 message-dont-reply-to-names
2391 "\\(\\(.*@aminb\\.org\\)\\|\\(amin@bandali\\.me\\)\\|\\(\\(aminb?\\|mab\\|bandali\\)@gnu\\.org\\)\\|\\(\\(m\\|a\\(min\\.\\)?\\)bandali@uwaterloo\\.ca\\)\\)"
2392 message-user-fqdn "aminb.org")
2393 (require 'company-ebdb)
2394 :hook (;; (message-setup . mml-secure-message-sign-pgpmime)
2395 (message-mode . flyspell-mode)
2396 (message-mode . (lambda ()
2397 ;; (setq fill-column 65
2398 ;; message-fill-column 65)
2399 (make-local-variable 'company-idle-delay)
2400 (setq company-idle-delay 0.2))))
2401 ;; :custom-face
2402 ;; (message-header-subject ((t (:foreground "#111" :weight semi-bold))))
2403 ;; (message-header-to ((t (:foreground "#111" :weight normal))))
2404 ;; (message-header-cc ((t (:foreground "#333" :weight normal))))
2405 )
2406
2407 (with-eval-after-load 'mml-sec
2408 (setq mml-secure-openpgp-encrypt-to-self t
2409 mml-secure-openpgp-sign-with-sender t))
2410 #+end_src
2411
2412 ** footnote
2413
2414 Convenient footnotes in =message-mode=.
2415
2416 #+begin_src emacs-lisp
2417 (use-feature footnote
2418 :after message
2419 :bind
2420 (:map message-mode-map
2421 :prefix-map a/footnote-prefix-map
2422 :prefix "C-c f"
2423 ("a" . footnote-add-footnote)
2424 ("b" . footnote-back-to-message)
2425 ("c" . footnote-cycle-style)
2426 ("d" . footnote-delete-footnote)
2427 ("g" . footnote-goto-footnote)
2428 ("r" . footnote-renumber-footnotes)
2429 ("s" . footnote-set-style))
2430 :config
2431 (setq footnote-start-tag ""
2432 footnote-end-tag ""
2433 footnote-style 'unicode))
2434 #+end_src
2435
2436 ** ebdb
2437
2438 #+begin_src emacs-lisp
2439 (use-package ebdb
2440 :straight (:host github :repo "girzel/ebdb")
2441 :after gnus
2442 :bind (:map gnus-group-mode-map ("e" . ebdb))
2443 :config
2444 (setq ebdb-sources (no-littering-expand-var-file-name "ebdb"))
2445 (with-eval-after-load 'swiper
2446 (add-to-list 'swiper-font-lock-exclude 'ebdb-mode t)))
2447
2448 (use-feature ebdb-com
2449 :after ebdb)
2450
2451 ;; (use-package ebdb-complete
2452 ;; :after ebdb
2453 ;; :config
2454 ;; (ebdb-complete-enable))
2455
2456 (use-package company-ebdb
2457 :config
2458 (defun company-ebdb--post-complete (_) nil))
2459
2460 (use-feature ebdb-gnus
2461 :after ebdb
2462 :custom
2463 (ebdb-gnus-window-configuration
2464 '(article
2465 (vertical 1.0
2466 (summary 0.25 point)
2467 (horizontal 1.0
2468 (article 1.0)
2469 (ebdb-gnus 0.3))))))
2470
2471 (use-feature ebdb-mua
2472 :after ebdb
2473 ;; :custom (ebdb-mua-pop-up nil)
2474 )
2475
2476 ;; (use-package ebdb-message
2477 ;; :after ebdb)
2478
2479
2480 ;; (use-package ebdb-vcard
2481 ;; :after ebdb)
2482 #+end_src
2483
2484 ** message-x
2485
2486 #+begin_src emacs-lisp
2487 (use-package message-x)
2488 #+end_src
2489
2490 #+begin_src emacs-lisp :tangle no
2491 (use-package message-x
2492 :custom
2493 (message-x-completion-alist
2494 (quote
2495 (("\\([rR]esent-\\|[rR]eply-\\)?[tT]o:\\|[bB]?[cC][cC]:" . gnus-harvest-find-address)
2496 ((if
2497 (boundp
2498 (quote message-newgroups-header-regexp))
2499 message-newgroups-header-regexp message-newsgroups-header-regexp)
2500 . message-expand-group)))))
2501 #+end_src
2502
2503 ** COMMENT gnus-harvest
2504
2505 #+begin_src emacs-lisp
2506 (use-package gnus-harvest
2507 :commands gnus-harvest-install
2508 :demand t
2509 :config
2510 (if (featurep 'message-x)
2511 (gnus-harvest-install 'message-x)
2512 (gnus-harvest-install)))
2513 #+end_src
2514
2515 * Blogging
2516 :PROPERTIES:
2517 :CUSTOM_ID: blogging
2518 :END:
2519
2520 ** [[https://ox-hugo.scripter.co][ox-hugo]]
2521
2522 #+begin_src emacs-lisp
2523 (use-package ox-hugo
2524 :after ox
2525 :demand)
2526 #+end_src
2527
2528 * Post initialization
2529 :PROPERTIES:
2530 :CUSTOM_ID: post-initialization
2531 :END:
2532
2533 Display how long it took to load the init file.
2534
2535 #+begin_src emacs-lisp
2536 (message "Loading %s...done (%.3fs)" user-init-file
2537 (float-time (time-subtract (current-time)
2538 a/before-user-init-time)))
2539 #+end_src
2540
2541 * Footer
2542 :PROPERTIES:
2543 :CUSTOM_ID: footer
2544 :END:
2545
2546 #+begin_src emacs-lisp :comments none
2547 ;;; init.el ends here
2548 #+end_src
2549
2550 * COMMENT Local Variables :ARCHIVE:
2551 # Local Variables:
2552 # eval: (add-hook 'after-save-hook #'a/async-babel-tangle 'append 'local)
2553 # eval: (when (featurep 'typo (typo-mode -1)))
2554 # End: