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]]
20 #+begin_src emacs-lisp :comments none
21 ;;; init.el --- Amin Bandali's Emacs config -*- lexical-binding: t ; eval: (view-mode 1)-*-
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
31 #+begin_src emacs-lisp :comments none
32 ;; Copyright (C) 2018 Amin Bandali <amin@aminb.org>
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.
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.
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/>.
50 #+begin_src emacs-lisp :comments none
53 ;; Emacs configuration of Amin Bandali, computer scientist and functional
56 ;; THIS FILE IS AUTO-GENERATED FROM `init.org'.
61 #+begin_src emacs-lisp :comments none
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]].
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)
83 Reset the variables back to default after init.
85 #+begin_src emacs-lisp
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))))
103 Next-generation, purely functional package manager for the Emacs
107 =straight.el= allows me to have a fully reproducible Emacs setup.
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)
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))
126 #+begin_src emacs-lisp
127 (defun straight-reload-init ()
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.")))
136 (defun straight-eval-buffer ()
137 "Evaluate the current buffer as Elisp code."
139 (message "Evaluating %s..." (buffer-name))
140 (straight-transaction
141 (if (null buffer-file-name)
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)))
152 A use-package declaration for simplifying your .emacs.
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.
160 #+begin_src emacs-lisp
161 (straight-use-package 'use-package)
162 (setq straight-use-package-by-default t)
165 ** No littering in =~/.emacs.d=
168 Help keeping ~/.emacs.d clean.
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
175 #+begin_src emacs-lisp
176 (use-package no-littering
180 (add-to-list 'savehist-additional-variables 'kill-ring)
182 (setq auto-save-file-name-transforms
183 `((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))
186 ** Custom file (=custom.el=)
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
192 #+begin_src emacs-lisp
193 (setq custom-file (no-littering-expand-etc-file-name "custom.el"))
194 (when (file-exists-p custom-file)
200 Emacs' default backup settings aren't that great. Let's use more
201 sensible options. See documentation for the ~make-backup-file~
204 #+begin_src emacs-lisp
205 (setq backup-by-copying t
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)
221 #+begin_src emacs-lisp :comments none
222 ;;; init.el ends here