wip: feat: Defer many packages

Shaving MILLISECONDS off our startup time!!!  Fuck yes!

I've measured the average startup time to be 0.68s in the previous commit, and an average of 0.52 with this commit.
This commit is contained in:
Madeleine Sydney
2025-01-08 06:52:18 -07:00
parent 27e78453e3
commit ab10e0ca56
9 changed files with 138 additions and 79 deletions

View File

@@ -2,10 +2,26 @@
;; Vim emulation.
(use-package evil
:init
(setq evil-want-minibuffer t)
(setq evil-move-beyond-eol t)
(setq evil-vsplit-window-right t)
:preface
(setq evil-want-minibuffer t
evil-move-beyond-eol t
evil-vsplit-window-right t
evil-ex-search-vim-style-regexp t
evil-ex-visual-char-range t
evil-mode-line-format nil
evil-normal-state-cursor 'box
evil-emacs-state-cursor 'hbar
evil-operator-state-cursor 'evil-half-cursor
evil-insert-state-cursor 'bar
evil-visual-state-cursor 'hollow
;; Only do highlighting in selected window so that Emacs has less work
;; to do highlighting them all.
evil-ex-interactive-search-highlight 'selected-window
;; It's infuriating that innocuous "beginning of line" or "end of line"
;; errors will abort macros, so suppress them:
evil-kbd-macro-suppress-motion-error t
evil-undo-system (cond ((featurep 'undo-tree) 'undo-tree)
((featurep 'undo-fu) 'undo-fu)))
;; These two are required for evil-collection.
(setq evil-want-keybinding nil
evil-want-integration t)
@@ -20,16 +36,18 @@
;; integrations.
(use-package evil-collection
:after evil
:custom
(evil-collection-setup-minibuffer t)
:custom (evil-collection-setup-minibuffer t)
:config
(evil-collection-init))
;; Tim Pope's famous `surround.vim' for Evil.
(use-package evil-surround
:ensure t
:commands (global-evil-surround-mode
evil-surround-edit
evil-Surround-edit
evil-surround-region)
:hook (on-first-input . global-evil-surround-mode)
:config
(global-evil-surround-mode 1)
;; In `emacs-lisp-mode', `' is a much more common pair than ``.
(add-hook 'emacs-lisp-mode-hook
(lambda ()
@@ -38,20 +56,21 @@
;; TODO: I'd like JK to escape visual state. evil-escape only allows defining a
;; single key sequence. Perhaps key-chord is capable of this?
(use-package evil-escape
:config
(setq-default evil-escape-key-sequence "jk"
evil-escape-delay 0.15)
(evil-escape-mode 1))
:hook (on-first-input . evil-escape-mode)
:custom ((evil-escape-key-sequence "jk")
(evil-escape-delay 0.15)))
;; `evil-nerd-commenter' has a bunch of cool functions[1]. Here, only the Evil
;; operator is used. }:3
;; [1]: https://github.com/redguardtoo/evil-nerd-commenter?tab=readme-ov-file#commands-and-hotkeys
(use-package evil-nerd-commenter
:config
(define-key evil-normal-state-map "#" #'evilnc-comment-operator)
(define-key evil-visual-state-map "#" #'evilnc-comment-operator)
(define-key evil-inner-text-objects-map "c" 'evilnc-inner-commenter)
(define-key evil-outer-text-objects-map "c" 'evilnc-outer-commenter))
:commands (evilnc-comment-operator
evilnc-inner-comment
evilnc-outer-commenter)
:bind (:map evil-normal-state-map ("#" . evilnc-comment-operator)
:map evil-visual-state-map ("#" . evilnc-comment-operator)
:map evil-inner-text-objects-map ("c" . evilnc-inner-comment)
:map evil-outer-text-objects-map ("c" . evilnc-outer-comment)))
;; Enhance `evil-surround' with integration with `embrace'.
(use-package evil-embrace
@@ -60,68 +79,60 @@
:config
(evil-embrace-enable-evil-surround-integration))
;; Provides a command to swap two regions of text.
;; Provides an Evil operator to swap two spans of text.
(use-package evil-exchange
:config
(define-key evil-normal-state-map "gX" 'evil-exchange)
(define-key evil-visual-state-map "gX" 'evil-exchange))
:bind (:map evil-normal-state-map ("gX" . evil-exchange)
:map evil-visual-state-map ("gX" . evil-exchange)))
;; Evil doesn't ship with support for Vim's 'g-'/'g+'. `evil-numbers'
;; implements this.
(use-package evil-numbers
:config
;; 'g=' is a bit more comfortable than 'g+', whilst preserving the analogy.
;; ('=' is '+' modulo shift)
(define-key evil-normal-state-map "g=" 'evil-numbers/inc-at-pt)
(define-key evil-normal-state-map "g-" 'evil-numbers/dec-at-pt))
:bind (:map evil-normal-state-map ("g=" . 'evil-numbers/inc-at-pt)
:map evil-normal-state-map ("g-" . 'evil-numbers/dec-at-pt)))
;; Tree-sitter queries → Evil text objects.
(use-package evil-textobj-tree-sitter)
(use-package evil-textobj-tree-sitter
:defer t)
;; Visually "flash" the region acted upon by Evil-mode operations.
(use-package evil-goggles
:hook (on-first-input . evil-goggles-mode)
;; The flash animation will delay actions, which can be very annoying for some
;; operations. Disable `evil-goggles' for those ones.
:custom
(evil-goggles-enable-delete nil)
(evil-goggles-enable-change nil)
(evil-goggles-duration 0.1)
:config
(evil-goggles-mode 1))
((evil-goggles-enable-delete nil)
(evil-goggles-enable-change nil)
(evil-goggles-duration 0.1)))
;; Change cursor shape and color by evil state in terminal.
(use-package evil-terminal-cursor-changer
;; This package is only useful in the terminal.
:if (not (display-graphic-p))
:config
(setq evil-motion-state-cursor 'box)
(setq evil-visual-state-cursor 'box)
(setq evil-normal-state-cursor 'box)
(setq evil-insert-state-cursor 'bar)
(setq evil-emacs-state-cursor 'hbar)
(evil-terminal-cursor-changer-activate))
:hook (on-first-input . evil-terminal-cursor-changer-activate))
;; Automatic alignment in region, by regexp.
(use-package evil-lion
:config
(evil-lion-mode 1))
:hook (on-first-input . evil-lion-mode))
;; Provides the 'g' text object which selects the entire buffer.
(use-package evil-textobj-entire)
;; 'g' text object selecting the entire buffer.
(with-eval-after-load 'evil
(evil-define-text-object
evil-entire-buffer (count &optional beg end type)
"Select entire buffer"
(evil-range (point-min) (point-max) type))
(define-key evil-inner-text-objects-map "g" #'evil-entire-buffer)
(define-key evil-outer-text-objects-map "g" #'evil-entire-buffer))
;; 2-character search.
(use-package evil-snipe
:commands evil-snipe-local-mode evil-snipe-override-local-mode
:hook (on-first-input . evil-snipe-override-mode)
:hook (on-first-input . evil-snipe-mode)
:init
(setq evil-snipe-smart-case t
evil-snipe-scope 'visible
evil-snipe-repeat-scope 'visible
evil-snipe-char-fold t))
;; Extend the set of delimiters recognised by '%'.
(use-package evil-matchit
:config
(global-evil-matchit-mode 1))
:commands (evil-snipe-local-mode evil-snipe-override-local-mode)
:hook ((on-first-input . evil-snipe-override-mode)
(on-first-input . evil-snipe-mode))
:custom ((evil-snipe-smart-case t)
(evil-snipe-scope 'visible)
(evil-snipe-repeat-scope 'visible)
(evil-snipe-char-fold t)))
(provide 'syd-evil)