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 @@
;;; emacs/dired/config.el
;;; tools/dired/config.el -*- lexical-binding: t; -*-
(setq ;; Always copy/delete recursively
dired-recursive-copies 'always
@ -59,7 +59,7 @@
(add-hook 'dired-initial-position-hook #'dired-k)
(add-hook 'dired-after-readin-hook #'dired-k-no-revert))
;; Striped dired buffers
(def-package! stripe-buffer
:commands stripe-buffer-mode
:init (add-hook 'dired-mode-hook #'stripe-buffer-mode))

View file

@ -1,4 +1,4 @@
;;; tools/electric-indent/config.el
;;; tools/electric-indent/config.el -*- lexical-binding: t; -*-
;; Smarter, keyword-based electric-indent
@ -10,13 +10,13 @@
(setq electric-indent-chars '(?\n ?\^?))
(push (lambda (c)
(when (and (eolp) doom-electric-indent-words)
(save-excursion
(backward-word)
(looking-at-p
(concat "\\<" (regexp-opt doom-electric-indent-words))))))
electric-indent-functions)
(defun +electric-indent|char (_c)
(when (and (eolp) doom-electric-indent-words)
(save-excursion
(backward-word)
(looking-at-p
(concat "\\<" (regexp-opt doom-electric-indent-words))))))
(cl-pushnew #'+electric-indent|char electric-indent-functions :test #'eq)
(def-setting! :electric (modes &rest plist)
"Declare :words (list of strings) or :chars (lists of chars) in MODES that

View file

@ -1,4 +1,4 @@
;;; emacs/eshell/autoload/eshell.el
;;; tools/eshell/autoload/eshell.el -*- lexical-binding: t; -*-
(require 'eshell)
@ -35,7 +35,7 @@ module to be loaded."
(+eshell/run))
(doom/workspace-display))
(defun +eshell--outside-prompt-p (&optional offset)
(defun +eshell--outside-prompt-p ()
(< (point) eshell-last-output-end))
(defun +eshell--current-git-branch ()

View file

@ -1,7 +1,8 @@
;;; emacs/eshell/autoload/evil.el
;;; tools/eshell/autoload/evil.el -*- lexical-binding: t; -*-
;;;###autoload (autoload '+eshell:run "emacs/eshell/autoload/evil" nil t)
(evil-define-command +eshell:run (command bang)
(evil-define-command +eshell:run (_command bang)
;; TODO Add COMMAND support
(interactive "<fsh><!>")
(if bang
(+eshell/run)

View file

@ -1,4 +1,4 @@
;;; emacs/eshell/config.el
;;; tools/eshell/config.el -*- lexical-binding: t; -*-
;; This is highly experimental. I don't use eshell often, so this may need work.

View file

@ -1,10 +1,10 @@
;;; tools/gist/autoload/evil.el
;;; tools/gist/autoload/evil.el -*- lexical-binding: t; -*-
;;;###autoload (autoload '+gist:send "tools/gist/autoload/evil" nil t)
(evil-define-operator +gist:send (beg end search bang)
(evil-define-operator +gist:send (bang)
"Create a private gist from the buffer. If BANG then make it public."
:type inclusive :repeat nil
(interactive "<r><!>")
(interactive "<!>")
(if bang
(gist-region-or-buffer)
(gist-region-or-buffer-private)))

View file

@ -1,4 +1,4 @@
;;; tools/gist/autoload/gist.el
;;; tools/gist/autoload/gist.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +gist/open-current ()

View file

@ -1,4 +1,4 @@
;;; tools/gist/config.el
;;; tools/gist/config.el -*- lexical-binding: t; -*-
;; NOTE On occasion, the cache gets corrupted, causing wrong-type-argument
;; errors. If that happens, try `+gist/kill-cache'. You may have to restart
@ -12,9 +12,8 @@
;; evil-ify gist listing
(set! :evil-state 'gist-list-mode 'normal)
(when (bound-and-true-p shackle-mode)
(defun +gist*list-render (orig-fn &rest args)
(funcall orig-fn (car args) t)
(unless (cadr args)
(doom-popup-buffer (current-buffer))))
(advice-add #'gist-list-render :around #'+gist*list-render)))
(defun +gist*list-render (orig-fn &rest args)
(funcall orig-fn (car args) t)
(unless (cadr args)
(doom-popup-buffer (current-buffer))))
(advice-add #'gist-list-render :around #'+gist*list-render))

View file

@ -1,4 +1,4 @@
;;; tools/macos/autoload.el
;;; tools/macos/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +macos-open-with (&optional app-name path)

View file

@ -1,21 +1,21 @@
;;; tools/neotree/autoload.el
;;; tools/neotree/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +neotree/toggle ()
"Toggle the neotree window."
(interactive)
(let ((in-neotree (and (neo-global--window-exists-p)
(window-live-p neo-global--buffer)
(eq (current-buffer) neo-global--buffer)))
(path buffer-file-name))
(if in-neotree
(neotree-hide)
(let ((project-root (doom-project-root)))
(unless (and (neo-global--window-exists-p)
(let ((path buffer-file-name)
(project-root (doom-project-root)))
(require 'neotree)
(cond ((and (neo-global--window-exists-p)
(window-live-p neo-global--buffer)
(eq (current-buffer) neo-global--buffer))
(neotree-hide))
((not (and (neo-global--window-exists-p)
(equal (file-truename (neo-global--with-buffer neo-buffer--start-node))
(file-truename project-root)))
(neotree-dir project-root))
(neotree-find path project-root)))))
(file-truename project-root))))
(neotree-dir project-root))
(t (neotree-find path project-root)))))
;;;###autoload
(defun +neotree/collapse-or-up ()
@ -44,11 +44,11 @@
"Expand or open a neotree node."
(interactive)
(when-let (node (neo-buffer--get-filename-current-line))
(if (file-directory-p node)
(progn
(neo-buffer--set-expand node t)
(neo-buffer--refresh t)
(when neo-auto-indent-point
(forward-line)
(neo-point-auto-indent)))
(call-interactively 'neotree-enter))))
(cond ((file-directory-p node)
(neo-buffer--set-expand node t)
(neo-buffer--refresh t)
(when neo-auto-indent-point
(forward-line)
(neo-point-auto-indent)))
(t
(call-interactively #'neotree-enter)))))

View file

@ -1,4 +1,4 @@
;;; tools/neotree/config.el
;;; tools/neotree/config.el -*- lexical-binding: t; -*-
(def-package! neotree
:commands (neotree-show

View file

@ -1,4 +1,4 @@
;;; tools/rotate-text/config.el
;;; tools/rotate-text/config.el -*- lexical-binding: t; -*-
(def-package! rotate-text
:commands (rotate-text rotate-text-backward)

View file

@ -1,4 +1,4 @@
;;; tools/term/autoload.el
;;; tools/term/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +term (&optional project-root)
@ -6,7 +6,7 @@
non-nil, cd into the current project's root."
(interactive "P")
(let ((default-directory (if project-root (doom-project-root) default-directory)))
(call-interactively 'multi-term)))
(call-interactively #'multi-term)))
;;;###autoload
(defun +term/popup (&optional project-root)
@ -14,10 +14,9 @@ non-nil, cd into the current project's root."
current project's root."
(interactive "P")
(require 'multi-term)
(let* ((default-directory (if project-root (doom-project-root) default-directory))
(buffer (multi-term-get-buffer current-prefix-arg))
(window (doom-popup-buffer buffer)))
(select-window window)
(let ((default-directory (if project-root (doom-project-root) default-directory))
(buffer (multi-term-get-buffer current-prefix-arg)))
(select-window (doom-popup-buffer buffer))
(setq multi-term-buffer-list (nconc multi-term-buffer-list (list buffer)))
(multi-term-internal)))

View file

@ -1,4 +1,4 @@
;;; tools/term/config.el
;;; tools/term/config.el -*- lexical-binding: t; -*-
(def-package! multi-term
:commands (multi-term multi-term-next multi-term-prev)

View file

@ -1,4 +1,4 @@
;;; tools/tmux/autoload/evil.el
;;; tools/tmux/autoload/evil.el -*- lexical-binding: t; -*-
;;;###autoload (autoload '+tmux:run "tools/tmux/autoload/evil" nil t)
(evil-define-command +tmux:run (bang &optional command)

View file

@ -1,4 +1,4 @@
;;; tools/tmux/autoload/tmux.el
;;; tools/tmux/autoload/tmux.el -*- lexical-binding: t; -*-
;; This library offers:
;; + A way of communicating with a tmux instance
@ -98,48 +98,46 @@ but do not execute them."
(defun +tmux-list-sessions ()
(let ((lines (+tmux "list-sessions -F '#{session_id};#{session_name};#{session_attached}'")))
(if lines
(mapcar (lambda (it)
(let ((sess (split-string it ";")))
(list (nth 0 sess) :name (nth 1 sess) :attached (equal (nth 2 sess) "1"))))
(split-string lines "\n" t))
(cl-loop for line in (split-string lines "\n" t)
collect
(let ((sess (split-string line ";")))
(list (nth 0 sess)
:name (nth 1 sess)
:attached (equal (nth 2 sess) "1"))))
(error "There are no sessions"))))
;;;###autoload
(defun +tmux-list-windows (&optional session)
(let* ((flags
(if session
(concat "-t " (car session))
"-a"))
(lines
(+tmux (format "list-windows %s -F '#{window_id};#{session_id};#{window_active};#{window_name};#{window_activity_flag}'"
flags))))
(if lines
(mapcar (lambda (it)
(let ((window (string-split it ";")))
(list (nth 0 window)
:session-id (nth 1 window)
:name (nth 3 window)
:active (equal (nth 2 window) "1")
:activity (equal (nth 4 window) "1"))))
(string-split lines "\n" t))
(error "There are no windows"))))
(if-let (lines
(+tmux (format "list-windows %s -F '#{window_id};#{session_id};#{window_active};#{window_name};#{window_activity_flag}'"
(if session
(concat "-t " (car session))
"-a"))))
(cl-loop for line in (string-split lines "\n" t)
collect (let ((window (string-split line ";")))
(list (nth 0 window)
:session-id (nth 1 window)
:name (nth 3 window)
:active (equal (nth 2 window) "1")
:activity (equal (nth 4 window) "1"))))
(error "There are no windows")))
;;;###autoload
(defun +tmux-list-panes (&optional sess-or-win)
(let* ((flags (if sess-or-win
(concat (if (string-prefix-p "$" (car sess-or-win)) "-s ") "-t " (car sess-or-win))
"-a"))
(lines (+tmux (format "list-panes %s -F '#{pane_id};#{window_id};#{session_id};#{pane_active};#{pane_title};#{pane_current_path}'"
flags))))
(if lines
(mapcar (lambda (it)
(let ((pane (split-string it ";")))
(list (nth 0 pane)
:window-id (nth 1 pane)
:session-id (nth 2 pane)
:name (nth 4 pane)
:active (equal (nth 3 pane) "1")
:pwd (nth 5 pane))))
(string-split lines "\n" t))
(error "There are no panes"))))
(if-let (lines
(+tmux (format "list-panes %s -F '#{pane_id};#{window_id};#{session_id};#{pane_active};#{pane_title};#{pane_current_path}'"
(if sess-or-win
(concat (if (string-prefix-p "$" (car sess-or-win)) "-s ")
"-t "
(car sess-or-win))
"-a"))))
(cl-loop for line in (string-split lines "\n" t)
collect (let ((pane (split-string line ";")))
(list (nth 0 pane)
:window-id (nth 1 pane)
:session-id (nth 2 pane)
:name (nth 4 pane)
:active (equal (nth 3 pane) "1")
:pwd (nth 5 pane))))
(error "There are no panes")))

View file

@ -1,4 +1,4 @@
;;; tools/upload/autoload.el
;;; tools/upload/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +upload/local (&optional force-p)

View file

@ -1,4 +1,4 @@
;;; tools/upload/config.el
;;; tools/upload/config.el -*- lexical-binding: t; -*-
;; Uses `ssh-deploy' to map a local folder to a remote one. Use
;; `ssh-deploy-root-remote' and `ssh-deploy-root-local' to set up this mapping.
@ -21,20 +21,22 @@
ssh-deploy-remote-changes-handler)
:init
;; Maybe auto-upload on save
(add-hook! 'after-save-hook
(defun +upload|init-after-save ()
(when (and (bound-and-true-p ssh-deploy-root-remote)
ssh-deploy-on-explicit-save)
(ssh-deploy-upload-handler)))
(add-hook 'after-save-hook #'+upload|init-after-save)
;; Enable ssh-deploy if variables are set, and check for changes on open file
;; (if possible)
(add-hook! 'find-file-hook
(defun +upload|init-find-file ()
(when (bound-and-true-p ssh-deploy-root-remote)
(require 'ssh-deploy)
(unless ssh-deploy-root-local
(setq ssh-deploy-root-local (doom-project-root)))
(when ssh-deploy-automatically-detect-remote-changes
(ssh-deploy-remote-changes-handler))))
(add-hook 'find-file-hook #'+upload|init-find-file)
:config
(setq ssh-deploy-revision-folder (concat doom-cache-dir "ssh-revisions/")