1 #+title: =aminb='s Literate Emacs Configuration
4 #+property: header-args :tangle yes
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/emacscollective/borg][Borg]]. Over the years, I've taken inspiration from configurations of
14 many different people. Some of the configurations that I can remember
15 off the top of my head are:
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
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]]
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 Borg. For what it's worth, I briefly
32 experimented with [[https://github.com/raxod502/straight.el][straight.el]], but found that it added about 2 seconds
33 to my init time; which is unacceptable for me: I use Emacs as my
34 window manager (via EXWM) and coming from bspwm, I'm too used to
35 having fast startup times.
39 To use this config for your Emacs, first you need to clone this repo,
40 then bootstrap Borg, tell Borg to retrieve package submodules, and
41 byte-compiled the packages. Something along these lines should work:
43 #+begin_src sh :tangle no
44 git clone https://github.com/aminb/dotfiles ~/.emacs.d
51 * Contents :toc_1:noexport:
55 - [[#initial-setup][Initial setup]]
57 - [[#post-initialization][Post initialization]]
67 #+begin_src emacs-lisp :comments none
68 ;;; init.el --- Amin Bandali's Emacs config -*- lexical-binding: t ; eval: (view-mode 1)-*-
71 Enable =view-mode=, which both makes the file read-only (as a reminder
72 that =init.el= is an auto-generated file, not supposed to be edited),
73 and provides some convenient key bindings for browsing through the
78 #+begin_src emacs-lisp :comments none
79 ;; Copyright (C) 2018 Amin Bandali <amin@aminb.org>
81 ;; This program is free software: you can redistribute it and/or modify
82 ;; it under the terms of the GNU General Public License as published by
83 ;; the Free Software Foundation, either version 3 of the License, or
84 ;; (at your option) any later version.
86 ;; This program is distributed in the hope that it will be useful,
87 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
88 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89 ;; GNU General Public License for more details.
91 ;; You should have received a copy of the GNU General Public License
92 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
97 #+begin_src emacs-lisp :comments none
100 ;; Emacs configuration of Amin Bandali, computer scientist and functional
103 ;; THIS FILE IS AUTO-GENERATED FROM `init.org'.
106 ** Naming conventions
108 The conventions below were inspired by [[https://github.com/hlissner/doom-emacs][Doom]]'s, found [[https://github.com/hlissner/doom-emacs/blob/5dacbb7cb1c6ac246a9ccd15e6c4290def67757c/core/core.el#L3-L17][here]].
110 #+begin_src emacs-lisp :comments none
111 ;; Naming conventions:
113 ;; amin-... public variables or non-interactive functions
114 ;; amin--... private anything (non-interactive), not safe for direct use
115 ;; amin/... an interactive function; safe for M-x or keybinding
116 ;; amin:... an evil operator, motion, or command
117 ;; amin|... a hook function
118 ;; amin*... an advising function
119 ;; amin@... a hydra command
125 :CUSTOM_ID: initial-setup
128 #+begin_src emacs-lisp :comments none
132 ** Emacs initialization
134 I'd like to do a couple of measurements of Emacs' startup time. First,
135 let's see how long Emacs takes to start up, before even loading
136 =init.el=, i.e. =user-init-file=:
138 #+begin_src emacs-lisp
139 (defvar amin--before-user-init-time (current-time)
140 "Value of `current-time' when Emacs begins loading `user-init-file'.")
141 (message "Loading Emacs...done (%.3fs)"
142 (float-time (time-subtract amin--before-user-init-time
146 Also, temporarily increase ~gc-cons-threshhold~ and
147 ~gc-cons-percentage~ during startup to reduce garbage collection
148 frequency. Clearing the ~file-name-handler-alist~ seems to help reduce
149 startup time as well.
151 #+begin_src emacs-lisp
152 (defvar amin--gc-cons-threshold gc-cons-threshold)
153 (defvar amin--gc-cons-percentage gc-cons-percentage)
154 (defvar amin--file-name-handler-alist file-name-handler-alist)
155 (setq gc-cons-threshold (* 400 1024 1024) ; 400 MiB
156 gc-cons-percentage 0.6
157 file-name-handler-alist nil
158 ;; sidesteps a bug when profiling with esup
159 esup-child-profile-require-level 0)
162 Of course, we'd like to set them back to their defaults once we're
165 #+begin_src emacs-lisp
169 (setq gc-cons-threshold amin--gc-cons-threshold
170 gc-cons-percentage amin--gc-cons-percentage
171 file-name-handler-alist amin--file-name-handler-alist)))
174 Increase the number of lines kept in message logs (the =*Messages*=
177 #+begin_src emacs-lisp
178 (setq message-log-max 20000)
181 Optionally, we could suppress some byte compiler warnings like below,
182 but for now I've decided to keep them enabled. See documentation for
183 ~byte-compile-warnings~ for more details.
185 #+begin_src emacs-lisp
186 ;; (setq byte-compile-warnings
187 ;; '(not free-vars unresolved noruntime lexical make-local))
192 #+begin_src emacs-lisp
193 (setq user-full-name "Amin Bandali"
194 user-mail-address "amin@aminb.org")
197 ** Package management
201 I can do all my package management things with Borg, and don't need
202 Emacs' built-in =package.el=. Emacs 27 lets us disable =package.el= in
203 the =early-init-file= (see [[https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=24acb31c04b4048b85311d794e600ecd7ce60d3b][here]]).
205 #+begin_src emacs-lisp :tangle early-init.el
206 (setq package-enable-at-startup nil)
209 But since Emacs 27 isn't out yet (Emacs 26 is just around the corner
210 right now), and even when released it'll be long before most distros
211 ship in their repos, I'll still put the old workaround with the
212 commented call to ~package-initialize~ here anyway.
214 #+begin_src emacs-lisp
215 (setq package-enable-at-startup nil)
216 ;; (package-initialize)
222 Assimilate Emacs packages as Git submodules
225 [[https://github.com/emacscollective/borg][Borg]] is at the heart of package management of my Emacs setup. In
226 short, it creates a git submodule in =lib/= for each package, which
227 can then be managed with the help of Magit or other tools.
229 #+begin_src emacs-lisp
230 (setq user-init-file (or load-file-name buffer-file-name)
231 user-emacs-directory (file-name-directory user-init-file))
232 (add-to-list 'load-path
233 (expand-file-name "lib/borg" user-emacs-directory))
237 (with-eval-after-load 'bind-key
238 ; unbind M-m for use as a personal prefix
239 (unbind-key "M-m" global-map)
240 (bind-key "M-m M-m" 'back-to-indentation)
241 ; add some bindings for Borg
244 ("M-m B A" . borg-activate)
245 ("M-m B a" . borg-assimilate)
246 ("M-m B b" . borg-build)
247 ("M-m B c" . borg-clone)))
253 A use-package declaration for simplifying your .emacs
256 [[https://github.com/jwiegley/use-package][use-package]] is an awesome utility for managing and configuring
257 packages (in our case especially the latter) in a neatly organized way
258 and without compromising on performance.
260 #+begin_src emacs-lisp
261 (require 'use-package)
262 (if nil ; set to t when need to debug init
263 (setq use-package-verbose t
264 use-package-expand-minimally nil
265 use-package-compute-statistics t
267 (setq use-package-verbose nil
268 use-package-expand-minimally t))
274 Browse the Emacsmirror package database
277 Epkg provides access to a local copy of the [[https://emacsmirror.net][Emacsmirror]] package
278 database, low-level functions for querying the database, and a
279 =package.el=-like user interface for browsing the available packages.
281 #+begin_src emacs-lisp
285 (("M-m B d" . epkg-describe-package)
286 ("M-m B p" . epkg-list-packages)
287 ("M-m B r" . borg-remove)
288 ("M-m B u" . epkg-update)))
291 ** No littering in =~/.emacs.d=
294 Help keeping ~/.emacs.d clean
297 By default, even for Emacs' built-in packages, the configuration files
298 and persistent data are all over the place. Use =no-littering= to help
301 #+begin_src emacs-lisp
302 (use-package no-littering
306 (add-to-list 'savehist-additional-variables 'kill-ring)
308 (setq auto-save-file-name-transforms
309 `((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))
312 ** Custom file (=custom.el=)
314 I'm not planning on using the custom file much, but even so, I
315 definitely don't want it mixing with =init.el=. So, here; let's give
316 it it's own file. While at it, treat themes as safe.
318 #+begin_src emacs-lisp
322 (setq custom-file (no-littering-expand-etc-file-name "custom.el"))
323 (when (file-exists-p custom-file)
325 (setf custom-safe-themes t))
328 ** Better =$PATH= handling
330 Let's use [[https://github.com/purcell/exec-path-from-shell][exec-path-from-shell]] to make Emacs use the =$PATH= as set up
333 #+begin_src emacs-lisp
334 (use-package exec-path-from-shell
337 (setq exec-path-from-shell-check-startup-files nil)
339 (exec-path-from-shell-initialize)
340 ;; while we're at it, let's fix access to our running ssh-agent
341 (exec-path-from-shell-copy-env "SSH_AGENT_PID")
342 (exec-path-from-shell-copy-env "SSH_AUTH_SOCK"))
345 ** Only one custom theme at a time
347 #+begin_src emacs-lisp
348 (defadvice load-theme (before clear-previous-themes activate)
349 "Clear existing theme settings instead of layering them"
350 (mapc #'disable-theme custom-enabled-themes))
355 Start server if not already running. Alternatively, can be done by
356 issuing =emacs --daemon= in the terminal, which can be automated with
357 a systemd service or using =brew services start emacs= on macOS. I use
358 Emacs as my window manager (via EXWM), so I always start Emacs on
359 login; so starting the server from inside Emacs is good enough for me.
361 See [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server][Using Emacs as a Server]].
363 #+begin_src emacs-lisp
365 :config (or (server-running-p) (server-mode)))
370 Font stack with better unicode support, around =Ubuntu Mono= and
373 #+begin_src emacs-lisp
374 (dolist (ft (fontset-list))
378 (font-spec :name "Ubuntu Mono"))
382 (font-spec :name "DejaVu Sans Mono")
389 ;; :name "Symbola monospacified for DejaVu Sans Mono")
395 ;; (font-spec :name "DejaVu Sans Mono")
401 (font-spec :name "DejaVu Sans Mono" :size 14)
408 #+begin_src emacs-lisp
415 #+begin_src emacs-lisp
416 (defun amin-enlist (exp)
417 "Return EXP wrapped in a list, or as-is if already a list."
418 (if (listp exp) exp (list exp)))
420 ; from https://github.com/hlissner/doom-emacs/commit/589108fdb270f24a98ba6209f6955fe41530b3ef
421 (defmacro after! (features &rest body)
422 "A smart wrapper around `with-eval-after-load'. Supresses warnings during
424 (declare (indent defun) (debug t))
425 (list (if (or (not (bound-and-true-p byte-compile-current-file))
426 (dolist (next (amin-enlist features))
428 (require next nil :no-error)
429 (load next :no-message :no-error))))
432 (cond ((symbolp features)
433 `(eval-after-load ',features '(progn ,@body)))
434 ((and (consp features)
435 (memq (car features) '(:or :any)))
437 ,@(cl-loop for next in (cdr features)
438 collect `(after! ,next ,@body))))
439 ((and (consp features)
440 (memq (car features) '(:and :all)))
441 (dolist (next (cdr features))
442 (setq body `(after! ,next ,@body)))
445 `(after! (:all ,@features) ,@body)))))
455 *** Time and battery in mode-line
457 Enable displaying time and battery in the mode-line, since I'm not
458 using the Xfce panel anymore. Also, I don't need to see the load
459 average on a regular basis, so disable that.
461 Note: using =i3status= on sway at the moment, so disabling this.
463 #+begin_src emacs-lisp :tangle no
466 (setq display-time-default-load-average nil)
472 (display-battery-mode))
477 Might want to set the fringe to a smaller value, especially if using
478 EXWM. I'm fine with the default for now.
480 #+begin_src emacs-lisp
481 ;; (fringe-mode '(3 . 1))
485 *** Disable disabled commands
487 Emacs disables some commands by default that could persumably be
488 confusing for novice users. Let's disable that.
490 #+begin_src emacs-lisp
491 (setq disabled-command-function nil)
496 Save what I copy into clipboard from other applications into Emacs'
497 kill-ring, which would allow me to still be able to easily access it
498 in case I kill (cut or copy) something else inside Emacs before
499 yanking (pasting) what I'd originally intended to.
501 #+begin_src emacs-lisp
502 (setq save-interprogram-paste-before-kill t)
507 #+begin_src emacs-lisp
508 (setq enable-recursive-minibuffers t
509 resize-mini-windows t)
512 *** Lazy-person-friendly yes/no prompts
514 Lazy people would prefer to type fewer keystrokes, especially for yes
515 or no questions. I'm lazy.
517 #+begin_src emacs-lisp
518 (defalias 'yes-or-no-p #'y-or-n-p)
521 *** Startup screen and =*scratch*=
523 Firstly, let Emacs know that I'd like to have =*scratch*= as my
526 #+begin_src emacs-lisp
527 (setq initial-buffer-choice t)
530 Now let's customize the =*scratch*= buffer a bit. First off, I don't
531 need the default hint.
533 #+begin_src emacs-lisp
534 (setq initial-scratch-message nil)
537 Also, let's use Text mode as the major mode, in case I want to
538 customize it (=*scratch*='s default major mode, Fundamental mode,
539 can't really be customized).
541 #+begin_src emacs-lisp
542 (setq initial-major-mode 'text-mode)
545 Inhibit the buffer list when more than 2 files are loaded.
547 #+begin_src emacs-lisp
548 (setq inhibit-startup-buffer-menu t)
551 I don't really need to see the startup screen or echo area message
554 #+begin_src emacs-lisp
555 (advice-add #'display-startup-echo-area-message :override #'ignore)
556 (setq inhibit-startup-screen t
557 inhibit-startup-echo-area-message user-login-name)
560 *** More useful frame titles
562 Show either the file name or the buffer name (in case the buffer isn't
563 visiting a file). Borrowed from Emacs Prelude.
565 #+begin_src emacs-lisp
566 (setq frame-title-format
567 '("" invocation-name " - "
568 (:eval (if (buffer-file-name)
569 (abbreviate-file-name (buffer-file-name))
575 Emacs' default backup settings aren't that great. Let's use more
576 sensible options. See documentation for the ~make-backup-file~
579 #+begin_src emacs-lisp
580 (setq backup-by-copying t
586 Enable automatic reloading of changed buffers and files.
588 #+begin_src emacs-lisp
589 (global-auto-revert-mode 1)
590 (setq auto-revert-verbose nil
591 global-auto-revert-non-file-buffers t)
594 *** Always use space for indentation
596 #+begin_src emacs-lisp
599 require-final-newline t
605 Enable =winner-mode=.
607 #+begin_src emacs-lisp
613 #+begin_src emacs-lisp :tangle no
616 ("M-m b b" . ibuffer-list-buffers)
617 ("M-m b k" . kill-this-buffer)
618 ("M-m b s" . save-buffer)
621 ("M-m h c" . describe-char)
622 ("M-m h f" . describe-function)
623 ("M-m h F" . describe-face)
625 ("M-m h k" . describe-key)
626 ("M-m h l" . view-lossage)
627 ("M-m h m" . describe-mode)
628 ("M-m h v" . describe-variable)
630 ("M-m o" . other-window)
631 ("M-m w o" . other-window)
633 ("M-m q q" . save-buffers-kill-terminal))
638 The packages in this section are absolutely essential to my everyday
639 workflow, and they play key roles in how I do my computing. They
640 immensely enhance the Emacs experience for me; both using Emacs, and
643 *** [[https://github.com/emacscollective/auto-compile][auto-compile]]
645 #+begin_src emacs-lisp
646 (use-package auto-compile
649 (auto-compile-on-load-mode)
650 (auto-compile-on-save-mode)
651 (setq auto-compile-display-buffer nil
652 auto-compile-mode-line-counter t
653 auto-compile-source-recreate-deletes-dest t
654 auto-compile-toggle-deletes-nonlib-dest t
655 auto-compile-update-autoloads t)
656 (add-hook 'auto-compile-inhibit-compile-hook
657 'auto-compile-inhibit-compile-detached-git-head))
660 *** [[https://orgmode.org/][Org mode]]
663 Org mode is for keeping notes, maintaining TODO lists, planning
664 projects, and authoring documents with a fast and effective plain-text
668 In short, my favourite way of life.
670 #+begin_src emacs-lisp
673 (setq org-src-tab-acts-natively t
674 org-src-preserve-indentation nil
675 org-edit-src-content-indentation 0)
676 :hook (org-mode . org-indent-mode))
678 (use-package org-notmuch
679 :after (:any org notmuch))
682 *** [[https://magit.vc/][Magit]]
685 It's Magit! A Git porcelain inside Emacs.
688 Not just how I do git, but /the/ way to do git.
690 #+begin_src emacs-lisp
694 (("s-g" . magit-dispatch-popup)
695 ("C-x g" . magit-status)
696 :prefix-map amin--magit-prefix-map
698 ("SPC" . magit-status)
700 ("S" . magit-status-prefix)
706 ("c c" . magit-commit)
707 ("c a" . magit-commit-amend)
708 ("b b" . magit-checkout)
709 ("b c" . magit-branch))
711 (magit-add-section-hook 'magit-status-sections-hook
712 'magit-insert-modules
713 'magit-insert-stashes
717 *** [[https://github.com/abo-abo/swiper][Ivy]] (and friends)
720 Ivy - a generic completion frontend for Emacs, Swiper - isearch with
721 an overview, and more. Oh, man!
724 There's no way I could top that, so I won't attempt to.
728 #+begin_src emacs-lisp
732 (("M-m ," . ivy-switch-buffer)
733 :map ivy-minibuffer-map
734 ([escape] . keyboard-escape-quit)
735 ([S-up] . ivy-previous-history-element)
736 ([S-down] . ivy-next-history-element)
737 ("DEL" . ivy-backward-delete-char))
745 #+begin_src emacs-lisp
747 :bind (([remap isearch-forward] . swiper)
748 ([remap isearch-backward] . swiper)))
753 #+begin_src emacs-lisp
756 :bind (([remap execute-extended-command] . counsel-M-x)
757 ([remap find-file] . counsel-find-file)
758 ("s-r" . counsel-recentf)
759 ("M-m SPC" . counsel-M-x)
760 ("M-m ." . counsel-find-file)
761 ("M-m f r" . counsel-recentf)
762 :map minibuffer-local-map
763 ("C-r" . counsel-minibuffer-history))
766 (defalias 'locate #'counsel-locate))
769 * Borg's =layer/essentials=
771 TODO: break this giant source block down into individual org sections.
773 #+begin_src emacs-lisp
775 :config (dash-enable-font-lock))
779 (setq diff-hl-draw-borders nil)
780 (global-diff-hl-mode)
781 (add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh t))
785 :config (setq dired-listing-switches "-alh"))
788 :when (version< "25" emacs-version)
789 :config (global-eldoc-mode))
793 :config (temp-buffer-resize-mode))
796 (setq isearch-allow-scroll t))
798 (use-package lisp-mode
800 (add-hook 'emacs-lisp-mode-hook 'outline-minor-mode)
801 (add-hook 'emacs-lisp-mode-hook 'reveal-mode)
802 (defun indent-spaces-mode ()
803 (setq indent-tabs-mode nil))
804 (add-hook 'lisp-interaction-mode-hook #'indent-spaces-mode))
808 :config (setq Man-width 80))
811 :config (show-paren-mode))
813 (use-package prog-mode
814 :config (global-prettify-symbols-mode)
815 (defun indicate-buffer-boundaries-left ()
816 (setq indicate-buffer-boundaries 'left))
817 (add-hook 'prog-mode-hook #'indicate-buffer-boundaries-left))
821 :config (add-to-list 'recentf-exclude "^/\\(?:ssh\\|su\\|sudo\\)?:"))
823 (use-package savehist
824 :config (savehist-mode))
826 (use-package saveplace
827 :when (version< "25" emacs-version)
828 :config (save-place-mode))
831 :config (column-number-mode))
834 (add-hook 'text-mode-hook #'indicate-buffer-boundaries-left))
839 (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
840 (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
841 (add-to-list 'tramp-default-proxies-alist
842 (list (regexp-quote (system-name)) nil nil)))
844 (use-package undo-tree
845 :bind (("C-?" . undo-tree-undo)
846 ("M-_" . undo-tree-redo))
848 (global-undo-tree-mode)
849 (setq undo-tree-mode-lighter ""
850 undo-tree-auto-save-history t))
857 #+begin_src emacs-lisp
861 (:map company-active-map
862 ([tab] . company-complete-common-or-cycle))
864 (company-idle-delay 0.3)
865 (company-minimum-prefix-length 1)
866 (company-selection-wrap-around t)
867 (company-dabbrev-char-regexp "\\sw\\|\\s_\\|[-_]")
869 (global-company-mode t))
872 * Syntax and spell checking
873 #+begin_src emacs-lisp
874 (use-package flycheck
875 :hook (prog-mode . flycheck-mode)
877 ;; Use the load-path from running Emacs when checking elisp files
878 (setq flycheck-emacs-lisp-load-path 'inherit)
880 ;; Only flycheck when I actually save the buffer
881 (setq flycheck-check-syntax-automatically '(mode-enabled save)))
885 ** [[http://alloytools.org][Alloy]] (with [[https://github.com/dwwmmn/alloy-mode][alloy-mode]])
887 #+begin_src emacs-lisp
888 (use-package alloy-mode
889 :config (setq alloy-basic-offset 2))
892 ** [[https://coq.inria.fr][Coq]] (with [[https://github.com/ProofGeneral/PG][Proof General]])
894 #+begin_src emacs-lisp
895 (use-package proof-site ; Proof General
896 :load-path "lib/proof-site/generic/")
899 ** [[https://leanprover.github.io][Lean]] (with [[https://github.com/leanprover/lean-mode][lean-mode]])
901 #+begin_src emacs-lisp
902 (use-package lean-mode
903 :bind (:map lean-mode-map
904 ("S-SPC" . company-complete)))
909 *** [[https://github.com/haskell/haskell-mode][haskell-mode]]
911 #+begin_src emacs-lisp
912 (use-package haskell-mode
914 (setq haskell-indentation-layout-offset 4
915 haskell-indentation-left-offset 4
916 flycheck-checker 'haskell-hlint
917 flycheck-disabled-checkers '(haskell-stack-ghc haskell-ghc)))
920 *** [[https://github.com/jyp/dante][dante]]
922 #+begin_src emacs-lisp
926 :hook (haskell-mode . dante-mode))
929 *** [[https://github.com/mpickering/hlint-refactor-mode][hlint-refactor]]
931 Emacs bindings for [[https://github.com/ndmitchell/hlint][hlint]]'s refactor option. This requires the refact
932 executable from [[https://github.com/mpickering/apply-refact][apply-refact]].
934 #+begin_src emacs-lisp
935 (use-package hlint-refactor
936 :bind (:map hlint-refactor-mode-map
937 ("C-c l b" . hlint-refactor-refactor-buffer)
938 ("C-c l r" . hlint-refactor-refactor-at-point))
939 :hook (haskell-mode . hlint-refactor-mode))
942 *** [[https://github.com/flycheck/flycheck-haskell][flycheck-haskell]]
944 #+begin_src emacs-lisp
945 (use-package flycheck-haskell)
948 *** [[https://github.com/ndmitchell/hlint/blob/20e116a043f2073c57b17b24ae6364b5e433ba7e/data/hs-lint.el][hs-lint.el]]
950 :header-args+: :tangle lisp/hs-lint.el :mkdirp yes
953 Currently using =flycheck-haskell= with the =haskell-hlint= checker
956 #+begin_src emacs-lisp :tangle no
957 ;;; hs-lint.el --- minor mode for HLint code checking
959 ;; Copyright 2009 (C) Alex Ott
961 ;; Author: Alex Ott <alexott@gmail.com>
962 ;; Keywords: haskell, lint, HLint
964 ;; Status: distributed under terms of GPL2 or above
966 ;; Typical message from HLint looks like:
968 ;; /Users/ott/projects/lang-exp/haskell/test.hs:52:1: Eta reduce
970 ;; count1 p l = length (filter p l)
972 ;; count1 p = length . filter p
977 (defgroup hs-lint nil
978 "Run HLint as inferior of Emacs, parse error messages."
982 (defcustom hs-lint-command "hlint"
983 "The default hs-lint command for \\[hlint]."
987 (defcustom hs-lint-save-files t
988 "Save modified files when run HLint or no (ask user)"
992 (defcustom hs-lint-replace-with-suggestions nil
993 "Replace user's code with suggested replacements"
997 (defcustom hs-lint-replace-without-ask nil
998 "Replace user's code with suggested replacements automatically"
1002 (defun hs-lint-process-setup ()
1003 "Setup compilation variables and buffer for `hlint'."
1004 (run-hooks 'hs-lint-setup-hook))
1006 ;; regex for replace suggestions
1008 ;; ^\(.*?\):\([0-9]+\):\([0-9]+\): .*
1014 (defvar hs-lint-regex
1015 "^\\(.*?\\):\\([0-9]+\\):\\([0-9]+\\): .*[\n\C-m]Found:[\n\C-m]\\s +\\(.*\\)[\n\C-m]Why not:[\n\C-m]\\s +\\(.*\\)[\n\C-m]"
1016 "Regex for HLint messages")
1018 (defun make-short-string (str maxlen)
1019 (if (< (length str) maxlen)
1021 (concat (substring str 0 (- maxlen 3)) "...")))
1023 (defun hs-lint-replace-suggestions ()
1024 "Perform actual replacement of suggestions"
1025 (goto-char (point-min))
1026 (while (re-search-forward hs-lint-regex nil t)
1027 (let* ((fname (match-string 1))
1028 (fline (string-to-number (match-string 2)))
1029 (old-code (match-string 4))
1030 (new-code (match-string 5))
1031 (msg (concat "Replace '" (make-short-string old-code 30)
1032 "' with '" (make-short-string new-code 30) "'"))
1038 (switch-to-buffer (get-file-buffer fname))
1039 (goto-char (point-min))
1040 (forward-line (1- fline))
1042 (setf bline (point))
1043 (when (or hs-lint-replace-without-ask
1046 (setf eline (point))
1048 (setf old-code (regexp-quote old-code))
1049 (while (string-match "\\\\ " old-code spos)
1050 (setf new-old-code (concat new-old-code
1051 (substring old-code spos (match-beginning 0))
1053 (setf spos (match-end 0)))
1054 (setf new-old-code (concat new-old-code (substring old-code spos)))
1055 (remove-text-properties bline eline '(composition nil))
1056 (when (re-search-forward new-old-code eline t)
1057 (replace-match new-code nil t)))))))
1059 (defun hs-lint-finish-hook (buf msg)
1060 "Function, that is executed at the end of HLint execution"
1061 (if hs-lint-replace-with-suggestions
1062 (hs-lint-replace-suggestions)
1065 (define-compilation-mode hs-lint-mode "HLint"
1066 "Mode for check Haskell source code."
1067 (set (make-local-variable 'compilation-process-setup-function)
1068 'hs-lint-process-setup)
1069 (set (make-local-variable 'compilation-disable-input) t)
1070 (set (make-local-variable 'compilation-scroll-output) nil)
1071 (set (make-local-variable 'compilation-finish-functions)
1072 (list 'hs-lint-finish-hook))
1076 "Run HLint for current buffer with haskell source"
1078 (save-some-buffers hs-lint-save-files)
1079 (compilation-start (concat hs-lint-command " \"" buffer-file-name "\"")
1083 ;;; hs-lint.el ends here
1086 #+begin_src emacs-lisp :tangle no
1087 (use-package hs-lint
1089 :bind (:map haskell-mode-map
1090 ("C-c l l" . hs-lint)))
1092 * Emacs Enhancements
1094 ** [[https://github.com/justbur/emacs-which-key][which-key]]
1097 Emacs package that displays available keybindings in popup
1100 #+begin_src emacs-lisp
1101 (use-package which-key
1103 :config (which-key-mode))
1106 ** [[https://github.com/seagle0128/doom-modeline][doom-modeline]]
1108 #+begin_src emacs-lisp
1109 (use-package doom-modeline
1111 :config (setq doom-modeline-height 32)
1112 :hook (after-init . doom-modeline-init))
1115 ** [[https://github.com/11111000000/tao-theme-emacs][tao-theme]]
1117 #+begin_src emacs-lisp :tangle no
1118 (use-package tao-theme
1120 :config (load-theme 'tao-yang t))
1123 ** [[https://github.com/maio/eink-emacs][eink-theme]]
1125 #+begin_src emacs-lisp
1126 (load-theme 'eink t)
1129 ** [[https://github.com/bbatsov/crux][crux]]
1131 #+begin_src emacs-lisp
1133 :bind (("C-c d" . crux-duplicate-current-line-or-region)
1134 ("C-c M-d" . crux-duplicate-and-comment-current-line-or-region)
1135 ("M-m b K" . crux-kill-other-buffers)
1136 ("M-m f c" . crux-copy-file-preserve-attributes)
1137 ("M-m f D" . crux-delete-file-and-buffer)
1138 ("M-m f R" . crux-rename-file-and-buffer)))
1141 ** [[https://github.com/alezost/mwim.el][mwim]]
1143 #+begin_src emacs-lisp
1145 :bind (("C-a" . mwim-beginning-of-code-or-line)
1146 ("C-e" . mwim-end-of-code-or-line)
1147 ("<home>" . mwim-beginning-of-line-or-code)
1148 ("<end>" . mwim-end-of-line-or-code)))
1152 ** [[https://notmuchmail.org][notmuch]]
1154 See [[notmuch:id:87muuqsvci.fsf@fencepost.gnu.org][bug follow-up]].
1156 #+begin_src emacs-lisp
1157 (defvar amin-maildir "~/mail")
1159 (use-package sendmail
1162 (setq sendmail-program "/usr/bin/msmtp"
1163 ; message-sendmail-extra-arguments '("-v" "-d")
1164 mail-specify-envelope-from t
1165 mail-envelope-from 'header))
1167 (use-package message
1170 (setq message-kill-buffer-on-exit t
1171 message-send-mail-function 'message-send-mail-with-sendmail
1172 message-sendmail-envelope-from 'header
1173 message-directory "drafts"
1174 message-user-fqdn "aminb.org")
1175 (add-hook 'message-mode-hook
1176 (lambda () (setq fill-column 65
1177 message-fill-column 65)))
1178 (add-hook 'message-mode-hook
1180 ;; (add-hook 'notmuch-message-mode-hook #'+doom-modeline|set-special-modeline)
1181 ;; TODO: is there a way to only run this when replying and not composing?
1182 ;; (add-hook 'notmuch-message-mode-hook
1183 ;; (lambda () (progn
1186 ;; (forward-line -1)
1187 ;; (forward-line -1))))
1188 ;; (add-hook 'message-setup-hook
1189 ;; #'mml-secure-message-sign-pgpmime)
1193 (setq mml-secure-openpgp-encrypt-to-self t
1194 mml-secure-openpgp-sign-with-sender t))
1196 (defun amin/notmuch ()
1197 "Delete other windows, then launch `notmuch'."
1199 (delete-other-windows)
1202 (use-package notmuch
1204 :bind (("C-c m" . amin/notmuch)
1205 ("M-m m" . amin/notmuch))
1207 (setq notmuch-hello-sections
1208 '(notmuch-hello-insert-header
1209 notmuch-hello-insert-saved-searches
1210 ;; notmuch-hello-insert-search
1211 notmuch-hello-insert-alltags)
1212 notmuch-search-oldest-first nil
1213 notmuch-show-all-tags-list t
1214 notmuch-message-headers ; see bug follow-up above
1215 '("Subject" "To" "Cc" "Date" "List-Id" "X-RT-Originator")
1216 notmuch-hello-thousands-separator ","
1218 '(("amin@aminb.org" . "amin/Sent")
1219 ("amin@gnu.org" . "gnu/Sent")
1220 ("abandali@uwaterloo.ca" . "\"uwaterloo/Sent Items\"")
1221 ("mab@gnu.org" . "gnu/Sent")
1222 ("aminb@gnu.org" . "gnu/Sent")
1224 notmuch-search-result-format
1225 '(("date" . "%12s ")
1227 ("authors" . "%-40s ")
1230 notmuch-saved-searches
1231 '((:name "inbox" :query "tag:inbox" :key "i")
1232 (:name "unread" :query "tag:unread" :key "u")
1233 (:name "latest" :query "tag:latest" :key "l")
1234 (:name "encrypted" :query "tag:encrypted" :key "e")
1235 (:name "flagged" :query "tag:flagged" :key "f")
1236 (:name "sent" :query "tag:sent" :key "s")
1237 (:name "drafts" :query "tag:draft" :key "d")
1238 (:name "all mail" :query "*" :key "a")))
1239 ;; (add-hook 'visual-fill-column-mode-hook
1241 ;; (when (string= major-mode 'notmuch-message-mode)
1242 ;; (setq visual-fill-column-width 70))))
1243 ;; (set! :evil-state 'notmuch-message-mode 'insert)
1244 ;; (advice-add #'notmuch-bury-or-kill-this-buffer
1245 ;; :override #'kill-this-buffer)
1246 ;; (evil-collection-define-key 'normal 'notmuch-common-keymap
1248 ;; "Compose new mail and prompt for sender"
1250 ;; (let ((current-prefix-arg t))
1251 ;; (call-interactively #'notmuch-mua-new-mail))))
1253 (:map notmuch-search-mode-map
1257 (notmuch-search-tag '("-unread"))
1258 ;; (notmuch-search-archive-thread)
1259 (notmuch-search-next-thread)))
1261 "Mark message unread"
1263 (notmuch-search-tag '("+unread"))
1264 (notmuch-search-next-thread)))
1266 "Mark message deleted"
1268 (notmuch-search-tag '("-unread" "-inbox" "+deleted"))
1269 (notmuch-search-archive-thread)))
1271 "Mark message as spam"
1273 (notmuch-search-tag '("-unread" "-inbox" "-webmasters" "+spam"))
1274 (notmuch-search-archive-thread))))
1275 (:map notmuch-tree-mode-map ; TODO: additional bindings
1277 "Mark message as spam"
1279 (notmuch-tree-tag '("-unread" "-inbox" "-webmasters" "+spam"))
1280 (notmuch-tree-archive-thread))))
1283 (use-package counsel-notmuch
1284 :bind ("M-m / m" . counsel-notmuch))
1286 (after! notmuch-crypto
1287 (setq notmuch-crypto-process-mime t))
1290 (add-to-list 'recentf-exclude (expand-file-name amin-maildir)))
1295 #+begin_src emacs-lisp :tangle no
1296 (use-package supercite
1297 :commands sc-cite-original
1299 (add-hook 'mail-citation-hook 'sc-cite-original)
1301 (defun sc-remove-existing-signature ()
1303 (goto-char (region-beginning))
1304 (when (re-search-forward message-signature-separator (region-end) t)
1305 (delete-region (match-beginning 0) (region-end)))))
1307 (add-hook 'mail-citation-hook 'sc-remove-existing-signature)
1309 (defun sc-remove-if-not-mailing-list ()
1310 (unless (assoc "list-id" sc-mail-info)
1311 (setq attribution sc-default-attribution
1312 citation (concat sc-citation-delimiter
1313 sc-citation-separator))))
1315 (add-hook 'sc-attribs-postselect-hook 'sc-remove-if-not-mailing-list)
1318 (defun sc-fill-if-different (&optional prefix)
1319 "Fill the region bounded by `sc-fill-begin' and point.
1320 Only fill if optional PREFIX is different than
1321 `sc-fill-line-prefix'. If `sc-auto-fill-region-p' is nil, do not
1322 fill region. If PREFIX is not supplied, initialize fill
1323 variables. This is useful for a regi `begin' frame-entry."
1325 (setq sc-fill-line-prefix ""
1326 sc-fill-begin (line-beginning-position))
1327 (if (and sc-auto-fill-region-p
1328 (not (string= prefix sc-fill-line-prefix)))
1329 (let ((fill-prefix sc-fill-line-prefix))
1330 (unless (or (string= fill-prefix "")
1332 (goto-char sc-fill-begin)
1333 (or (looking-at ">+ +")
1335 (buffer-substring (point)
1336 (line-end-position)))
1338 (fill-region sc-fill-begin (line-beginning-position)))
1339 (setq sc-fill-line-prefix prefix
1340 sc-fill-begin (line-beginning-position)))))
1345 ** [[https://ox-hugo.scripter.co][ox-hugo]]
1347 #+begin_src emacs-lisp
1348 (use-package ox-hugo
1352 * Post initialization
1354 :CUSTOM_ID: post-initialization
1357 Display how long it took to load the init file.
1359 #+begin_src emacs-lisp
1360 (message "Loading %s...done (%.3fs)" user-init-file
1361 (float-time (time-subtract (current-time)
1362 amin--before-user-init-time)))
1370 #+begin_src emacs-lisp :comments none
1371 ;;; init.el ends here