This commit is contained in:
parent
453c4b112f
commit
983c7330e8
256
early-init.el
256
early-init.el
|
@ -1,10 +1,9 @@
|
||||||
;;; early-init.el -*- lexical-binding: t; coding: utf-8 -*-
|
;;; early-init.el -*- lexical-binding: t; coding: utf-8-unix -*-
|
||||||
;; Copyright (C) 2020-2021 Case Duckworth
|
|
||||||
;;
|
;;
|
||||||
;; Author: Case Duckworth <acdw@acdw.net>
|
;; Author: Case Duckworth <acdw@acdw.net>
|
||||||
;; Created: Sometime during Covid-19, 2020
|
;; Created: Sometime during Covid-19, 2020
|
||||||
;; Keywords: configuration
|
;; Keywords: configuration
|
||||||
;; URL https://tildegit.org/acdw/emacs
|
;; URL: https://tildegit.org/acdw/emacs
|
||||||
;;
|
;;
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
;;
|
;;
|
||||||
|
@ -23,174 +22,85 @@
|
||||||
;;
|
;;
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
;; Speed up init
|
;;; Define personal-use constants
|
||||||
(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?
|
|
||||||
(defconst acdw/system (pcase system-type
|
(defconst acdw/system (pcase system-type
|
||||||
('gnu/linux :home)
|
('gnu/linux :home)
|
||||||
((or 'msdos 'windows-nt) :work)
|
((or 'msdos 'windows-nt) :work)
|
||||||
(_ :other)))
|
(_ :other))
|
||||||
|
"Which system is currently being used.")
|
||||||
|
|
||||||
;; Frame initiation
|
(defvar acdw/dir (expand-file-name
|
||||||
|
(convert-standard-filename "var/")
|
||||||
|
user-emacs-directory)
|
||||||
|
"A directory to hold extra configuration and emacs data.")
|
||||||
|
|
||||||
;; Initialize frames with as little UI as possible.
|
;;; Speed up init
|
||||||
(setq-default
|
;; see doom-emacs, et al.
|
||||||
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
|
(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'.")
|
||||||
|
|
||||||
scroll-margin 0 ; how many lines to show at window edge
|
(defconst gc-cons-percentage-basis 0.1
|
||||||
scroll-conservatively 101 ; just enough to bring text into view
|
"The basis value for `gc-cons-percentage' to return to after init.
|
||||||
scroll-preserve-screen-position 1 ; always keep screen position
|
0.1 is Emacs's default `gc-cons-percentage'.")
|
||||||
|
|
||||||
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
|
(defvar orig-file-name-handler-alist file-name-handler-alist
|
||||||
`("%e"
|
"The original value of `file-name-handler-alist' will be restored
|
||||||
mode-line-front-space
|
after init.")
|
||||||
;; 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
|
|
||||||
))
|
|
||||||
|
|
||||||
;; Set the rest of the fonts after initiation
|
(setq gc-cons-threshold most-positive-fixnum
|
||||||
(defun hook--setup-fonts ()
|
gc-cons-percentage 0.6
|
||||||
(pcase acdw/system
|
file-name-handler-alist nil)
|
||||||
(: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))))
|
|
||||||
|
|
||||||
(add-hook 'after-init-hook #'hook--setup-fonts)
|
(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))
|
||||||
|
|
||||||
;; In case I do want the UI elements later, I also disable the modes
|
(add-hook 'after-init-hook #'hook--post-init-reset)
|
||||||
;; -- otherwise I'd have to run the mode twice to actually show the
|
|
||||||
;; thing.
|
;; ;;; 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 ()
|
(defun hook--disable-ui-modes ()
|
||||||
(dolist (mode '(tool-bar-mode
|
"Disable frame UI using modes, for toggling later."
|
||||||
menu-bar-mode
|
(dolist (mode ;; each mode is of the form (MODE . FRAME-ALIST-VAR)
|
||||||
scroll-bar-mode
|
'((tool-bar-mode . tool-bar-lines)
|
||||||
horizontal-scroll-bar-mode))
|
(menu-bar-mode . menu-bar-lines)
|
||||||
(funcall mode -1)))
|
(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)
|
(add-hook 'after-init-hook #'hook--disable-ui-modes)
|
||||||
|
|
||||||
;; Customize the fringe
|
;;; Bootstrap package manager (`straight.el')
|
||||||
(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'.
|
|
||||||
|
|
||||||
|
;; 1. Update `exec-path'.
|
||||||
(let ((win-app-dir "~/Applications"))
|
(let ((win-app-dir "~/Applications"))
|
||||||
(dolist (path (list
|
(dolist (path (list
|
||||||
;; Windows
|
;; Windows
|
||||||
|
@ -210,26 +120,19 @@
|
||||||
))
|
))
|
||||||
(when (file-exists-p path)
|
(when (file-exists-p path)
|
||||||
(add-to-list 'exec-path path :append))))
|
(add-to-list 'exec-path path :append))))
|
||||||
|
;; 1.5. Update $PATH to reflect changes.
|
||||||
;; Set $PATH back to `exec-path', for symmetry's sake.
|
|
||||||
(setenv "PATH" (mapconcat #'identity exec-path path-separator))
|
(setenv "PATH" (mapconcat #'identity exec-path path-separator))
|
||||||
|
|
||||||
;; Set some variables
|
;; 2. Set `package' and `straight' variables.
|
||||||
(defvar acdw/etc-dir
|
(setq package-enable-at-startup nil ; not sure if strictly
|
||||||
(expand-file-name "etc/" user-emacs-directory)
|
; necessary
|
||||||
"Where to put other configurations.")
|
package-quickstart nil ; ditto
|
||||||
(defvar acdw/var-dir
|
straight-host-usernames '((github . "duckwork")
|
||||||
(expand-file-name "var/" user-emacs-directory)
|
(gitlab . "acdw"))
|
||||||
"Where to put variable stuff.")
|
straight-base-dir acdw/dir ; don't clutter ~/.emacs.d
|
||||||
|
)
|
||||||
|
|
||||||
(setq-default package-enable-at-startup nil
|
;; 3. Bootstrap `straight'.
|
||||||
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)
|
(defvar bootstrap-version)
|
||||||
(let ((bootstrap-file
|
(let ((bootstrap-file
|
||||||
(expand-file-name
|
(expand-file-name
|
||||||
|
@ -239,20 +142,17 @@
|
||||||
(unless (file-exists-p bootstrap-file)
|
(unless (file-exists-p bootstrap-file)
|
||||||
(with-current-buffer
|
(with-current-buffer
|
||||||
(url-retrieve-synchronously
|
(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)
|
'silent 'inhibit-cookies)
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
(eval-print-last-sexp)))
|
(eval-print-last-sexp)))
|
||||||
(load bootstrap-file nil 'nomessage))
|
(load bootstrap-file nil 'nomessage))
|
||||||
|
|
||||||
;; `use-package'
|
;;; Message startup time for profiling
|
||||||
|
|
||||||
(straight-use-package 'use-package)
|
|
||||||
(require 'use-package)
|
|
||||||
|
|
||||||
;; Message startup time
|
|
||||||
(defun hook--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."
|
(message "Emacs ready in %s with %d garbage collections."
|
||||||
(format "%.2f seconds"
|
(format "%.2f seconds"
|
||||||
(float-time (time-subtract after-init-time
|
(float-time (time-subtract after-init-time
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
:;;; acdw.el -*- lexical-binding: t; coding: utf-8-unix -*-
|
||||||
|
;;
|
||||||
|
;; Author: Case Duckworth <acdw@acdw.net>
|
||||||
|
;; Created: Sometime during Covid-19, 2020
|
||||||
|
;; Keywords: configuration
|
||||||
|
;; URL: https://tildegit.org/acdw/emacs
|
||||||
|
;; Bankruptcy: 5b
|
||||||
|
;;
|
||||||
|
;; 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.
|
||||||
|
;;
|
||||||
|
;;; Commentary:
|
||||||
|
;; `acdw.el' contains `acdw/map', its mode, and assorted ease-of-life
|
||||||
|
;; functions for me, acdw.
|
||||||
|
;;
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
;;; Directories (think `no-littering')
|
||||||
|
|
||||||
|
(defvar acdw/dir (expand-file-name
|
||||||
|
(convert-standard-filename "var/")
|
||||||
|
user-emacs-directory)
|
||||||
|
"A directory to hold extra configuration and emacs data.")
|
||||||
|
|
||||||
|
(defun acdw/in-dir (file &optional make-directory)
|
||||||
|
"Expand FILE relative to `acdw/dir', optionally creating its
|
||||||
|
directory."
|
||||||
|
(let ((f (expand-file-name (convert-standard-filename file)
|
||||||
|
acdw/dir)))
|
||||||
|
(when make-directory
|
||||||
|
(make-directory (file-name-directory) 'parents))
|
||||||
|
f))
|
||||||
|
|
||||||
|
;;; Settings
|
||||||
|
|
||||||
|
(defun acdw/set (assignments)
|
||||||
|
"Perform `customize-set-variable' on each of ASSIGNMENTS.
|
||||||
|
|
||||||
|
ASSIGNMENTS is a list where each element is of the form
|
||||||
|
(VARIABLE VALUE [COMMENT])."
|
||||||
|
(dolist (assn assignments)
|
||||||
|
(customize-set-variable (car assignment)
|
||||||
|
(cadr assignment)
|
||||||
|
(if (and (caddr assignment)
|
||||||
|
(stringp (caddr assignment)))
|
||||||
|
(caddr assignment)
|
||||||
|
"Customized by `acdw/set'."))))
|
||||||
|
|
||||||
|
;;; Keymap & Mode
|
||||||
|
|
||||||
|
(defvar acdw/map (make-sparse-keymap)
|
||||||
|
"A keymap for my custom bindings.")
|
||||||
|
|
||||||
|
(define-minor-mode acdw/mode
|
||||||
|
"A mode for `acdw/map'."
|
||||||
|
:init-value t
|
||||||
|
:lighter " acdw"
|
||||||
|
:keymap acdw/map)
|
||||||
|
(define-globalized-minor-mode acdw/global-mode acdw/mode acdw/mode)
|
||||||
|
|
||||||
|
;; Disable `acdw/mode' in the minibuffer
|
||||||
|
(defun acdw/mode--disable ()
|
||||||
|
"Disable `acdw/mode'."
|
||||||
|
(acdw/mode -1))
|
||||||
|
(add-hook 'minibuffer-setup-hook #'acdw/mode--disable)
|
||||||
|
|
||||||
|
;; Set up a leader key for `acdw/mode'
|
||||||
|
(defvar acdw/leader
|
||||||
|
(let ((map (make-sparse-keymap))
|
||||||
|
(c-z (global-key-binding "\C-z")))
|
||||||
|
(define-key acdw/map "\C-z" map)
|
||||||
|
(define-key map "\C-z" c-z)
|
||||||
|
map))
|
||||||
|
|
||||||
|
(provide 'acdw)
|
||||||
|
;;; acdw.el ends here
|
Loading…
Reference in New Issue