mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-17 13:33:36 -05:00
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:
@@ -1,4 +1,4 @@
|
||||
;;; editor.el
|
||||
;;; core/autoload/editor.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/sudo-find-file (file)
|
||||
@@ -65,7 +65,7 @@ If already there, do nothing."
|
||||
(looking-at-p match-str))))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/dumb-indent (&optional smart)
|
||||
(defun doom/dumb-indent ()
|
||||
"Inserts a tab character (or spaces x tab-width)."
|
||||
(interactive)
|
||||
(if indent-tabs-mode
|
||||
@@ -142,11 +142,13 @@ possible, or just one char if that's not possible."
|
||||
"Checks if point is surrounded by {} [] () delimiters and adds a
|
||||
space on either side of the point if so."
|
||||
(interactive)
|
||||
(let ((command (or (command-remapping #'self-insert-command) #'self-insert-command)))
|
||||
(if (doom--surrounded-p)
|
||||
(progn (call-interactively command)
|
||||
(save-excursion (call-interactively command)))
|
||||
(call-interactively command))))
|
||||
(let ((command (or (command-remapping #'self-insert-command)
|
||||
#'self-insert-command)))
|
||||
(cond ((doom--surrounded-p)
|
||||
(call-interactively command)
|
||||
(save-excursion (call-interactively command)))
|
||||
(t
|
||||
(call-interactively command)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/deflate-space-maybe ()
|
||||
@@ -155,22 +157,24 @@ spaces on either side of the point if so. Resorts to
|
||||
`doom/backward-delete-whitespace-to-column' otherwise."
|
||||
(interactive)
|
||||
(save-match-data
|
||||
(if (doom--surrounded-p)
|
||||
(let ((whitespace-match (match-string 1)))
|
||||
(cond ((not whitespace-match)
|
||||
(call-interactively #'delete-backward-char))
|
||||
((string-match "\n" whitespace-match)
|
||||
(funcall (if (featurep 'evil) #'evil-delete #'delete-region)
|
||||
(point-at-bol) (point))
|
||||
(call-interactively #'delete-backward-char)
|
||||
(save-excursion (call-interactively #'delete-char)))
|
||||
(t (just-one-space 0))))
|
||||
(doom/backward-delete-whitespace-to-column))))
|
||||
(cond ((doom--surrounded-p)
|
||||
(let ((whitespace-match (match-string 1)))
|
||||
(cond ((not whitespace-match)
|
||||
(call-interactively #'delete-backward-char))
|
||||
((string-match "\n" whitespace-match)
|
||||
(funcall (if (featurep 'evil) #'evil-delete #'delete-region)
|
||||
(point-at-bol) (point))
|
||||
(call-interactively #'delete-backward-char)
|
||||
(save-excursion (call-interactively #'delete-char)))
|
||||
(t (just-one-space 0)))))
|
||||
(t
|
||||
(doom/backward-delete-whitespace-to-column)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/newline-and-indent ()
|
||||
"Inserts a newline and possibly indents it. Also cotinues comments if executed
|
||||
from a commented line."
|
||||
"Inserts a newline and possibly indents it. Also continues comments if
|
||||
executed from a commented line; handling special cases for certain languages
|
||||
with weak native support."
|
||||
(interactive)
|
||||
(cond ((sp-point-in-string)
|
||||
(newline))
|
||||
|
Reference in New Issue
Block a user