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:
Henrik Lissner 2017-06-08 11:47:56 +02:00
parent 64a142b3fc
commit c7254e7bdc
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
154 changed files with 1101 additions and 1118 deletions

View file

@ -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)

View file

@ -1,4 +1,4 @@
;;; ui/doom-modeline/config.el
;;; ui/doom-modeline/config.el -*- lexical-binding: t; -*-
(eval-when-compile (require 'subr-x))
@ -90,6 +90,8 @@
(defvar evil-state nil)
(defvar evil-visual-selection nil)
(defvar iedit-mode nil)
(defvar all-the-icons-scale-factor)
(defvar all-the-icons-default-adjust)
;;
@ -196,7 +198,6 @@ active."
(propertize
" " 'display
(let ((data (make-list height (make-list width 1)))
(i 0)
(color (or color "None")))
(create-image
(concat
@ -205,30 +206,26 @@ active."
(length data)
color
color)
(let ((len (length data))
(idx 0))
(apply #'concat
(mapcar #'(lambda (dl)
(setq idx (+ idx 1))
(concat
"\""
(concat
(mapcar #'(lambda (d)
(if (eq d 0)
(string-to-char " ")
(string-to-char ".")))
dl))
(if (eq idx len) "\"};" "\",\n")))
data))))
(apply #'concat
(cl-loop with idx = 0
with len = (length data)
for dl in data
do (cl-incf idx)
collect
(concat "\""
(cl-loop for d in dl
if (= d 0) collect (string-to-char " ")
else collect (string-to-char "."))
(if (eq idx len) "\"};" "\",\n")))))
'xpm t :ascent 'center)))))
(defun +doom-modeline--buffer-file ()
(defsubst +doom-modeline--buffer-file ()
"Display the base of the current buffer's filename."
(if buffer-file-name
(file-name-nondirectory (or buffer-file-truename (file-truename buffer-file-name)))
"%b"))
(defun +doom-modeline--buffer-path ()
(defsubst +doom-modeline--buffer-path ()
"Displays the buffer's full path relative to the project root (includes the
project root). Excludes the file basename. See `doom-buffer-name' for that."
(when buffer-file-name
@ -373,7 +370,7 @@ directory, the file name, and its state (modified, read-only or non-existent)."
+doom-modeline-vspc))))
;;
(def-memoized! +doom-ml-icon (icon &optional text face)
(defun +doom-ml-icon (icon &optional text face)
"Displays an octicon ICON with FACE, followed by TEXT. Uses
`all-the-icons-octicon' to fetch the icon."
(concat

View file

@ -1,4 +1,4 @@
;;; ui/doom-quit/config.el
;;; ui/doom-quit/config.el -*- lexical-binding: t; -*-
;; A silly module that prompts you with messages when you try to quit, like DOOM
;; did. Some quotes are taken from Doom's quit-message list, others are random,

View file

@ -1,4 +1,4 @@
;;; ui/doom/autoload/doom.el
;;; ui/doom/autoload/doom.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +doom/reset-theme ()

View file

@ -1,4 +1,4 @@
;;; ui/doom/autoload/evil.el
;;; ui/doom/autoload/evil.el -*- lexical-binding: t; -*-
;;;###autoload (autoload '+doom:scratch-buffer "ui/doom/autoload/evil" nil t)
(evil-define-operator +doom:scratch-buffer (&optional beg end bang)
@ -6,7 +6,7 @@
region to it. If BANG, use current window instead of a popup."
:move-point nil :type inclusive
(interactive "<r><!>")
(let ((text (when (and (evil-visual-state-p) beg end)
(let ((text (when (and (not (evil-normal-state-p)) beg end)
(buffer-substring beg end)))
(mode major-mode)
(old-project (doom-project-root))

View file

@ -1,4 +1,4 @@
;;; ui/doom/config.el
;;; ui/doom/config.el -*- lexical-binding: t; -*-
(defvar +doom-theme 'doom-one
"The color theme to use.")
@ -38,10 +38,10 @@
(load-theme +doom-theme t)
;; blink mode-line on errors
(doom-themes-visual-bell-config)
(add-hook 'emacs-startup-hook #'doom-themes-visual-bell-config t)
;; Add file icons to doom-neotree
(doom-themes-neotree-config)
(add-hook 'emacs-startup-hook #'doom-themes-neotree-config t)
(setq doom-neotree-enable-variable-pitch t
doom-neotree-file-icons 'simple
doom-neotree-line-spacing 2)

View file

@ -1,4 +1,4 @@
;;; feature/ui/evil-goggles/autoload.el
;;; feature/ui/evil-goggles/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +evil-goggles/toggle ()

View file

@ -1,4 +1,4 @@
;;; ui/evil-goggles/config.el
;;; ui/evil-goggles/config.el -*- lexical-binding: t; -*-
(def-package! evil-goggles
:when (featurep! :feature evil)

View file

@ -1,9 +1,8 @@
;;; ui/hl-todo/packages.el
;;; ui/hl-todo/packages.el -*- lexical-binding: t; -*-
(def-package! hl-todo
:commands hl-todo-mode
:init
(add-hook 'prog-mode-hook #'hl-todo-mode)
:init (add-hook 'prog-mode-hook #'hl-todo-mode)
:config
(setq hl-todo-keyword-faces
`(("TODO" . ,(face-foreground 'warning))

View file

@ -0,0 +1,21 @@
;;; ui/nav-flash/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +doom*blink-cursor-maybe (orig-fn &rest args)
"Blink current line if the window has moved."
(let ((point (save-excursion (goto-char (window-start))
(point-marker))))
(apply orig-fn args)
(unless (equal point
(save-excursion (goto-char (window-start))
(point-marker)))
(+doom/blink-cursor))))
;;;###autoload
(defun +doom/blink-cursor (&rest _)
"Blink current line using `nav-flash'."
(interactive)
(unless (minibufferp)
(nav-flash-show)
;; only show in the current window
(overlay-put compilation-highlight-overlay 'window (selected-window))))

View file

@ -1,29 +1,10 @@
;;; ui/nav-flash/config.el
;;; ui/nav-flash/config.el -*- lexical-binding: t; -*-
(def-package! nav-flash
:commands nav-flash-show
:init
(defun +doom*blink-cursor-maybe (orig-fn &rest args)
"Blink current line if the window has moved."
(let ((point (save-excursion (goto-char (window-start))
(point-marker))))
(apply orig-fn args)
(unless (equal point
(save-excursion (goto-char (window-start))
(point-marker)))
(+doom/blink-cursor))))
(defun +doom/blink-cursor (&rest _)
"Blink current line using `nav-flash'."
(interactive)
(unless (minibufferp)
(nav-flash-show)
;; only show in the current window
(overlay-put compilation-highlight-overlay 'window (selected-window))))
;; NOTE In :feature jump `recenter' is hooked to a bunch of jumping commands,
;; which will trigger nav-flash.
(advice-add #'windmove-do-window-select :around #'+doom*blink-cursor-maybe)
(advice-add #'recenter :around #'+doom*blink-cursor-maybe)