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