From 3f60767599db61c95333969869287d792d37159a Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 28 Feb 2021 23:58:57 -0600 Subject: Restart shit --- early-init.el | 297 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 216 insertions(+), 81 deletions(-) (limited to 'early-init.el') diff --git a/early-init.el b/early-init.el index ef72beb..36bacbe 100644 --- a/early-init.el +++ b/early-init.el @@ -1,21 +1,180 @@ -;;; early-init.el -*- no-byte-compile: t; coding: utf-8 -*- -;; Copyright (C) 2020 Case Duckworth - +;;; early-init.el -*- lexical-binding: t; coding: utf-8 -*- +;; Copyright (C) 2020-2021 Case Duckworth +;; ;; Author: Case Duckworth -;; Created: Sometime during the Covid-19 lockdown, 2019 +;; 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. +;; +;;; 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: -;; This file is not part of GNU Emacs. +;; Speed up init +(setq gc-cons-threshold most-positive-fixnum + gc-cons-percentage 0.6 + comp-deferred-compilation nil) -;;; Commentary: -;; This file is automatically tangled from config.org. -;; Hand edits will be overwritten! +(defconst gc-cons-basis (* 800 1024) + "The basis value to which to return after a max jump. +800,000 (800 KB) is Emacs' default.") -;;; Code: +(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 doom-reset-file-handler-alist-h () + (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 #'doom-reset-file-handler-alist-h)) + +;; 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") + ) + +;; 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 + :familiy "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)))) + +(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])) +(add-hook 'after-init-hook #'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'. -(message "%s..." "Loading early-init.el") -;; BOOTSTRAP PACKAGE MANAGEMENT (let ((win-app-dir "~/Applications")) (dolist (path (list ;; Windows @@ -31,21 +190,44 @@ (expand-file-name "bin" user-emacs-directory) (expand-file-name "~/bin") (expand-file-name "~/.local/bin") - (expand-file-name "~/Scripts") + (expand-file-name "~/usr/bin") )) (when (file-exists-p path) (add-to-list 'exec-path path :append)))) -;; Set $PATH +;; Set $PATH back to `exec-path', for symmetry's sake. (setenv "PATH" (mapconcat #'identity exec-path path-separator)) -(setq package-enable-at-startup nil) -(defun acdw/bootstrap-straight () - "Bootstrap straight.el." + +;; 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, after gitting the code directly. +(if (not (executable-find "git")) + (error "No 'git' in $PATH!") + (call-process "git" nil + (get-buffer-create "*bootstrap-straight-messages*") + nil + "clone" + "https://github.com/raxod502/straight.el" + (expand-file-name "repos/straight.el" + straight-base-dir)) (defvar bootstrap-version) (let ((bootstrap-file (expand-file-name - "straight/repos/straight.el/bootstrap.el" - user-emacs-directory)) + "repos/straight.el/bootstrap.el" + straight-base-dir)) (bootstrap-version 5)) (unless (file-exists-p bootstrap-file) (with-current-buffer @@ -57,67 +239,20 @@ (goto-char (point-max)) (eval-print-last-sexp))) (load bootstrap-file nil 'nomessage))) -(when (executable-find "git") - (unless (ignore-errors (acdw/bootstrap-straight)) - (let ((msg "Straight.el didn't bootstrap correctly. Cloning directly")) - (message "%s..." msg) - (call-process "git" nil - (get-buffer-create "*bootstrap-straight-messages*") nil - "clone" - "https://github.com/raxod502/straight.el" - (expand-file-name "straight/repos/straight.el" - user-emacs-directory)) - (message "%s...Done." msg) - (acdw/bootstrap-straight)))) -;; SETUP FRAME -(add-to-list 'default-frame-alist - '(tool-bar-lines . 0)) - -(tool-bar-mode -1) -(add-to-list 'default-frame-alist - '(menu-bar-lines . 0)) - -(menu-bar-mode -1) -(add-to-list 'default-frame-alist - '(vertical-scroll-bars . nil) - '(horizontal-scroll-bars . nil)) - -(scroll-bar-mode -1) -(horizontal-scroll-bar-mode -1) -(setq-default frame-inhibit-implied-resize t - frame-resize-pixelwise t) -(setq-default indicate-empty-lines t) -(setq-default indicate-buffer-boundaries 'right) -(setq-default visual-line-fringe-indicators '(left-curly-arrow nil)) -(defun hook--setup-fringes-curly-arrows () - "Set up curly-arrow fringes." - (define-fringe-bitmap 'left-curly-arrow - [#b11000000 - #b01100000 - #b00110000 - #b00011000]) - (define-fringe-bitmap 'right-curly-arrow - [#b00011000 - #b00110000 - #b01100000 - #b11000000])) - -(add-hook 'after-init-hook #'hook--setup-fringes-curly-arrows) -(defun hook--setup-fringes-arrows () - "Setup arrow fringe bitmaps." - (define-fringe-bitmap 'left-arrow - [#b00000000 - #b01010100 - #b01010100 - #b00000000]) - (define-fringe-bitmap 'right-arrow - [#b00000000 - #b00101010 - #b00101010 - #b00000000])) - -(add-hook 'after-init-hook #'hook--setup-fringes-arrows) -(message "%s... Done." "Loading early-init.el") -;;; early-init.el ends here +;; `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) -- cgit 1.4.1-21-gabe81