From 2525822791c2d6df3d18b1c17b6ea5f8ba38f75d Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 15 May 2019 18:30:20 -0400 Subject: [PATCH] Move GC optimization to init.el And reformat core.el --- core/core.el | 37 ++++++++++++++----------------------- init.el | 16 +++++++++++++++- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/core/core.el b/core/core.el index a15a804a7..c6a07890a 100644 --- a/core/core.el +++ b/core/core.el @@ -216,6 +216,17 @@ Doom was setup, which may cause problems.") url-configuration-directory (concat doom-etc-dir "url/") gamegrid-user-score-file-directory (concat doom-etc-dir "games/")) +(defun doom*symbol-file (orig-fn symbol &optional type) + "If a `doom-file' symbol property exists on SYMBOL, use that instead of the +original value of `symbol-file'." + (or (if (symbolp symbol) (get symbol 'doom-file)) + (funcall orig-fn symbol type))) +(advice-add #'symbol-file :around #'doom*symbol-file) + + +;; +;;; Minor mode version of `auto-mode-alist' + (defvar doom-auto-minor-mode-alist '() "Alist mapping filename patterns to corresponding minor mode functions, like `auto-mode-alist'. All elements of this alist are checked, meaning you can @@ -239,12 +250,9 @@ enable multiple minor modes for the same regexp.") (setq alist (cdr alist)))))) (add-hook 'find-file-hook #'doom|enable-minor-mode-maybe) -(defun doom*symbol-file (orig-fn symbol &optional type) - "If a `doom-file' symbol property exists on SYMBOL, use that instead of the -original value of `symbol-file'." - (or (if (symbolp symbol) (get symbol 'doom-file)) - (funcall orig-fn symbol type))) -(advice-add #'symbol-file :around #'doom*symbol-file) + +;; +;;; MODE-local-vars-hook ;; File+dir local variables are initialized after the major mode and its hooks ;; have run. If you want hook functions to be aware of these customizations, add @@ -272,23 +280,6 @@ original value of `symbol-file'." (add-hook 'find-file-not-found-functions #'doom|create-non-existent-directories) -;; -;;; Garbage collector optimizations - -;; To speed up minibuffer commands (like helm and ivy), defer garbage collection -;; when the minibuffer is active. It may mean a pause when finished, but that's -;; acceptable instead of pauses during. -(defun doom|defer-garbage-collection () - (setq gc-cons-threshold doom-gc-cons-upper-limit)) -(defun doom|restore-garbage-collection () - (setq gc-cons-threshold doom-gc-cons-threshold)) -(add-hook 'minibuffer-setup-hook #'doom|defer-garbage-collection) -(add-hook 'minibuffer-exit-hook #'doom|restore-garbage-collection) - -;; GC all sneaky breeky like -(add-hook 'focus-out-hook 'garbage-collect) - - ;; ;;; Incremental lazy-loading diff --git a/init.el b/init.el index f67b43ae6..be1e83269 100644 --- a/init.el +++ b/init.el @@ -45,7 +45,21 @@ decrease this. If you experience stuttering, increase this.") ;; Do this on idle timer to defer a possible GC pause that could result; also ;; allows deferred packages to take advantage of these optimizations. (run-with-idle-timer - 3 nil (lambda () (setq-default gc-cons-threshold doom-gc-cons-threshold)))) + 3 nil + (lambda () + (setq-default gc-cons-threshold doom-gc-cons-threshold) + ;; To speed up minibuffer commands (like helm and ivy), we defer garbage + ;; collection while the minibuffer is active. + (defun doom|defer-garbage-collection () + (setq gc-cons-threshold doom-gc-cons-upper-limit)) + (defun doom|restore-garbage-collection () + ;; Defer it so that commands launched from the minibuffer can enjoy the + ;; benefits. + (run-at-time 1 nil (lambda () (setq gc-cons-threshold doom-gc-cons-threshold)))) + (add-hook 'minibuffer-setup-hook #'doom|defer-garbage-collection) + (add-hook 'minibuffer-exit-hook #'doom|restore-garbage-collection) + ;; GC all sneaky breeky like + (add-hook 'focus-out-hook #'garbage-collect)))) (if (ignore-errors (or after-init-time noninteractive))