Improve vanity metric: startup time

This commit is contained in:
David Morgan 2022-10-14 12:29:07 +01:00
parent 05edd37e19
commit fc3ad64579
Signed by: djm
GPG Key ID: C171251002C200F2
4 changed files with 99 additions and 106 deletions

View File

@ -12,7 +12,7 @@
(dabbrev-case-replace nil)) (dabbrev-case-replace nil))
(use-feature hippie-expand (use-feature hippie-expand
:init :config
(setq hippie-expand-try-functions-list (setq hippie-expand-try-functions-list
'(;yas-hippie-try-expand '(;yas-hippie-try-expand
try-expand-dabbrev try-expand-dabbrev
@ -25,7 +25,6 @@
try-expand-line try-expand-line
try-complete-lisp-symbol-partially try-complete-lisp-symbol-partially
try-complete-lisp-symbol)) try-complete-lisp-symbol))
:config
;; https://www.emacswiki.org/emacs/HippieExpand#h5o-9 ;; https://www.emacswiki.org/emacs/HippieExpand#h5o-9
(defadvice he-substitute-string (after he-paredit-fix) (defadvice he-substitute-string (after he-paredit-fix)
"Remove extra paren when expanding line in paredit." "Remove extra paren when expanding line in paredit."
@ -52,20 +51,23 @@
(setq tab-always-indent 'complete)) (setq tab-always-indent 'complete))
(use-package orderless (use-package orderless
:defer 2
:bind (:map minibuffer-local-map :bind (:map minibuffer-local-map
("C-l" . my/orderless-match-components-literally)) ("C-l" . my/orderless-match-components-literally))
:custom (orderless-component-separator 'orderless-escapable-split-on-space) :custom
:init (orderless-component-separator 'orderless-escapable-split-on-space)
(setq completion-styles '(orderless partial-completion basic) (completion-styles '(orderless partial-completion basic))
completion-category-defaults nil (completion-category-defaults nil)
completion-category-overrides '((file (styles . (partial-completion orderless))))) (completion-category-overrides '((file (styles . (partial-completion orderless)))))
(orderless-matching-styles '(orderless-literal orderless-regexp orderless-strict-leading-initialism))
(orderless-style-dispatchers '(+orderless-dispatch))
:config
(defun my/orderless-match-components-literally () (defun my/orderless-match-components-literally ()
"Components match literally for the rest of the session." "Components match literally for the rest of the session."
(interactive) (interactive)
(setq-local orderless-matching-styles '(orderless-literal) (setq-local orderless-matching-styles '(orderless-literal)
orderless-style-dispatchers nil)) orderless-style-dispatchers nil))
:config
(defun orderless-strict-initialism (component &optional leading) (defun orderless-strict-initialism (component &optional leading)
"Match a component as a strict leading initialism. "Match a component as a strict leading initialism.
This means the characters in COMPONENT must occur in the This means the characters in COMPONENT must occur in the
@ -124,10 +126,7 @@ no words in between, beginning with the first word."
((if-let (x (assq (aref word 0) +orderless-dispatch-alist)) ((if-let (x (assq (aref word 0) +orderless-dispatch-alist))
(cons (cdr x) (substring word 1)) (cons (cdr x) (substring word 1))
(when-let (x (assq (aref word (1- (length word))) +orderless-dispatch-alist)) (when-let (x (assq (aref word (1- (length word))) +orderless-dispatch-alist))
(cons (cdr x) (substring word 0 -1))))))) (cons (cdr x) (substring word 0 -1))))))))
(setq orderless-matching-styles '(orderless-literal orderless-regexp orderless-strict-leading-initialism)
orderless-style-dispatchers '(+orderless-dispatch)))
;; code completion - corfu ;; code completion - corfu
(use-package corfu (use-package corfu
@ -139,12 +138,11 @@ no words in between, beginning with the first word."
([tab] . corfu-next) ([tab] . corfu-next)
("S-TAB" . corfu-previous) ("S-TAB" . corfu-previous)
([backtab] . corfu-previous)) ([backtab] . corfu-previous))
:init :hook (emacs-startup . global-corfu-mode))
(global-corfu-mode))
(use-package corfu-doc (use-package corfu-doc
:config :hook
(add-hook 'corfu-mode-hook #'corfu-doc-mode)) (corfu-mode . corfu-doc-mode))
(use-package cape (use-package cape
:bind (("C-c p p" . completion-at-point) ;; capf :bind (("C-c p p" . completion-at-point) ;; capf

View File

@ -5,8 +5,12 @@
;; Relies on orderless config in init-completion.el ;; Relies on orderless config in init-completion.el
;;; Code: ;;; Code:
(use-package emacs (use-package vertico
:init :straight (vertico :files (:defaults "extensions/*")
:includes (vertico-directory vertico-repeat))
:hook (emacs-startup . vertico-mode)
:custom (vertico-cycle t)
:config
;; Do not allow the cursor in the minibuffer prompt ;; Do not allow the cursor in the minibuffer prompt
(setq minibuffer-prompt-properties (setq minibuffer-prompt-properties
'(read-only t cursor-intangible t face minibuffer-prompt)) '(read-only t cursor-intangible t face minibuffer-prompt))
@ -28,15 +32,8 @@
;; Emacs 28: Hide commands in M-x which do not work in the current mode. ;; Emacs 28: Hide commands in M-x which do not work in the current mode.
;; Vertico commands are hidden in normal buffers. ;; Vertico commands are hidden in normal buffers.
(setq read-extended-command-predicate (setq read-extended-command-predicate
#'command-completion-default-include-p)) #'command-completion-default-include-p)
(use-package vertico
:straight (vertico :files (:defaults "extensions/*")
:includes (vertico-directory vertico-repeat))
:init
(vertico-mode)
:custom (vertico-cycle t)
:config
(advice-add #'vertico--format-candidate :around (advice-add #'vertico--format-candidate :around
(lambda (orig cand prefix suffix index start) (lambda (orig cand prefix suffix index start)
(setq cand (funcall orig cand prefix suffix index start)) (setq cand (funcall orig cand prefix suffix index start))
@ -99,7 +96,7 @@ DEFS is a plist associating completion categories to commands."
(use-feature vertico-directory (use-feature vertico-directory
:after vertico :after vertico
:init :config
(defvar switching-project nil) (defvar switching-project nil)
(defun vertico-directory-enter-or-select-project () (defun vertico-directory-enter-or-select-project ()
"vertico-directory-enter wrapper that plays nicely with selecting new projects." "vertico-directory-enter wrapper that plays nicely with selecting new projects."
@ -140,13 +137,12 @@ DEFS is a plist associating completion categories to commands."
(define-vertico-key "M-DEL" (define-vertico-key "M-DEL"
'file #'vertico-directory-delete-word 'file #'vertico-directory-delete-word
'project-file #'vertico-directory-delete-word) 'project-file #'vertico-directory-delete-word)
:config
:commands (vertico-directory-enter vertico-directory-delete-word vertico-directory-delete-char) :commands (vertico-directory-enter vertico-directory-delete-word vertico-directory-delete-char)
;; Tidy shadowed file names ;; Tidy shadowed file names
:hook (rfn-eshadow-update-overlay . vertico-directory-tidy)) :hook (rfn-eshadow-update-overlay . vertico-directory-tidy))
(use-feature vertico-repeat (use-feature vertico-repeat
:bind ("M-P" . vertico-repeat)) :bind ("<f9>" . vertico-repeat))
(use-package consult (use-package consult
:bind (;; C-c bindings (mode-specific-map) :bind (;; C-c bindings (mode-specific-map)
@ -198,7 +194,7 @@ DEFS is a plist associating completion categories to commands."
;; Toggle preview on/off without changing preview-key ;; Toggle preview on/off without changing preview-key
("M-P" . consult-toggle-preview))) ("M-P" . consult-toggle-preview)))
:init :config
;; Optionally configure the register formatting. This improves the register ;; Optionally configure the register formatting. This improves the register
;; preview for `consult-register', `consult-register-load', ;; preview for `consult-register', `consult-register-load',
@ -214,8 +210,6 @@ DEFS is a plist associating completion categories to commands."
(setq xref-show-xrefs-function #'consult-xref (setq xref-show-xrefs-function #'consult-xref
xref-show-definitions-function #'consult-xref) xref-show-definitions-function #'consult-xref)
:config
(defun consult-ripgrep-symbol-at-point (&optional dir initial) (defun consult-ripgrep-symbol-at-point (&optional dir initial)
(interactive (interactive
(list prefix-arg (when-let ((s (symbol-at-point))) (list prefix-arg (when-let ((s (symbol-at-point)))
@ -410,9 +404,9 @@ DEFS is a plist associating completion categories to commands."
(use-package consult-project-extra) (use-package consult-project-extra)
(use-package marginalia (use-package marginalia
:init :hook (emacs-startup . marginalia-mode)
:config
;; crux-recentf-find-file ;; crux-recentf-find-file
(marginalia-mode)
(add-to-list 'marginalia-prompt-categories '("Choose recent file" . file))) (add-to-list 'marginalia-prompt-categories '("Choose recent file" . file)))
(use-package embark (use-package embark
@ -428,8 +422,8 @@ DEFS is a plist associating completion categories to commands."
(:map embark-become-file+buffer-map (:map embark-become-file+buffer-map
("e" . consult-project-extra-find) ("e" . consult-project-extra-find)
("E" . project-switch-consult-project-extra-find))) ("E" . project-switch-consult-project-extra-find)))
:init :custom
(setq prefix-help-command #'embark-prefix-help-command) (prefix-help-command 'embark-prefix-help-command)
:config :config
(defun embark-preview () (defun embark-preview ()
(interactive) (interactive)
@ -446,9 +440,9 @@ DEFS is a plist associating completion categories to commands."
(use-package embark-consult (use-package embark-consult
:after (embark consult) :after (embark consult)
:demand t ; only necessary if you have the hook below ;; demand, combined with after means that this will load after embark and consult
;; if you want to have consult previews as you move around an ;; See https://github.com/oantolin/embark/commit/47daded610b245caf01a97d74c940aff91fe14e2#r46010972
;; auto-updating embark collect buffer :demand t
:bind :bind
(:map embark-consult-async-search-map (:map embark-consult-async-search-map
("^" . consult-ripgrep-parent) ("^" . consult-ripgrep-parent)

View File

@ -47,7 +47,6 @@
(use-package deadgrep) (use-package deadgrep)
(use-package affe (use-package affe
:after (consult orderless)
:config :config
(setq affe-grep-command (replace-regexp-in-string "\\." "-Suu ." affe-grep-command)) (setq affe-grep-command (replace-regexp-in-string "\\." "-Suu ." affe-grep-command))
;; Configure Orderless ;; Configure Orderless

View File

@ -5,13 +5,19 @@
;;; Code: ;;; Code:
(use-package emacs (use-package emacs
:config :hook (emacs-startup . (lambda ()
(cond (cond
((find-font (font-spec :name "iosevka comfy")) ((find-font (font-spec :name "iosevka comfy"))
(set-face-attribute 'default nil :font "iosevka comfy")) (set-face-attribute 'default nil :font "iosevka comfy"))
((find-font (font-spec :name "iosevka")) ((find-font (font-spec :name "iosevka"))
(set-face-attribute 'default nil :font "iosevka"))) (set-face-attribute 'default nil :font "iosevka")))
(global-display-line-numbers-mode)
(global-hl-line-mode +1)
(global-set-key (kbd "C-x C-S-k") 'kill-this-buffer)))
:config
;; https://github.com/rougier/elegant-emacs/blob/master/sanity.el ;; https://github.com/rougier/elegant-emacs/blob/master/sanity.el
(setq inhibit-startup-screen t (setq inhibit-startup-screen t
inhibit-startup-echo-area-message t inhibit-startup-echo-area-message t
@ -32,13 +38,8 @@
scroll-conservatively 100000 scroll-conservatively 100000
scroll-preserve-screen-position 1) scroll-preserve-screen-position 1)
(global-display-line-numbers-mode)
(global-hl-line-mode +1)
(fset 'yes-or-no-p 'y-or-n-p) (fset 'yes-or-no-p 'y-or-n-p)
(global-set-key (kbd "C-x C-S-k") 'kill-this-buffer)
(setq frame-title-format (setq frame-title-format
'("Emacs: " (:eval (if (buffer-file-name) '("Emacs: " (:eval (if (buffer-file-name)
(abbreviate-file-name (buffer-file-name)) (abbreviate-file-name (buffer-file-name))
@ -50,46 +51,58 @@
(setq mac-command-modifier 'super))) (setq mac-command-modifier 'super)))
(use-package modus-themes (use-package modus-themes
:init
(setq modus-themes-syntax '(green-strings yellow-comments)
modus-themes-paren-match '(bold intense underline)
modus-themes-bold-constructs t
modus-themes-italic-constructs t
modus-themes-lang-checkers '(text-also))
(load-theme 'modus-vivendi t)
;; Use less magenta
(custom-set-faces
`(font-lock-builtin-face ((t (:foreground "LawnGreen"))))
`(font-lock-keyword-face ((t (:foreground "gold"))))
`(font-lock-function-name-face ((t (:foreground "cyan"))))
`(font-lock-variable-name-face ((t (:foreground "gold3"))))
`(font-lock-constant-face ((t (:foreground "DeepSkyBlue2"))))
`(font-lock-type-face ((t (:foreground "PaleGreen2"))))
`(font-lock-string-face ((t (:foreground "SpringGreen3"))))
`(font-lock-comment-face ((t (:foreground "burlywood"))))
`(font-lock-doc-face ((t :foreground "LightCyan3")))
`(region ((t (:background "firebrick"))))
`(secondary-selection ((t (:background "firebrick4"))))
`(idle-highlight ((t (:background "grey50" :foreground "white"))))
`(isearch ((t (:background "coral2"))))
`(lazy-highlight ((t (:background "LightSteelBlue2" :foreground "black"))))
`(match ((t (:background "gray35" :foreground "grey85"))))
`(lsp-face-highlight-textual ((t (:background "DimGrey"))))
`(whitespace-empty ((t (:background "gray10"))))
`(hl-line ((t :background "gray15" :underline "gray35" :inherit nil)))
`(simple-modeline-status-modified ((t :foreground "DeepSkyBlue")))
`(consult-async-split ((t :foreground "LightCoral")))
`(orderless-match-face-0 ((t :foreground "tomato")))
`(orderless-match-face-1 ((t :foreground "SpringGreen2")))
`(orderless-match-face-2 ((t :foreground "gold")))
`(orderless-match-face-3 ((t :foreground "cyan")))
`(flycheck-fringe-warning ((t :foreground "white" :background "gold3")))
`(flycheck-fringe-error ((t :foreground "white" :background "red2")))
`(flycheck-fringe-info ((t :foreground "white" :background "RoyalBlue3")))
`(alt-font-lock-keyword-face ((t :foreground "LightSkyBlue" :weight bold)))
`(alt-hl-line-face ((t :underline "gray50" :weight bold))))
:config :config
(defun my/load-theme ()
"Load modus vivendi theme, with my customisations."
(setq modus-themes-syntax '(green-strings yellow-comments)
modus-themes-paren-match '(bold intense underline)
modus-themes-bold-constructs t
modus-themes-italic-constructs t
modus-themes-lang-checkers '(text-also))
(load-theme 'modus-vivendi t)
(custom-set-faces
`(font-lock-builtin-face ((t (:foreground "LawnGreen"))))
`(font-lock-keyword-face ((t (:foreground "gold"))))
`(font-lock-function-name-face ((t (:foreground "cyan"))))
`(font-lock-variable-name-face ((t (:foreground "gold3"))))
`(font-lock-constant-face ((t (:foreground "DeepSkyBlue2"))))
`(font-lock-type-face ((t (:foreground "PaleGreen2"))))
`(font-lock-string-face ((t (:foreground "SpringGreen3"))))
`(font-lock-comment-face ((t (:foreground "burlywood"))))
`(font-lock-doc-face ((t :foreground "LightCyan3")))
`(region ((t (:background "firebrick"))))
`(secondary-selection ((t (:background "firebrick4"))))
`(idle-highlight ((t (:background "grey50" :foreground "white"))))
`(isearch ((t (:background "coral2"))))
`(lazy-highlight ((t (:background "LightSteelBlue2" :foreground "black"))))
`(match ((t (:background "gray35" :foreground "grey85"))))
`(lsp-face-highlight-textual ((t (:background "DimGrey"))))
`(whitespace-empty ((t (:background "gray10"))))
`(hl-line ((t :background "gray15" :underline "gray35" :inherit nil)))
`(simple-modeline-status-modified ((t :foreground "DeepSkyBlue")))
`(consult-async-split ((t :foreground "LightCoral")))
`(orderless-match-face-0 ((t :foreground "tomato")))
`(orderless-match-face-1 ((t :foreground "SpringGreen2")))
`(orderless-match-face-2 ((t :foreground "gold")))
`(orderless-match-face-3 ((t :foreground "cyan")))
`(flycheck-fringe-warning ((t :foreground "white" :background "gold3")))
`(flycheck-fringe-error ((t :foreground "white" :background "red2")))
`(flycheck-fringe-info ((t :foreground "white" :background "RoyalBlue3")))
`(alt-font-lock-keyword-face ((t :foreground "LightSkyBlue" :weight bold)))
`(alt-hl-line-face ((t :underline "gray50" :weight bold))))
(setq hl-todo-keyword-faces
'(("TODO" . "red3")
("FIXME" . "red3")
("DEBUG" . "#A020F0")
("GOTCHA" . "#FF4500")
("HACK" . "#FF4500")
("STUB" . "#1E90FF")
("FAIL" . "red3")
("NOTE" . "DarkOrange2")
("DEPRECATED" . "yellow"))))
(defun use-alt-font-lock-keyword-face () (defun use-alt-font-lock-keyword-face ()
"Remap font-lock-keyword-face to the alternate one, in the current buffer" "Remap font-lock-keyword-face to the alternate one, in the current buffer"
(face-remap-add-relative 'font-lock-keyword-face 'alt-font-lock-keyword-face)) (face-remap-add-relative 'font-lock-keyword-face 'alt-font-lock-keyword-face))
@ -97,12 +110,11 @@
"Remap hl-line face to the alternate one, in the current buffer" "Remap hl-line face to the alternate one, in the current buffer"
(face-remap-add-relative 'hl-line 'alt-hl-line-face)) (face-remap-add-relative 'hl-line 'alt-hl-line-face))
:hook :hook
(after-init . my/load-theme)
(cider-inspector-mode . use-alt-font-lock-keyword-face) (cider-inspector-mode . use-alt-font-lock-keyword-face)
(magit-mode . use-alt-hl-line-face)) (magit-mode . use-alt-hl-line-face))
(use-package hl-todo (use-package hl-todo
:defer 5
:after modus-themes
:bind :bind
(:map hl-todo-mode-map (:map hl-todo-mode-map
("C-c c t p" . hl-todo-previous) ("C-c c t p" . hl-todo-previous)
@ -110,19 +122,9 @@
("C-c c t o" . hl-todo-occur) ("C-c c t o" . hl-todo-occur)
("C-c c t r" . hl-todo-rgrep) ("C-c c t r" . hl-todo-rgrep)
("C-c c t i" . hl-todo-insert)) ("C-c c t i" . hl-todo-insert))
:custom ;; Use emacs-startup-hook so that it runs after my/load-theme is called in after-init-hook
(hl-todo-keyword-faces ;; hl-todo-keyword-faces is customised in my/load-theme
'(("TODO" . "red3") :hook (emacs-startup . global-hl-todo-mode))
("FIXME" . "red3")
("DEBUG" . "#A020F0")
("GOTCHA" . "#FF4500")
("HACK" . "#FF4500")
("STUB" . "#1E90FF")
("FAIL" . "red3")
("NOTE" . "DarkOrange2")
("DEPRECATED" . "yellow")))
:config
(global-hl-todo-mode 1))
(use-package whitespace (use-package whitespace
:diminish :diminish