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 @@
|
|||
;;; feature/workspaces/autoload/evil.el
|
||||
;;; feature/workspaces/autoload/evil.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload (autoload '+workspace:save-session "feature/workspaces/autoload/evil" nil t)
|
||||
(evil-define-command +workspace:save-session (&optional bang name)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
;;; feature/workspaces/autoload/workspaces.el
|
||||
;;; feature/workspaces/autoload/workspaces.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defvar +workspace-workspace-file "_workspaces"
|
||||
"The file basename in which to store single workspace perspectives.")
|
||||
|
@ -139,12 +139,11 @@ perspective or its hash table."
|
|||
(persp-frame-switch name))
|
||||
|
||||
(defun +workspace--generate-id ()
|
||||
(let ((numbers (mapcar (lambda (it) (string-to-number (substring it 1)))
|
||||
(cl-remove-if-not (lambda (it) (string-match-p "^#[0-9]+$" it))
|
||||
(+workspace-list)))))
|
||||
(if numbers
|
||||
(1+ (car (sort numbers (lambda (it other) (> it other)))))
|
||||
1)))
|
||||
(or (cl-loop for name in (+workspace-list)
|
||||
when (string-match-p "^#[0-9]+$" name)
|
||||
maximize (string-to-number (substring name 1)) into max
|
||||
finally return (if max (1+ max)))
|
||||
1))
|
||||
|
||||
(defun +workspace-protected-p (name)
|
||||
(or (equal name persp-nil-name)
|
||||
|
@ -373,17 +372,16 @@ the workspace and move to the next."
|
|||
|
||||
(defun +workspace--tabline (&optional names)
|
||||
(let ((names (or names (+workspace-list)))
|
||||
(current-name (+workspace-current-name))
|
||||
(i 0))
|
||||
(current-name (+workspace-current-name)))
|
||||
(mapconcat
|
||||
#'identity
|
||||
(mapcar (lambda (it)
|
||||
(cl-incf i)
|
||||
(propertize (format " [%d] %s " i it)
|
||||
'face (if (equal current-name it)
|
||||
'+workspace-tab-selected-face
|
||||
'+workspace-tab-face)))
|
||||
names)
|
||||
(cl-loop for name in names
|
||||
for i to (length names)
|
||||
collect
|
||||
(propertize (format " [%d] %s " i name)
|
||||
'face (if (equal current-name name)
|
||||
'+workspace-tab-selected-face
|
||||
'+workspace-tab-face)))
|
||||
" ")))
|
||||
|
||||
(defun +workspace--message-body (message &optional type)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
;;; feature/workspaces/config.el
|
||||
;;; feature/workspaces/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
;; `persp-mode' gives me workspaces, a workspace-restricted `buffer-list', and
|
||||
;; file-based session persistence. I had used workgroups2 before this, but
|
||||
|
@ -24,7 +24,8 @@ renamed.")
|
|||
;; Plugins
|
||||
;;
|
||||
|
||||
(def-package! persp-mode :demand t
|
||||
(def-package! persp-mode
|
||||
:demand t
|
||||
:config
|
||||
(setq persp-autokill-buffer-on-remove 'kill-weak
|
||||
persp-nil-name "nil"
|
||||
|
@ -44,35 +45,34 @@ renamed.")
|
|||
|
||||
(defun +workspaces|init (&rest _)
|
||||
(unless persp-mode
|
||||
(persp-mode +1))
|
||||
;; The default perspective persp-mode makes (defined by `persp-nil-name') is
|
||||
;; special and doesn't actually represent a real persp object, so buffers
|
||||
;; can't really be assigned to it, among other quirks. We create a *real*
|
||||
;; main workspace to fill this role.
|
||||
(persp-add-new +workspaces-main)
|
||||
;; Switch to it if we aren't auto-loading the last session
|
||||
(when (or (= persp-auto-resume-time -1)
|
||||
(equal (safe-persp-name (get-current-persp)) persp-nil-name))
|
||||
(persp-frame-switch +workspaces-main)))
|
||||
(persp-mode +1)
|
||||
;; The default perspective persp-mode makes (defined by `persp-nil-name')
|
||||
;; is special and doesn't actually represent a real persp object, so
|
||||
;; buffers can't really be assigned to it, among other quirks. We create a
|
||||
;; *real* main workspace to fill this role.
|
||||
(persp-add-new +workspaces-main)
|
||||
;; Switch to it if we aren't auto-loading the last session
|
||||
(when (or (= persp-auto-resume-time -1)
|
||||
(equal (safe-persp-name (get-current-persp)) persp-nil-name))
|
||||
(persp-frame-switch +workspaces-main))))
|
||||
|
||||
(add-hook! 'after-init-hook
|
||||
(if (display-graphic-p)
|
||||
(+workspaces|init)
|
||||
(add-hook 'after-make-frame-functions #'+workspaces|init)))
|
||||
(add-hook 'emacs-startup-hook #'+workspaces|init)
|
||||
(add-hook 'after-make-frame-functions #'+workspaces|init)
|
||||
|
||||
(define-key persp-mode-map [remap delete-window] #'+workspace/close-window-or-workspace)
|
||||
|
||||
;; Spawn a perspective for each new frame
|
||||
(setq persp-init-new-frame-behaviour-override nil
|
||||
persp-interactive-init-frame-behaviour-override
|
||||
(lambda (frame &optional new-frame-p)
|
||||
(lambda (frame &optional _new-frame-p)
|
||||
(select-frame frame)
|
||||
(+workspace/new)
|
||||
(set-frame-parameter frame 'assoc-persp (+workspace-current-name))))
|
||||
|
||||
(defun +workspaces*delete-frame-and-persp (frame)
|
||||
"Delete workspace associated with current frame IF it has no real buffers."
|
||||
(when (and (string= (or (frame-parameter frame 'assoc-persp) "") (+workspace-current-name))
|
||||
(when (and (string= (or (frame-parameter frame 'assoc-persp) "")
|
||||
(+workspace-current-name))
|
||||
(not (delq (doom-fallback-buffer) (doom-real-buffers-list))))
|
||||
(+workspace/delete persp-name)))
|
||||
(add-hook 'delete-frame-functions #'+workspaces*delete-frame-and-persp)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue