Major optimization refactor, across the board
+ enable lexical-scope everywhere (lexical-binding = t): ~5-10% faster startup; ~5-20% general boost + reduce consing, function calls & garbage collection by preferring cl-loop & dolist over lambda closures (for mapc[ar], add-hook, and various cl-lib filter/map/reduce functions) -- where possible + prefer functions with dedicated opcodes, like assq (see byte-defop's in bytecomp.el for more) + prefer pcase & cond (faster) over cl-case + general refactor for code readability + ensure naming & style conventions are adhered to + appease byte-compiler by marking unused variables with underscore + defer minor mode activation to after-init, emacs-startup or window-setup hooks; a customization opportunity for users + ensures custom functionality won't interfere with startup.
This commit is contained in:
parent
64a142b3fc
commit
c7254e7bdc
154 changed files with 1101 additions and 1118 deletions
|
@ -1,4 +1,4 @@
|
|||
;;; ui/doom-dashboard/config.el
|
||||
;;; ui/doom-dashboard/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defvar +doom-dashboard-name " *doom*"
|
||||
"TODO")
|
||||
|
@ -6,12 +6,6 @@
|
|||
(defvar +doom-dashboard-modeline nil
|
||||
"TODO")
|
||||
|
||||
(defvar +doom-dashboard-old-modeline nil
|
||||
"TODO")
|
||||
|
||||
(defvar +doom-dashboard-edited-p nil
|
||||
"If non-nil, the scratch buffer has been edited.")
|
||||
|
||||
(defvar +doom-dashboard-inhibit-refresh nil
|
||||
"If non-nil, the doom buffer won't be refreshed.")
|
||||
|
||||
|
@ -25,7 +19,10 @@
|
|||
(defvar +doom-dashboard--width 0)
|
||||
(defvar +doom-dashboard--height 0)
|
||||
(defvar +doom-dashboard--old-fringe-indicator fringe-indicator-alist)
|
||||
(defvar +doom-dashboard--old-modeline nil)
|
||||
|
||||
|
||||
;;
|
||||
(after! evil
|
||||
(map! :map +doom-dashboard-mode-map
|
||||
"n" #'+doom-dashboard/next-button
|
||||
|
@ -48,9 +45,8 @@
|
|||
(goto-char (previous-button (point))))))
|
||||
|
||||
|
||||
(def-package! all-the-icons :when (display-graphic-p))
|
||||
|
||||
(unless (display-graphic-p)
|
||||
(if (display-graphic-p)
|
||||
(require 'all-the-icons)
|
||||
(defalias 'all-the-icons-octicon #'ignore)
|
||||
(defalias 'all-the-icons-faicon #'ignore)
|
||||
(defalias 'all-the-icons-fileicon #'ignore)
|
||||
|
@ -61,19 +57,20 @@
|
|||
;;
|
||||
(setq doom-fallback-buffer +doom-dashboard-name)
|
||||
|
||||
(defun +doom-dashboard|kill-buffer-query-fn ()
|
||||
(or (not (+doom-dashboard-p))
|
||||
(ignore (ignore-errors (+doom-dashboard-reload))
|
||||
(bury-buffer))))
|
||||
|
||||
(defun +doom-dashboard|init (&rest _)
|
||||
(add-hook 'after-make-frame-functions #'+doom-dashboard-deferred-reload)
|
||||
(add-hook 'window-configuration-change-hook #'+doom-dashboard-reload)
|
||||
(add-hook! 'kill-buffer-query-functions
|
||||
(or (not (+doom-dashboard-p))
|
||||
(ignore (ignore-errors (+doom-dashboard-force-reload))
|
||||
(bury-buffer))))
|
||||
(add-hook 'kill-buffer-query-functions #'+doom-dashboard|kill-buffer-query-fn)
|
||||
(+doom-dashboard-reload)
|
||||
(when (equal (buffer-name) "*scratch*")
|
||||
(switch-to-buffer (doom-fallback-buffer))))
|
||||
|
||||
(add-hook! '(after-make-frame-functions window-setup-hook)
|
||||
#'+doom-dashboard|init)
|
||||
(add-hook 'window-setup-hook #'+doom-dashboard|init)
|
||||
|
||||
;; Compatibility with `midnight-mode' and `clean-buffer-list'
|
||||
(after! midnight-mode
|
||||
|
@ -94,19 +91,6 @@
|
|||
(and (buffer-live-p buffer)
|
||||
(eq buffer (doom-fallback-buffer)))))
|
||||
|
||||
(defun +doom-dashboard-force-reload ()
|
||||
(setq +doom-dashboard-edited-p nil)
|
||||
(+doom-dashboard-reload))
|
||||
|
||||
(defun +doom-dashboard|clear-on-insert ()
|
||||
"Erase the buffer and prepare it to be used like a normal buffer."
|
||||
(unless +doom-dashboard-edited-p
|
||||
(erase-buffer)
|
||||
(setq +doom-dashboard-edited-p t
|
||||
mode-line-format +doom-dashboard-old-modeline
|
||||
fringe-indicator-alist +doom-dashboard--old-fringe-indicator)
|
||||
(remove-hook 'evil-insert-state-entry-hook #'doom|mode-erase-on-insert t)))
|
||||
|
||||
(defun +doom-dashboard-deferred-reload (&rest _)
|
||||
"Reload the dashboard after a brief pause. This is necessary for new frames,
|
||||
whose dimensions may not be fully initialized by the time this is run."
|
||||
|
@ -116,37 +100,33 @@ whose dimensions may not be fully initialized by the time this is run."
|
|||
"Update the DOOM scratch buffer (or create it, if it doesn't exist)."
|
||||
(when (and (not +doom-dashboard-inhibit-refresh)
|
||||
(not (minibuffer-window-active-p (minibuffer-window)))
|
||||
(get-buffer-window-list (doom-fallback-buffer) nil t)
|
||||
(or (not +doom-dashboard-edited-p) dir))
|
||||
(get-buffer-window-list (doom-fallback-buffer) nil t))
|
||||
(unless +doom-dashboard-modeline
|
||||
(setq +doom-dashboard-old-modeline mode-line-format)
|
||||
(setq +doom-dashboard--old-modeline mode-line-format)
|
||||
(setq +doom-dashboard-modeline
|
||||
(or (and (featurep! :ui doom-modeline)
|
||||
(doom-modeline 'project))
|
||||
mode-line-format)))
|
||||
(let ((old-pwd (or dir default-directory)))
|
||||
(let ((old-pwd (or dir default-directory))
|
||||
(inhibit-read-only t))
|
||||
(with-current-buffer (doom-fallback-buffer)
|
||||
(read-only-mode -1)
|
||||
(read-only-mode +1)
|
||||
(+doom-dashboard-mode)
|
||||
;; (add-hook 'evil-insert-state-entry-hook #'+doom-dashboard|clear-on-insert nil t)
|
||||
;; (add-hook 'after-change-major-mode-hook #'+doom-dashboard|clear-on-insert nil t)
|
||||
(setq +doom-dashboard-edited-p nil
|
||||
fringe-indicator-alist (mapcar (lambda (i) (cons (car i) nil))
|
||||
fringe-indicator-alist))
|
||||
(setq fringe-indicator-alist (cl-loop for (car . _cdr) in fringe-indicator-alist
|
||||
collect (cons car nil)))
|
||||
(erase-buffer)
|
||||
(let* ((+doom-dashboard--width (window-width (get-buffer-window (doom-fallback-buffer))))
|
||||
(+doom-dashboard--height (window-height (get-buffer-window (doom-fallback-buffer)))))
|
||||
(let* ((window (get-buffer-window (doom-fallback-buffer)))
|
||||
(+doom-dashboard--width (window-width window))
|
||||
(+doom-dashboard--height (window-height window)))
|
||||
(insert (make-string (max 0 (- (truncate (/ +doom-dashboard--height 2)) 16)) ?\n))
|
||||
(mapc (lambda (widget-name)
|
||||
(funcall (intern (format "doom-dashboard-widget--%s" widget-name)))
|
||||
(insert "\n"))
|
||||
+doom-dashboard-widgets))
|
||||
(dolist (widget-name +doom-dashboard-widgets)
|
||||
(funcall (intern (format "doom-dashboard-widget--%s" widget-name)))
|
||||
(insert "\n")))
|
||||
(setq default-directory old-pwd
|
||||
mode-line-format +doom-dashboard-modeline)
|
||||
(unless (button-at (point))
|
||||
(goto-char (point-min))
|
||||
(goto-char (next-button (point))))
|
||||
(read-only-mode +1))))
|
||||
(goto-char (next-button (point)))))))
|
||||
t)
|
||||
|
||||
(defun doom-dashboard-widget--banner ()
|
||||
|
@ -184,10 +164,11 @@ whose dimensions may not be fully initialized by the time this is run."
|
|||
'face 'font-lock-comment-face)
|
||||
"\n"))
|
||||
|
||||
(defvar all-the-icons-scale-factor)
|
||||
(defvar all-the-icons-default-adjust)
|
||||
(defun doom-dashboard-widget--shortmenu ()
|
||||
(let ((all-the-icons-scale-factor 1.3)
|
||||
(all-the-icons-default-adjust -0.05)
|
||||
(start (point))
|
||||
(last-session-p (and (and (featurep 'persp-mode) persp-mode)
|
||||
(file-exists-p (expand-file-name persp-auto-save-fname persp-save-dir)))))
|
||||
(mapc (lambda (btn)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue