Silence 'cannot load' false positive errors when byte-compiling

This commit is contained in:
Henrik Lissner 2017-12-10 14:50:43 -05:00
parent 76a4ae459d
commit ae25e319b0
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 67 additions and 64 deletions

View file

@ -328,13 +328,18 @@ MODULES is an malformed plist of modules to load."
(message "Doom modules initialized")))) (message "Doom modules initialized"))))
(defmacro def-package! (name &rest plist) (defmacro def-package! (name &rest plist)
"A thin wrapper around `use-package'. "A thin wrapper around `use-package'."
;; Ignore package if NAME is in `doom-disabled-packages'
Ignores the package if its NAME is present in `doom-disabled-packages'."
(when (and (memq name doom-disabled-packages) (when (and (memq name doom-disabled-packages)
(not (memq :disabled plist))) (not (memq :disabled plist)))
(setq plist (append (list :disabled t) plist))) (setq plist (append (list :disabled t) plist)))
`(use-package ,name ,@plist)) ;; If byte-compiling, ignore this package if it doesn't meet the condition.
;; This avoids false-positive load errors.
(unless (and (bound-and-true-p byte-compile-current-file)
(or (and (plist-member plist :if) (not (eval (plist-get plist :if))))
(and (plist-member plist :when) (not (eval (plist-get plist :when))))
(and (plist-member plist :unless) (eval (plist-get plist :unless)))))
`(use-package ,name ,@plist)))
(defmacro def-package-hook! (package when &rest body) (defmacro def-package-hook! (package when &rest body)
"Reconfigures a package's `def-package!' block. "Reconfigures a package's `def-package!' block.

View file

@ -342,78 +342,76 @@ See `doom-line-numbers-style' to control the style of line numbers to display."
(add-hook! (prog-mode text-mode conf-mode) #'doom|enable-line-numbers) (add-hook! (prog-mode text-mode conf-mode) #'doom|enable-line-numbers)
;; Emacs 26+ has native line number support. ;; Emacs 26+ has native line number support.
(unless (boundp 'display-line-numbers) ;; Line number column. A faster (or equivalent, in the worst case) line number
;; Line number column. A faster (or equivalent, in the worst case) line number ;; plugin than `linum-mode'.
;; plugin than `linum-mode'. (def-package! nlinum
(def-package! nlinum :unless (boundp 'display-line-numbers)
:commands nlinum-mode :commands nlinum-mode
:init :init
(defvar doom-line-number-lpad 4 (defvar doom-line-number-lpad 4
"How much padding to place before line numbers.") "How much padding to place before line numbers.")
(defvar doom-line-number-rpad 1 (defvar doom-line-number-rpad 1
"How much padding to place after line numbers.") "How much padding to place after line numbers.")
(defvar doom-line-number-pad-char 32 (defvar doom-line-number-pad-char 32
"Character to use for padding line numbers. "Character to use for padding line numbers.
By default, this is a space character. If you use `whitespace-mode' with By default, this is a space character. If you use `whitespace-mode' with
`space-mark', the whitespace in line numbers will be affected (this can look `space-mark', the whitespace in line numbers will be affected (this can look
ugly). In this case, you can change this to ?\u2002, which is a unicode ugly). In this case, you can change this to ?\u2002, which is a unicode
character that looks like a space that `whitespace-mode' won't affect.") character that looks like a space that `whitespace-mode' won't affect.")
:config
(setq nlinum-highlight-current-line t)
:config ;; Fix lingering hl-line overlays (caused by nlinum)
(setq nlinum-highlight-current-line t) (add-hook! 'hl-line-mode-hook
(remove-overlays (point-min) (point-max) 'face 'hl-line))
;; Fix lingering hl-line overlays (caused by nlinum) (defun doom-nlinum-format-fn (line _width)
(add-hook! 'hl-line-mode-hook "A more customizable `nlinum-format-function'. See `doom-line-number-lpad',
(remove-overlays (point-min) (point-max) 'face 'hl-line))
(defun doom-nlinum-format-fn (line _width)
"A more customizable `nlinum-format-function'. See `doom-line-number-lpad',
`doom-line-number-rpad' and `doom-line-number-pad-char'. Allows a fix for `doom-line-number-rpad' and `doom-line-number-pad-char'. Allows a fix for
`whitespace-mode' space-marks appearing inside the line number." `whitespace-mode' space-marks appearing inside the line number."
(let ((str (number-to-string line))) (let ((str (number-to-string line)))
(setq str (concat (make-string (max 0 (- doom-line-number-lpad (length str))) (setq str (concat (make-string (max 0 (- doom-line-number-lpad (length str)))
doom-line-number-pad-char) doom-line-number-pad-char)
str str
(make-string doom-line-number-rpad doom-line-number-pad-char))) (make-string doom-line-number-rpad doom-line-number-pad-char)))
(put-text-property 0 (length str) 'face (put-text-property 0 (length str) 'face
(if (and nlinum-highlight-current-line (if (and nlinum-highlight-current-line
(= line nlinum--current-line)) (= line nlinum--current-line))
'nlinum-current-line 'nlinum-current-line
'linum) 'linum)
str) str)
str)) str))
(setq nlinum-format-function #'doom-nlinum-format-fn) (setq nlinum-format-function #'doom-nlinum-format-fn)
(defun doom|init-nlinum-width () (defun doom|init-nlinum-width ()
"Calculate line number column width beforehand (optimization)." "Calculate line number column width beforehand (optimization)."
(setq nlinum--width (setq nlinum--width
(length (save-excursion (goto-char (point-max)) (length (save-excursion (goto-char (point-max))
(format-mode-line "%l"))))) (format-mode-line "%l")))))
(add-hook 'nlinum-mode-hook #'doom|init-nlinum-width)) (add-hook 'nlinum-mode-hook #'doom|init-nlinum-width))
;; Fixes disappearing line numbers in nlinum and other quirks ;; Fixes disappearing line numbers in nlinum and other quirks
(def-package! nlinum-hl (def-package! nlinum-hl
:after nlinum :unless (boundp 'display-line-numbers)
:config :after nlinum
;; With `markdown-fontify-code-blocks-natively' enabled in `markdown-mode', :config
;; line numbers tend to vanish next to code blocks. ;; With `markdown-fontify-code-blocks-natively' enabled in `markdown-mode',
(advice-add #'markdown-fontify-code-block-natively ;; line numbers tend to vanish next to code blocks.
:after #'nlinum-hl-do-markdown-fontify-region) (advice-add #'markdown-fontify-code-block-natively
:after #'nlinum-hl-do-markdown-fontify-region)
;; When using `web-mode's code-folding an entire range of line numbers will
;; vanish in the affected area.
(advice-add #'web-mode-fold-or-unfold :after #'nlinum-hl-do-generic-flush)
;; Changing fonts can leave nlinum line numbers in their original size; this
;; forces them to resize.
(advice-add #'set-frame-font :after #'nlinum-hl-flush-all-windows))
;; When using `web-mode's code-folding an entire range of line numbers will (def-package! nlinum-relative
;; vanish in the affected area. :unless (boundp 'display-line-numbers)
(advice-add #'web-mode-fold-or-unfold :after #'nlinum-hl-do-generic-flush) :commands nlinum-relative-mode
:config
;; Changing fonts can leave nlinum line numbers in their original size; this (after! evil (nlinum-relative-setup-evil)))
;; forces them to resize.
(advice-add #'set-frame-font :after #'nlinum-hl-flush-all-windows))
(def-package! nlinum-relative
:commands nlinum-relative-mode
:config
(after! evil
(nlinum-relative-setup-evil))))
;; ;;