From ae25e319b0a314695b782921c0830f5a85ef5ba5 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 10 Dec 2017 14:50:43 -0500 Subject: [PATCH] Silence 'cannot load' false positive errors when byte-compiling --- core/core-packages.el | 13 +++-- core/core-ui.el | 118 +++++++++++++++++++++--------------------- 2 files changed, 67 insertions(+), 64 deletions(-) diff --git a/core/core-packages.el b/core/core-packages.el index b4f31fdfa..3fd22c245 100644 --- a/core/core-packages.el +++ b/core/core-packages.el @@ -328,13 +328,18 @@ MODULES is an malformed plist of modules to load." (message "Doom modules initialized")))) (defmacro def-package! (name &rest plist) - "A thin wrapper around `use-package'. - -Ignores the package if its NAME is present in `doom-disabled-packages'." + "A thin wrapper around `use-package'." + ;; Ignore package if NAME is in `doom-disabled-packages' (when (and (memq name doom-disabled-packages) (not (memq :disabled 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) "Reconfigures a package's `def-package!' block. diff --git a/core/core-ui.el b/core/core-ui.el index 712f24c6e..014f3dab8 100644 --- a/core/core-ui.el +++ b/core/core-ui.el @@ -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) ;; 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 - ;; plugin than `linum-mode'. - (def-package! nlinum - :commands nlinum-mode - :init - (defvar doom-line-number-lpad 4 - "How much padding to place before line numbers.") - (defvar doom-line-number-rpad 1 - "How much padding to place after line numbers.") - (defvar doom-line-number-pad-char 32 - "Character to use for padding line numbers. +;; Line number column. A faster (or equivalent, in the worst case) line number +;; plugin than `linum-mode'. +(def-package! nlinum + :unless (boundp 'display-line-numbers) + :commands nlinum-mode + :init + (defvar doom-line-number-lpad 4 + "How much padding to place before line numbers.") + (defvar doom-line-number-rpad 1 + "How much padding to place after line numbers.") + (defvar doom-line-number-pad-char 32 + "Character to use for padding line numbers. 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 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.") + :config + (setq nlinum-highlight-current-line t) - :config - (setq nlinum-highlight-current-line t) + ;; Fix lingering hl-line overlays (caused by nlinum) + (add-hook! 'hl-line-mode-hook + (remove-overlays (point-min) (point-max) 'face 'hl-line)) - ;; Fix lingering hl-line overlays (caused by nlinum) - (add-hook! 'hl-line-mode-hook - (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', + (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 `whitespace-mode' space-marks appearing inside the line number." - (let ((str (number-to-string line))) - (setq str (concat (make-string (max 0 (- doom-line-number-lpad (length str))) - doom-line-number-pad-char) - str - (make-string doom-line-number-rpad doom-line-number-pad-char))) - (put-text-property 0 (length str) 'face - (if (and nlinum-highlight-current-line - (= line nlinum--current-line)) - 'nlinum-current-line - 'linum) - str) - str)) - (setq nlinum-format-function #'doom-nlinum-format-fn) + (let ((str (number-to-string line))) + (setq str (concat (make-string (max 0 (- doom-line-number-lpad (length str))) + doom-line-number-pad-char) + str + (make-string doom-line-number-rpad doom-line-number-pad-char))) + (put-text-property 0 (length str) 'face + (if (and nlinum-highlight-current-line + (= line nlinum--current-line)) + 'nlinum-current-line + 'linum) + str) + str)) + (setq nlinum-format-function #'doom-nlinum-format-fn) - (defun doom|init-nlinum-width () - "Calculate line number column width beforehand (optimization)." - (setq nlinum--width - (length (save-excursion (goto-char (point-max)) - (format-mode-line "%l"))))) - (add-hook 'nlinum-mode-hook #'doom|init-nlinum-width)) + (defun doom|init-nlinum-width () + "Calculate line number column width beforehand (optimization)." + (setq nlinum--width + (length (save-excursion (goto-char (point-max)) + (format-mode-line "%l"))))) + (add-hook 'nlinum-mode-hook #'doom|init-nlinum-width)) - ;; Fixes disappearing line numbers in nlinum and other quirks - (def-package! nlinum-hl - :after nlinum - :config - ;; With `markdown-fontify-code-blocks-natively' enabled in `markdown-mode', - ;; line numbers tend to vanish next to code blocks. - (advice-add #'markdown-fontify-code-block-natively - :after #'nlinum-hl-do-markdown-fontify-region) +;; Fixes disappearing line numbers in nlinum and other quirks +(def-package! nlinum-hl + :unless (boundp 'display-line-numbers) + :after nlinum + :config + ;; With `markdown-fontify-code-blocks-natively' enabled in `markdown-mode', + ;; line numbers tend to vanish next to code blocks. + (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 - ;; 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)) - - (def-package! nlinum-relative - :commands nlinum-relative-mode - :config - (after! evil - (nlinum-relative-setup-evil)))) +(def-package! nlinum-relative + :unless (boundp 'display-line-numbers) + :commands nlinum-relative-mode + :config + (after! evil (nlinum-relative-setup-evil))) ;;