Use my initials, ab, for prefixing my functions and vars
[~bandali/configs] / emacs / init.org
CommitLineData
35ea1ba4
AB
1#+title: =aminb='s Emacs Init file
2#+property: header-args :results silent :comments link :tangle ~/dotfiles/emacs/init.el
3
4* Intro
5
6TODO: description
7
abdc6c07
AB
8* Contents :toc_1:noexport:
9
10- [[#intro][Intro]]
11- [[#header][Header]]
12- [[#initial-setup][Initial setup]]
13- [[#config][Config]]
14- [[#footer][Footer]]
35ea1ba4
AB
15
16* Header
279a98e2
AB
17:PROPERTIES:
18:CUSTOM_ID: header
19:END:
35ea1ba4
AB
20
21** First line
22
23#+begin_src emacs-lisp :comments none
24;;; init.el --- Amin Bandali's Emacs config -*- lexical-binding: t ; eval: (view-mode 1)-*-
25#+end_src
26
27Enable =view-mode=, which both makes the file read-only (as a reminder
28that =init.el= is an auto-generated file, not supposed to be edited),
29and provides some convenient key bindings for browsing through the
30file.
31
32** License
33
34#+begin_src emacs-lisp :comments none
35;; Copyright (C) 2018 Amin Bandali <amin@aminb.org>
36
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.
41
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.
46
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/>.
49#+end_src
50
51** Commentary
52
6089982a 53#+begin_src emacs-lisp :comments none
35ea1ba4
AB
54;;; Commentary:
55
56;; Emacs configuration of Amin Bandali, computer scientist and functional
57;; programmer.
58
59;; THIS FILE IS AUTO-GENERATED FROM `init.org'.
60#+end_src
61
fd134a2b 62* Initial setup
279a98e2
AB
63:PROPERTIES:
64:CUSTOM_ID: initial-setup
65:END:
35ea1ba4 66
6089982a 67#+begin_src emacs-lisp :comments none
35ea1ba4
AB
68;;; Code:
69#+end_src
70
6089982a
AB
71** Startup time
72
73Measure and display startup time. Also, temporarily increase
74~gc-cons-threshhold~ during startup to reduce reduce garbage
75collection frequency. Taken from [[https://github.com/dieggsy/dotfiles/tree/3d95bc08033920e077855caf545a975eba52d28d/emacs.d#startup-time][here]].
76
77#+begin_src emacs-lisp
63a849c3
AB
78(defconst ab--emacs-start-time (current-time))
79(defconst ab--gc-cons-threshold gc-cons-threshold)
80(defconst ab--gc-cons-percentage gc-cons-percentage)
81(defvar ab--file-name-handler-alist file-name-handler-alist)
6089982a
AB
82(setq gc-cons-threshold 400000000
83 gc-cons-percentage 0.6
84 file-name-handler-alist nil
85 ;; sidesteps a bug when profiling with esup
86 esup-child-profile-require-level 0)
87#+end_src
88
89Reset the variables back to default after init.
90
91#+begin_src emacs-lisp
92(add-hook
93 'after-init-hook
94 `(lambda ()
63a849c3
AB
95 (setq gc-cons-threshold ab--gc-cons-threshold
96 gc-cons-percentage ab--gc-cons-percentage
97 file-name-handler-alist ab--file-name-handler-alist)
6089982a 98 (let ((elapsed (float-time (time-subtract (current-time)
63a849c3 99 ab--emacs-start-time))))
6089982a
AB
100 (message "Loading %s...done (%.3fs) [after-init]"
101 ,load-file-name elapsed))))
102#+end_src
35ea1ba4 103
63a849c3
AB
104Note that I'll be using my initials, =ab=, as a prefix for the
105variables and functions I define throughout my init file.
106
fd134a2b
AB
107** Package management
108
204986be 109*** =straight.el=
fd134a2b
AB
110
111#+begin_quote
112Next-generation, purely functional package manager for the Emacs
113hacker.
114#+end_quote
115
116=straight.el= allows me to have a fully reproducible Emacs setup.
117
118**** Bootstrap
119
120#+begin_src emacs-lisp
121(let ((bootstrap-file (concat user-emacs-directory "straight/repos/straight.el/bootstrap.el"))
122 (bootstrap-version 3))
123 (unless (file-exists-p bootstrap-file)
124 (with-current-buffer
125 (url-retrieve-synchronously
126 "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
127 'silent 'inhibit-cookies)
128 (goto-char (point-max))
129 (eval-print-last-sexp)))
130 (load bootstrap-file nil 'nomessage))
131#+end_src
132
133**** Useful helpers
134
135#+begin_src emacs-lisp
136(defun straight-reload-init ()
137 "Reload init.el."
138 (interactive)
139 (straight-transaction
140 (straight-mark-transaction-as-init)
141 (message "Reloading init.el...")
142 (load user-init-file nil 'nomessage)
143 (message "Reloading init.el... done.")))
144
145(defun straight-eval-buffer ()
146 "Evaluate the current buffer as Elisp code."
147 (interactive)
148 (message "Evaluating %s..." (buffer-name))
149 (straight-transaction
150 (if (null buffer-file-name)
151 (eval-buffer)
152 (when (string= buffer-file-name user-init-file)
153 (straight-mark-transaction-as-init))
154 (load-file buffer-file-name)))
155 (message "Evaluating %s... done." (buffer-name)))
156#+end_src
157
158*** =use-package=
159
160#+begin_quote
63a849c3 161A use-package declaration for simplifying your .emacs
fd134a2b
AB
162#+end_quote
163
164=use-package= is an awesome utility for managing and configuring
165packages in a neatly organized way and without compromising on
166performance. So let's install it using =striaght.el= and have it use
167=straight.el= for installing packages.
168
169#+begin_src emacs-lisp
170(straight-use-package 'use-package)
171(setq straight-use-package-by-default t)
172#+end_src
173
174** No littering in =~/.emacs.d=
175
176#+begin_quote
63a849c3 177Help keeping ~/.emacs.d clean
fd134a2b
AB
178#+end_quote
179
180By default, even for Emacs' built-in packages, the configuration files
181and persistent data are all over the place. Use =no-littering= to help
182contain the mess.
183
184#+begin_src emacs-lisp
185(use-package no-littering
186 :demand t
187 :config
188 (savehist-mode 1)
189 (add-to-list 'savehist-additional-variables 'kill-ring)
190 (save-place-mode 1)
191 (setq auto-save-file-name-transforms
192 `((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))
193#+end_src
194
bab98ee5
AB
195** Custom file (=custom.el=)
196
197I'm not planning on using the custom file much, but even so, I
198definitely don't want it mixing with =init.el=. So, here, let's give
199it it's own file.
200
201#+begin_src emacs-lisp
fd134a2b
AB
202(setq custom-file (no-littering-expand-etc-file-name "custom.el"))
203(when (file-exists-p custom-file)
204 (load custom-file))
bab98ee5
AB
205#+end_src
206
204986be
AB
207** Backups
208
209Emacs' default backup settings aren't that great. Let's use more
210sensible options. See documentation for the ~make-backup-file~
211variable.
212
213#+begin_src emacs-lisp
214(setq backup-by-copying t
215 version-control t)
216#+end_src
217
abdc6c07 218* Config
279a98e2
AB
219:PROPERTIES:
220:CUSTOM_ID: config
221:END:
abdc6c07 222
bab98ee5
AB
223** Org
224
225#+begin_src emacs-lisp
226(setq org-src-tab-acts-natively t
227 org-src-preserve-indentation nil
228 org-edit-src-content-indentation 0)
229#+end_src
230
35ea1ba4 231* Footer
279a98e2
AB
232:PROPERTIES:
233:CUSTOM_ID: footer
234:END:
35ea1ba4
AB
235
236#+begin_src emacs-lisp :comments none
35ea1ba4
AB
237;;; init.el ends here
238#+end_src