General refactor for readability

+ Removes redundant/unhelpful comments
+ Renames functions, hooks and variables to be self-documenting
+ Use add-to-list to ensure idempotency (and is more performant)
This commit is contained in:
Henrik Lissner 2018-07-09 15:33:31 +02:00
parent 1b98422291
commit 4941e327f4
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
11 changed files with 89 additions and 95 deletions

View file

@ -592,8 +592,7 @@ modified."
(print! (green "✓ Clean up autoloads")))
;; Byte compile it to give the file a chance to reveal errors.
(doom--byte-compile-file doom-autoload-file)
(when (and noninteractive (not (daemonp)))
(doom--server-load doom-autoload-file))
(doom--server-load doom-autoload-file)
t)))
@ -668,8 +667,7 @@ This should be run whenever your `doom!' block or update your packages."
(doom--cleanup-package-autoloads)
(print! (green "✓ Removed load-path/auto-mode-alist entries"))))
(doom--byte-compile-file doom-package-autoload-file)
(when (and noninteractive (not (daemonp)))
(doom--server-load doom-package-autoload-file))
(doom--server-load doom-package-autoload-file)
t))

View file

@ -282,13 +282,14 @@ compilation. This will no-op on features that have been disabled by the user."
(save-silently t))
,@forms))))
(defmacro add-transient-hook! (hook &rest forms)
"Attaches transient forms to a HOOK.
(defmacro add-transient-hook! (hook-or-function &rest forms)
"Attaches a self-removing function to HOOK-OR-FUNCTION.
This means FORMS will be evaluated once when that function/hook is first
invoked, then never again.
FORMS are evaluated once when that function/hook is first invoked, then never
again.
HOOK can be a quoted hook or a sharp-quoted function (which will be advised)."
HOOK-OR-FUNCTION can be a quoted hook or a sharp-quoted function (which will be
advised)."
(declare (indent 1))
(let ((append (if (eq (car forms) :after) (pop forms)))
(fn (if (symbolp (car forms))
@ -298,14 +299,14 @@ HOOK can be a quoted hook or a sharp-quoted function (which will be advised)."
(fset ',fn
(lambda (&rest _)
,@forms
(cond ((functionp ,hook) (advice-remove ,hook #',fn))
((symbolp ,hook) (remove-hook ,hook #',fn)))
(cond ((functionp ,hook-or-function) (advice-remove ,hook-or-function #',fn))
((symbolp ,hook-or-function) (remove-hook ,hook-or-function #',fn)))
(unintern ',fn nil)))
(cond ((functionp ,hook)
(advice-add ,hook ,(if append :after :before) #',fn))
((symbolp ,hook)
(cond ((functionp ,hook-or-function)
(advice-add ,hook-or-function ,(if append :after :before) #',fn))
((symbolp ,hook-or-function)
(put ',fn 'permanent-local-hook t)
(add-hook ,hook #',fn ,append))))))
(add-hook ,hook-or-function #',fn ,append))))))
(defmacro add-hook! (&rest args)
"A convenience macro for `add-hook'. Takes, in order:

View file

@ -287,8 +287,7 @@ DEFAULT is non-nil, set the default mode-line for all buffers."
(1- (line-end-position)))
((or (eobp) (save-excursion (forward-line) (eobp)))
(line-end-position))
(t
(line-beginning-position 2)))))
((line-beginning-position 2)))))
(setq hl-line-range-function #'doom--line-range))
(after! evil

View file

@ -341,30 +341,31 @@ Module load order is determined by your `doom!' block. See `doom-modules-dirs'
for a list of all recognized module trees. Order defines precedence (from most
to least)."
(when (or force-p (not doom-init-p))
;; Set this to prevent infinite recursive calls to `doom-initialize'
(setq doom-init-p t)
(setq doom-init-p t) ; Prevent infinite recursion
;; `doom-autoload-file' tells Emacs where to load all its autoloaded
;; functions from. This includes everything in core/autoload/*.el and all
;; the autoload files in your enabled modules.
(when (or force-p (not (doom-initialize-autoloads doom-autoload-file)))
(doom-ensure-core-directories)
(doom-ensure-same-emacs-version-p)
;; Ensure packages are set up and initialized
(require 'core-packages)
(doom-ensure-packages-initialized force-p)
(doom-ensure-core-packages)
;; Regenerate `doom-autoload-file', which tells Doom where to find all its
;; module autoloaded functions.
(unless (or force-p noninteractive)
(user-error "Your doom autoloads are missing! Run `bin/doom refresh' to regenerate them")))
;; Loads `doom-package-autoload-file', which caches `load-path',
;; `auto-mode-alist', `Info-directory-list', `doom-disabled-packages' and
;; Loads `doom-package-autoload-file', which loads a concatenated package
;; autoloads file and caches `load-path', `auto-mode-alist',
;; `Info-directory-list', `doom-disabled-packages' and
;; `package-activated-list'. A big reduction in startup time.
(unless (or force-p
(doom-initialize-autoloads doom-package-autoload-file)
noninteractive)
(user-error "Your package autoloads are missing! Run `bin/doom refresh' to regenerate them")))
;; Initialize Doom core
(require 'core-os)
(unless noninteractive
(add-hook! 'emacs-startup-hook
@ -375,7 +376,8 @@ to least)."
(require 'core-keybinds)))
(defun doom-initialize-autoloads (file)
"Tries to load FILE (an autoloads file). Return t on success, nil otherwise."
"Tries to load FILE (an autoloads file). Return t on success, throws an error
in interactive sessions, nil otherwise (but logs a warning)."
(condition-case e
(load (file-name-sans-extension file) 'noerror 'nomessage)
((debug error)