1 #+title: =aminb='s Emacs Init file
2 #+property: header-args :results silent :comments link :tangle ~/dotfiles/emacs/init.el
8 * Contents :toc_1:noexport:
12 - [[#initial-setup][Initial setup]]
23 #+begin_src emacs-lisp :comments none
24 ;;; init.el --- Amin Bandali's Emacs config -*- lexical-binding: t ; eval: (view-mode 1)-*-
27 Enable =view-mode=, which both makes the file read-only (as a reminder
28 that =init.el= is an auto-generated file, not supposed to be edited),
29 and provides some convenient key bindings for browsing through the
34 #+begin_src emacs-lisp :comments none
35 ;; Copyright (C) 2018 Amin Bandali <amin@aminb.org>
37 ;; This program is free software: you can redistribute it and/or modify
38 ;; it under the terms of the GNU General Public License as published by
39 ;; the Free Software Foundation, either version 3 of the License, or
40 ;; (at your option) any later version.
42 ;; This program is distributed in the hope that it will be useful,
43 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
44 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 ;; GNU General Public License for more details.
47 ;; You should have received a copy of the GNU General Public License
48 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
53 #+begin_src emacs-lisp :comments none
56 ;; Emacs configuration of Amin Bandali, computer scientist and functional
59 ;; THIS FILE IS AUTO-GENERATED FROM `init.org'.
64 The conventions below were inspired by [[https://github.com/hlissner/doom-emacs][Doom]]'s conventions, found
65 [[https://github.com/hlissner/doom-emacs/blob/5dacbb7cb1c6ac246a9ccd15e6c4290def67757c/core/core.el#L3-L17][here]]. Naturally, I use my initials, =ab=, instead of =doom=.
67 #+begin_src emacs-lisp :comments none
68 ;; Naming conventions:
70 ;; ab-... public variables or non-interactive functions
71 ;; ab--... private anything (non-interactive), not safe for direct use
72 ;; ab/... an interactive function; safe for M-x or keybinding
73 ;; ab:... an evil operator, motion, or command
74 ;; ab|... a hook function
75 ;; ab*... an advising function
76 ;; ab@... a hydra command
82 :CUSTOM_ID: initial-setup
85 #+begin_src emacs-lisp :comments none
91 Measure and display startup time. Also, temporarily increase
92 ~gc-cons-threshhold~ during startup to reduce reduce garbage
93 collection frequency. Taken from [[https://github.com/dieggsy/dotfiles/tree/3d95bc08033920e077855caf545a975eba52d28d/emacs.d#startup-time][here]].
95 #+begin_src emacs-lisp
96 (defconst ab--emacs-start-time (current-time))
97 (defconst ab--gc-cons-threshold gc-cons-threshold)
98 (defconst ab--gc-cons-percentage gc-cons-percentage)
99 (defvar ab--file-name-handler-alist file-name-handler-alist)
100 (setq gc-cons-threshold 400000000
101 gc-cons-percentage 0.6
102 file-name-handler-alist nil
103 ;; sidesteps a bug when profiling with esup
104 esup-child-profile-require-level 0)
107 Reset the variables back to default after init.
109 #+begin_src emacs-lisp
113 (setq gc-cons-threshold ab--gc-cons-threshold
114 gc-cons-percentage ab--gc-cons-percentage
115 file-name-handler-alist ab--file-name-handler-alist)
116 (let ((elapsed (float-time (time-subtract (current-time)
117 ab--emacs-start-time))))
118 (message "Loading %s...done (%.3fs) [after-init]"
119 ,load-file-name elapsed))))
122 ** Package management
127 Next-generation, purely functional package manager for the Emacs
131 =straight.el= allows me to have a fully reproducible Emacs setup.
135 #+begin_src emacs-lisp
136 (let ((bootstrap-file (concat user-emacs-directory "straight/repos/straight.el/bootstrap.el"))
137 (bootstrap-version 3))
138 (unless (file-exists-p bootstrap-file)
140 (url-retrieve-synchronously
141 "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
142 'silent 'inhibit-cookies)
143 (goto-char (point-max))
144 (eval-print-last-sexp)))
145 (load bootstrap-file nil 'nomessage))
150 #+begin_src emacs-lisp
151 (defun straight-reload-init ()
154 (straight-transaction
155 (straight-mark-transaction-as-init)
156 (message "Reloading init.el...")
157 (load user-init-file nil 'nomessage)
158 (message "Reloading init.el... done.")))
160 (defun straight-eval-buffer ()
161 "Evaluate the current buffer as Elisp code."
163 (message "Evaluating %s..." (buffer-name))
164 (straight-transaction
165 (if (null buffer-file-name)
167 (when (string= buffer-file-name user-init-file)
168 (straight-mark-transaction-as-init))
169 (load-file buffer-file-name)))
170 (message "Evaluating %s... done." (buffer-name)))
176 A use-package declaration for simplifying your .emacs
179 =use-package= is an awesome utility for managing and configuring
180 packages in a neatly organized way and without compromising on
181 performance. So let's install it using =striaght.el= and have it use
182 =straight.el= for installing packages.
184 #+begin_src emacs-lisp
185 (straight-use-package 'use-package)
186 (setq straight-use-package-by-default t)
189 ** No littering in =~/.emacs.d=
192 Help keeping ~/.emacs.d clean
195 By default, even for Emacs' built-in packages, the configuration files
196 and persistent data are all over the place. Use =no-littering= to help
199 #+begin_src emacs-lisp
200 (use-package no-littering
204 (add-to-list 'savehist-additional-variables 'kill-ring)
206 (setq auto-save-file-name-transforms
207 `((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))
210 ** Custom file (=custom.el=)
212 I'm not planning on using the custom file much, but even so, I
213 definitely don't want it mixing with =init.el=. So, here, let's give
216 #+begin_src emacs-lisp
217 (setq custom-file (no-littering-expand-etc-file-name "custom.el"))
218 (when (file-exists-p custom-file)
224 Emacs' default backup settings aren't that great. Let's use more
225 sensible options. See documentation for the ~make-backup-file~
228 #+begin_src emacs-lisp
229 (setq backup-by-copying t
240 #+begin_src emacs-lisp
241 (setq org-src-tab-acts-natively t
242 org-src-preserve-indentation nil
243 org-edit-src-content-indentation 0)
251 #+begin_src emacs-lisp :comments none
252 ;;; init.el ends here