aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/dashboard-config.el57
-rw-r--r--tests/test-dashboard-config.el10
2 files changed, 43 insertions, 24 deletions
diff --git a/modules/dashboard-config.el b/modules/dashboard-config.el
index d5aa501d..8507344d 100644
--- a/modules/dashboard-config.el
+++ b/modules/dashboard-config.el
@@ -92,30 +92,39 @@
(with-suppressed-warnings ((lexical el))
(defvar el))
-(defun dashboard-insert-bookmarks (list-size)
- "Add the list of LIST-SIZE items of bookmarks."
- (require 'bookmark)
- (dashboard-insert-section
- "Bookmarks:"
- (dashboard-subseq (bookmark-all-names) list-size)
- list-size
- 'bookmarks
- (dashboard-get-shortcut 'bookmarks)
- `(lambda (&rest _) (bookmark-jump ,el))
- (if-let* ((filename el)
- (path (bookmark-get-filename el))
- (path-shorten (dashboard-shorten-path path 'bookmarks)))
- (cl-case dashboard-bookmarks-show-path
- (`align
- (unless dashboard--bookmarks-cache-item-format
- (let* ((len-align (dashboard--align-length-by-type 'bookmarks))
- (new-fmt (dashboard--generate-align-format
- dashboard-bookmarks-item-format len-align)))
- (setq dashboard--bookmarks-cache-item-format new-fmt)))
- (format dashboard--bookmarks-cache-item-format filename path-shorten))
- (`nil filename)
- (t (format dashboard-bookmarks-item-format filename path-shorten)))
- el)))
+;; The override body uses the `dashboard-insert-section' MACRO, so it must be
+;; known when this module byte-compiles or the call compiles as a plain
+;; function call that evaluates `el' eagerly -- void-variable at render time.
+(eval-when-compile (require 'dashboard-widgets nil t))
+
+;; Registered after dashboard-widgets, not as a bare top-level defun: the
+;; use-package below reloads dashboard-widgets, which would clobber an eager
+;; override. Same shape as the banner-title override further down.
+(with-eval-after-load 'dashboard-widgets
+ (defun dashboard-insert-bookmarks (list-size)
+ "Add the list of LIST-SIZE items of bookmarks."
+ (require 'bookmark)
+ (dashboard-insert-section
+ "Bookmarks:"
+ (dashboard-subseq (bookmark-all-names) list-size)
+ list-size
+ 'bookmarks
+ (dashboard-get-shortcut 'bookmarks)
+ `(lambda (&rest _) (bookmark-jump ,el))
+ (if-let* ((filename el)
+ (path (bookmark-get-filename el))
+ (path-shorten (dashboard-shorten-path path 'bookmarks)))
+ (cl-case dashboard-bookmarks-show-path
+ (`align
+ (unless dashboard--bookmarks-cache-item-format
+ (let* ((len-align (dashboard--align-length-by-type 'bookmarks))
+ (new-fmt (dashboard--generate-align-format
+ dashboard-bookmarks-item-format len-align)))
+ (setq dashboard--bookmarks-cache-item-format new-fmt)))
+ (format dashboard--bookmarks-cache-item-format filename path-shorten))
+ (`nil filename)
+ (t (format dashboard-bookmarks-item-format filename path-shorten)))
+ el))))
;; ------------------------- Banner Title Centering Fix ------------------------
;; The default centering can be off due to font width calculations.
diff --git a/tests/test-dashboard-config.el b/tests/test-dashboard-config.el
index 2dbcd4f4..3a48ee56 100644
--- a/tests/test-dashboard-config.el
+++ b/tests/test-dashboard-config.el
@@ -56,5 +56,15 @@ start at the top. Without `set-window-start', batch redisplay leaves
(when (buffer-live-p dash)
(kill-buffer dash)))))
+(ert-deftest test-dashboard-config-bookmark-override-deferred-to-package-load ()
+ "Normal: the bookmarks override is defined exactly when dashboard-widgets is.
+A bare top-level defun would exist even without the package (and be
+clobbered when the package loads); the deferred registration means the
+function tracks the package's own load state. Holds in both runners:
+the hook env loads dashboard, the make-test env can't."
+ (if (featurep 'dashboard-widgets)
+ (should (fboundp 'dashboard-insert-bookmarks))
+ (should-not (fboundp 'dashboard-insert-bookmarks))))
+
(provide 'test-dashboard-config)
;;; test-dashboard-config.el ends here