From 8df085bb42991a3c9bd216b1bbcb73738b29d411 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 21 Aug 2021 09:10:01 -0500 Subject: [PATCH] Rewrite early-init.el --- early-init.el | 96 ++++++++++++++++++++++++++-------------------- lisp/acdw-frame.el | 36 +++++++++++++++++ 2 files changed, 91 insertions(+), 41 deletions(-) create mode 100644 lisp/acdw-frame.el diff --git a/early-init.el b/early-init.el index 27c8450..4037fde 100644 --- a/early-init.el +++ b/early-init.el @@ -24,23 +24,24 @@ load-path) (require 'acdw) - ;;; Speed up init ;; see doom-emacs, et al. -(setq load-prefer-newer noninteractive - orig-file-name-handler-alist file-name-handler-alist +(setq acdw/orig-file-name-handler-alist file-name-handler-alist file-name-handler-alist nil - inhibit-x-resources t) -(acdw/gc-disable) + gc-cons-percentage 0.8 + gc-cons-threshold most-positive-fixnum + load-prefer-newer noninteractive) (add-hook 'after-init-hook (defun after-init@reset () - (acdw/gc-enable) + "Reset `file-name-handler-alist' and garbage collection." + (setq gc-cons-percentage 0.1 + gc-cons-threshold (* 800 1024 1024)) (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-to-list 'acdw/orig-file-name-handler-alist handler)) + (setq file-name-handler-alist acdw/orig-file-name-handler-alist))) + ;;; Frame settings (setq default-frame-alist ; Remove most UI `((tool-bar-lines . 0) ; No tool bar @@ -63,53 +64,65 @@ (add-hook 'after-init-hook (defun after-init@disable-ui-modes () + "Disable UI modes after init. +I already disable them from the `default-frame-alist' for speed +and anti-flickering reasons, but this function allows running, +say, `tool-bar-mode' once to toggle the tool bar back on." (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) - )) + (horizontal-scroll-bar-mode . horizontal-scroll-bars))) (let ((setting (alist-get (cdr mode) default-frame-alist))) (when (or (not setting) - (= 0 setting)) + (zerop setting)) (funcall (car mode) -1)))))) (add-hook 'after-make-frame-functions - (defun acdw/frame-setup (&rest args) + (defun after-make-frame@setup (&rest args) (ignore args) - ;; fonts - (require 'acdw-fonts) - (setq acdw-fonts/monospace (acdw/system - (:home "DejaVu Sans Mono") - (:work "Consolas") - (_ "monospace")) - acdw-fonts/monospace-size (acdw/system - (:work 12) - (_ 10)) - acdw-fonts/variable (acdw/system - (:home "Inter") - (:work "Inter") - (_ "sans-serif")) - acdw-fonts/variable-size (acdw/system - (:work 14) - (_ 12))) - (acdw-fonts/set) - (acdw-fonts/setup-emoji-fonts "Segoe UI Emoji" - "Noto Color Emoji" - "Apple Color Emoji" - "Symbola") - ;; fringes - (acdw/setup-fringes))) + (let ((monospace-faces '((:font "DejaVu Sans Mono" :height 100) + (:font "Consolas" :height 100) + (:font "monospace" :height 100)))) + (acdw/set-first-face-attribute 'default monospace-faces) + (acdw/set-first-face-attribute 'fixed-pitch monospace-faces) + (acdw/set-first-face-attribute 'variable-pitch + '((:font "Inter" :height 12) + (:font "sans-serif" + :height 10)))) + (acdw/set-emoji-fonts "Segoe UI Emoji" + "Noto Color Emoji" + "Apple Color Emoji" + "Symbola") + (acdw/set-fringes '((left-curly-arrow [#b01100000 + #b00110000 + #b00011000 + #b00001100] + 4 8 center) + (right-curly-arrow [#b00000011 + #b00000110 + #b00001100 + #b00011000] + 4 8 center) + (left-arrow [#b01100000 + #b01010000] + 2 8 (top t)) + (right-arrow [#b00000011 + #b00000101] + 2 8 (top t)))) + (setq indicate-empty-lines nil + indicate-buffer-boundaries '((top . right) + (bottom . right))) + (custom-set-faces '(fringe ((t (:foreground "dim gray"))))))) ;; I have this here because ... the first frame doesn't ? run ? the hook ??? (add-function :after after-focus-change-function - (defun acdw/first-frame-setup (&rest args) + (defun after-focus-change@first-frame-setup (&rest args) (ignore args) - (acdw/frame-setup) + (after-make-frame@setup) (remove-function after-focus-change-function - #'acdw/first-frame-setup))) + #'after-focus-change@first-frame-setup))) - ;;; Bootstrap package manager (`straight.el') ;; 1. Update `exec-path'. @@ -161,7 +174,6 @@ ;; By the way, the alias is `straight-package-neutering-mode'. (defalias 'straight-ಠ_ಠ-mode nil) - ;;; Message startup time for profiling ;; This just redefines the Emacs function ;; `display-startup-echo-area-message', so no hooks needed. @@ -172,3 +184,5 @@ (float-time (time-subtract after-init-time before-init-time))) gcs-done)) + +;;; early-init.el ends here diff --git a/lisp/acdw-frame.el b/lisp/acdw-frame.el new file mode 100644 index 0000000..753fd14 --- /dev/null +++ b/lisp/acdw-frame.el @@ -0,0 +1,36 @@ +;;; acdw-frame.el -*- lexical-binding: t; coding: utf-8-unix -*- + +;;; Fonts + +(defun acdw/set-first-face-attribute (face font-list) + "Set FACE to the first font found in FONT-LIST. +FONT-LIST is a list of `font-spec' plists to be passed to +`set-face-attribute'." + (cond + ((or (null window-system) + (null font-list)) + nil) + ((x-list-fonts (or (plist-get (car font-list) :font) + (plist-get (car font-list) :family))) + (apply #'set-face-attribute face nil (car font-list))) + (t (acdw/set-first-face-attribute face (cdr font-list))))) + +(defun acdw/set-emoji-fonts (&rest emoji-fonts) + "Add all installed EMOJI-FONTS to the symbol fontset." + (let ((ffl (font-family-list))) + (dolist (font emoji-fonts) + (when (member font ffl) + (set-fontset-font t 'symbol + (font-spec :family font) nil 'append))))) + +;;; Fringes + +(defun acdw/set-fringes (bitmap-list) + "Apply multiple fringes at once. +BITMAP-LIST is a list of arglists passed directly to +`define-fringe-bitmap', which see." + (dolist (bitmap bitmap-list) + (apply #'define-fringe-bitmap bitmap)) + (redraw-frame)) + +(provide 'acdw-frame)