emacs/early-init.el

263 lines
7.9 KiB
EmacsLisp
Raw Normal View History

2021-03-01 05:58:57 +00:00
;;; early-init.el -*- lexical-binding: t; coding: utf-8 -*-
;; Copyright (C) 2020-2021 Case Duckworth
;;
2021-02-26 17:31:50 +00:00
;; Author: Case Duckworth <acdw@acdw.net>
2021-03-01 05:58:57 +00:00
;; Created: Sometime during Covid-19, 2020
2021-02-26 17:31:50 +00:00
;; Keywords: configuration
2021-03-01 05:58:57 +00:00
;; URL https://tildegit.org/acdw/emacs
;;
;; This file is NOT part of GNU Emacs.
;;
;;; License:
;;
;; Everyone is permitted to do whatever with this software, without
;; limitation. This software comes without any warranty whatsoever,
;; but with two pieces of advice:
;; - Don't hurt yourself.
;; - Make good choices.
;;
;;; Comentary:
;;
;; Starting with Emacs 27.1, `early-init' is sourced before `package'
;; or any frames. So those are the settings I run in this file.
;;
;;; Code:
2021-02-26 17:31:50 +00:00
2021-03-01 05:58:57 +00:00
;; Speed up init
(setq gc-cons-threshold most-positive-fixnum
gc-cons-percentage 0.6
comp-deferred-compilation nil)
2021-02-26 17:31:50 +00:00
2021-03-01 05:58:57 +00:00
(defconst gc-cons-basis (* 800 1024)
"The basis value to which to return after a max jump.
800,000 (800 KB) is Emacs' default.")
2021-02-26 17:31:50 +00:00
2021-03-01 05:58:57 +00:00
(add-hook 'after-init-hook #'(lambda ()
(setq gc-cons-threshold gc-cons-basis
gc-cons-percentage 0.1)))
(defun hook--gc-cons-maximize ()
"Set `gc-cons-threshold' to the highest possible.
For memory-intensive features."
(setq gc-cons-threshold most-positive-fixnum))
(defun hook--gc-cons-baseline ()
"Return `gc-cons-threshold' to `gc-cons-basis'.
For after memory intensive operations."
(setq gc-cons-threshold gc-cons-basis))
(add-hook 'minibuffer-setup-hook #'hook--gc-cons-maximize)
(add-hook 'minibuffer-exit-hook #'hook--gc-cons-baseline)
;; From doom-emacs
(unless (daemonp)
(defvar doom--initial-file-name-handler-alist file-name-handler-alist)
(setq file-name-handler-alist nil)
2021-03-01 18:12:20 +00:00
(defun hook--reset-file-handler-alist ()
2021-03-01 05:58:57 +00:00
(dolist (handler file-name-handler-alist)
(add-to-list 'doom--initial-file-name-handler-alist handler))
(setq file-name-handler-alist doom--initial-file-name-handler-alist))
2021-03-01 18:12:20 +00:00
(add-hook 'emacs-startup-hook #'hook--reset-file-handler-alist))
2021-03-01 05:58:57 +00:00
;; Where are we?
(defconst acdw/system (pcase system-type
('gnu/linux :home)
((or 'msdos 'windows-nt) :work)
(_ :other)))
;; Frame initiation
;; Initialize frames with as little UI as possible.
(setq-default
default-frame-alist ; The default look of frames
`((tool-bar-lines . 0) ; Remove tool bar
(menu-bar-lines . 0) ; Remove menu bar
(vertical-scroll-bars) ; Remove vertical scroll bars
(horizontal-scroll-bars) ; Remove horizontal scroll bars
(width . 84) ; A /little/ wider than `fill-column'
(height . 30) ; Text characters
(left-fringe . 8) ; Width of fringes
(right-fringe . 8) ; (8 is the default)
(font . ,(pcase acdw/system ; Default font
(:home "Terminus 12")
(:work "Consolas 11")))
)
x-underline-at-descent-line t ; underline at the descent line
scroll-margin 0 ; how many lines to show at window edge
scroll-conservatively 101 ; just enough to bring text into view
scroll-preserve-screen-position 1 ; always keep screen position
frame-title-format ; Titles for frames
'((:eval (if (buffer-file-name) ; (cf. `mode-line-format')
(abbreviate-file-name (buffer-file-name))
"%b"))
" "
mode-line-client
mode-line-modified
" - GNU Emacs")
mode-line-format ; Mode line
`("%e"
mode-line-front-space
;; mode-line-mule-info
mode-line-client
mode-line-modified
mode-line-remote
mode-line-frame-identification
mode-line-buffer-identification " "
mode-line-position
(vc-mode vc-mode) " "
minions-mode-line-modes
mode-line-misc-info
mode-line-end-spaces
))
2021-03-01 05:58:57 +00:00
;; Set the rest of the fonts after initiation
(defun hook--setup-fonts ()
(pcase acdw/system
(:home (set-face-attribute 'default nil
:family "Terminus"
:height 120)
(set-face-attribute 'fixed-pitch nil
:family "Terminus"
:height 1.0)
(set-face-attribute 'variable-pitch nil
:family "DejaVu Sans"
:height 1.0))
(:work (set-face-attribute 'default nil
2021-03-01 18:12:20 +00:00
:family "Consolas"
2021-03-01 05:58:57 +00:00
:height 110)
(set-face-attribute 'fixed-pitch nil
:family "Consolas"
:height 1.0)
(set-face-attribute 'variable-pitch nil
:family "Cambria"
:height 1.0))))
(add-hook 'after-init-hook #'hook--setup-fonts)
;; In case I do want the UI elements later, I also disable the modes
;; -- otherwise I'd have to run the mode twice to actually show the
;; thing.
(defun hook--disable-ui-modes ()
(dolist (mode '(tool-bar-mode
menu-bar-mode
scroll-bar-mode
horizontal-scroll-bar-mode))
(funcall mode -1)))
;; I run it on the `after-init-hook' so it doesn't slow down init so much.
(add-hook 'after-init-hook #'hook--disable-ui-modes)
;; Customize the fringe
(setq-default
indicate-empty-lines t ; show an indicator at the end of the buffer
indicate-buffer-boundaries 'right ; show buffer boundaries on the right
visual-line-fringe-indicators ; show continuation indicators on the left
'(left-curly-arrow nil))
(defun hook--setup-fringe-bitmaps ()
(define-fringe-bitmap 'left-curly-arrow
[#b11000000
#b01100000
#b00110000
#b00011000])
(define-fringe-bitmap 'right-curly-arrow
[#b00011000
#b00110000
#b01100000
#b11000000])
(define-fringe-bitmap 'left-arrow
[#b00000000
#b01010100
#b01010100
#b00000000])
(define-fringe-bitmap 'right-arrow
[#b00000000
#b00101010
#b00101010
#b00000000])
(remove-function after-focus-change-function #'hook--setup-fringe-bitmaps))
(add-function :after after-focus-change-function #'hook--setup-fringe-bitmaps)
2021-03-01 05:58:57 +00:00
;; Resize like it's 2021
(setq-default frame-inhibit-implied-resize t
frame-resize-pixelwise t)
;; Bootstrap package manager (`straight')
;; First, I need to make sure it's in the `exec-path'.
2021-02-26 17:31:50 +00:00
(let ((win-app-dir "~/Applications"))
(dolist (path (list
;; Windows
(expand-file-name "exe" win-app-dir)
(expand-file-name "exe/bin" win-app-dir)
(expand-file-name "Git/bin" win-app-dir)
(expand-file-name "Git/usr/bin" win-app-dir)
(expand-file-name "Git/mingw64/bin" win-app-dir)
(expand-file-name "Everything" win-app-dir)
(expand-file-name "Win-builds/bin" win-app-dir)
(expand-file-name "Z/bin" win-app-dir)
;; Linux
(expand-file-name "bin" user-emacs-directory)
(expand-file-name "~/bin")
(expand-file-name "~/.local/bin")
2021-03-01 05:58:57 +00:00
(expand-file-name "~/usr/bin")
2021-02-26 17:31:50 +00:00
))
(when (file-exists-p path)
(add-to-list 'exec-path path :append))))
2021-03-01 05:58:57 +00:00
;; Set $PATH back to `exec-path', for symmetry's sake.
2021-02-26 17:31:50 +00:00
(setenv "PATH" (mapconcat #'identity exec-path path-separator))
2021-03-01 05:58:57 +00:00
;; Set some variables
(defvar acdw/etc-dir
(expand-file-name "etc/" user-emacs-directory)
"Where to put other configurations.")
(defvar acdw/var-dir
(expand-file-name "var/" user-emacs-directory)
"Where to put variable stuff.")
(setq-default package-enable-at-startup nil
package-quickstart nil
straight-use-package-by-default t
straight-host-usernames '((github . "duckwork")
(gitlab . "acdw"))
straight-base-dir acdw/var-dir)
;; Run `straight''s bootstrap code
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name
2021-03-01 22:16:06 +00:00
"straight/repos/straight.el/bootstrap.el"
straight-base-dir))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
2021-02-26 17:31:50 +00:00
2021-03-01 05:58:57 +00:00
;; `use-package'
(straight-use-package 'use-package)
(require 'use-package)
;; Message startup time
(defun hook--message-startup-time ()
"Message Emacs' startup time."
(message "Emacs ready in %s with %d garbage collections."
(format "%.2f seconds"
(float-time (time-subtract after-init-time
before-init-time)))
gcs-done))
(add-hook 'emacs-startup-hook #'hook--message-startup-time)