From 983c7330e87481227393670b2151cb0539dc4de4 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 7 Mar 2021 22:14:38 -0600 Subject: 5c --- early-init.el | 260 ++++++++++++++++++---------------------------------------- 1 file changed, 80 insertions(+), 180 deletions(-) (limited to 'early-init.el') diff --git a/early-init.el b/early-init.el index 1bf78eb..352d4e6 100644 --- a/early-init.el +++ b/early-init.el @@ -1,10 +1,9 @@ -;;; early-init.el -*- lexical-binding: t; coding: utf-8 -*- -;; Copyright (C) 2020-2021 Case Duckworth +;;; early-init.el -*- lexical-binding: t; coding: utf-8-unix -*- ;; ;; Author: Case Duckworth ;; Created: Sometime during Covid-19, 2020 ;; Keywords: configuration -;; URL https://tildegit.org/acdw/emacs +;; URL: https://tildegit.org/acdw/emacs ;; ;; This file is NOT part of GNU Emacs. ;; @@ -23,174 +22,85 @@ ;; ;;; Code: -;; Speed up init -(setq gc-cons-threshold most-positive-fixnum - gc-cons-percentage 0.6 - comp-deferred-compilation nil) - -(defconst gc-cons-basis (* 800 1024) - "The basis value to which to return after a max jump. -800,000 (800 KB) is Emacs' default.") - -(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) - (defun hook--reset-file-handler-alist () - (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)) - (add-hook 'emacs-startup-hook #'hook--reset-file-handler-alist)) - -;; Where are we? +;;; Define personal-use constants (defconst acdw/system (pcase system-type ('gnu/linux :home) ((or 'msdos 'windows-nt) :work) - (_ :other))) - -;; Frame initiation + (_ :other)) + "Which system is currently being used.") -;; 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"))) - ) +(defvar acdw/dir (expand-file-name + (convert-standard-filename "var/") + user-emacs-directory) + "A directory to hold extra configuration and emacs data.") - x-underline-at-descent-line t ; underline at the descent line +;;; Speed up init +;; see doom-emacs, et al. - 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") +(defconst gc-cons-threshold-basis (* 800 1000) + "The basis value for `gc-cons-threshold' to return to after a jump. +800 KB is Emacs's default `gc-cons-threshold'.") - 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 - )) +(defconst gc-cons-percentage-basis 0.1 + "The basis value for `gc-cons-percentage' to return to after init. +0.1 is Emacs's default `gc-cons-percentage'.") -;; 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 - :family "Consolas" - :height 110) - (set-face-attribute 'fixed-pitch nil - :family "Consolas" - :height 1.0) - (set-face-attribute 'variable-pitch nil - :family "Cambria" - :height 1.0)))) +(defvar orig-file-name-handler-alist file-name-handler-alist + "The original value of `file-name-handler-alist' will be restored + after init.") -(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. +(setq gc-cons-threshold most-positive-fixnum + gc-cons-percentage 0.6 + file-name-handler-alist nil) + +(defun hook--post-init-reset () + "Reset `gc-cons-threshold', `gc-cons-percentage', and + `file-name-handler-alist' to their defaults after init." + (setq gc-cons-threshold gc-cons-threshold-basis + gc-cons-percentage gc-cons-percentage-basis) + (dolist (handler file-name-handler-alist) + (add-to-list 'orig-file-name-handler-alist handler)) + (setq file-name-handler-alist orig-file-name-handler-alist)) + +(add-hook 'after-init-hook #'hook--post-init-reset) + +;; ;;; Frame settings + +(setq default-frame-alist ; Remove most UI + `((tool-bar-lines . 0) ; No tool bar + (menu-bar-lines . 0) ; No menu bar + (vertical-scroll-bars) ; No scroll bars + (horizontal-scroll-bars) ; ... at all + (width . 84) ; A /little/ wider than + ; `fill-column' (set later) + (height . 30) + (left-fringe . 8) ; Width of fringes + (right-fringe . 8) ; (8 is default) + (font . ,(pcase acdw/system + (:home "Terminus 12") + (:work "Consolas 10")))) + frame-inhibit-implied-resize t ; Don't resize randomly + frame-resize-pixelwise t ; Resize by pixels, not chars + ) (defun hook--disable-ui-modes () - (dolist (mode '(tool-bar-mode - menu-bar-mode - scroll-bar-mode - horizontal-scroll-bar-mode)) - (funcall mode -1))) + "Disable frame UI using modes, for toggling later." + (dolist (mode ;; each mode is of the form (MODE . FRAME-ALIST-VAR) + '((tool-bar-mode . tool-bar-lines) + (menu-bar-mode . menu-bar-lines) + (scroll-bar-mode . vertical-scroll-bars) + (horizontal-scroll-bar-mode . horizontal-scroll-bars) + )) + (let ((setting (alist-get (cdr mode) default-frame-alist))) + (when (or (not setting) + (= 0 setting)) + (funcall (car 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) - -;; 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'. +;;; Bootstrap package manager (`straight.el') +;; 1. Update `exec-path'. (let ((win-app-dir "~/Applications")) (dolist (path (list ;; Windows @@ -210,26 +120,19 @@ )) (when (file-exists-p path) (add-to-list 'exec-path path :append)))) - -;; Set $PATH back to `exec-path', for symmetry's sake. +;; 1.5. Update $PATH to reflect changes. (setenv "PATH" (mapconcat #'identity exec-path path-separator)) -;; 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.") +;; 2. Set `package' and `straight' variables. +(setq package-enable-at-startup nil ; not sure if strictly + ; necessary + package-quickstart nil ; ditto + straight-host-usernames '((github . "duckwork") + (gitlab . "acdw")) + straight-base-dir acdw/dir ; don't clutter ~/.emacs.d + ) -(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 +;; 3. Bootstrap `straight'. (defvar bootstrap-version) (let ((bootstrap-file (expand-file-name @@ -239,20 +142,17 @@ (unless (file-exists-p bootstrap-file) (with-current-buffer (url-retrieve-synchronously - "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el" + (concat "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)) -;; `use-package' - -(straight-use-package 'use-package) -(require 'use-package) +;;; Message startup time for profiling -;; Message startup time (defun hook--message-startup-time () - "Message Emacs' startup time." + "Show Emacs's startup time in the message buffer. For profiling." (message "Emacs ready in %s with %d garbage collections." (format "%.2f seconds" (float-time (time-subtract after-init-time -- cgit 1.4.1-21-gabe81