Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: elpaca example results in initializing dashboard twice #499

Open
montchr opened this issue Feb 24, 2024 · 2 comments
Open

docs: elpaca example results in initializing dashboard twice #499

montchr opened this issue Feb 24, 2024 · 2 comments

Comments

@montchr
Copy link

montchr commented Feb 24, 2024

The example for configuring this package for Elpaca compatibility calls dashboard-setup-startup-hook, however this results in initializing the dashboard on after-init-hook in addition to the correct elpaca-after-init-hook.

Source of dashboard-setup-startup-hook:

;;;###autoload
(defun dashboard-setup-startup-hook ()
"Setup post initialization hooks unless a command line argument is provided."
(when (< (length command-line-args) 2) ;; Assume no file name passed
(add-hook 'window-size-change-functions #'dashboard-resize-on-hook 100)
(add-hook 'window-setup-hook #'dashboard-resize-on-hook)
(add-hook 'after-init-hook #'dashboard-insert-startupify-lists)
(add-hook 'emacs-startup-hook #'dashboard-initialize)))

README example:

(use-package dashboard
:elpaca t
:config
(add-hook 'elpaca-after-init-hook #'dashboard-insert-startupify-lists)
(add-hook 'elpaca-after-init-hook #'dashboard-initialize)
(dashboard-setup-startup-hook))

Thanks to #475, it is at least possible to work around.

Edit, providing example:

(use-package dashboard  
  :ensure t 
  :config 
  (add-hook 'elpaca-after-init-hook #'dashboard-insert-startupify-lists) 
  (add-hook 'elpaca-after-init-hook #'dashboard-initialize) 
  (add-hook 'window-size-change-functions #'dashboard-resize-on-hook 100)
  (add-hook 'window-setup-hook #'dashboard-resize-on-hook)) 

The common add-hook usages could be extracted to a separate function and then a call to that function could be added in the Elpaca example. The function should then also be called in dashboard-setup-startup-hook to replace the original lines, preserving backward compatibility.

Also note that :elpaca t should be replaced with :ensure t due to upstream changes.

@jcs090218
Copy link
Member

cc @progfolio

@progfolio
Copy link
Contributor

progfolio commented Feb 24, 2024

The above assessment looks sound to me.
I don't use this package, so I don't have a strong implementation preference.
Another solution is to add optional args to the setup function like so:

;; Probably want to avoid the -hook suffix in the actual parameter names.
;; But for example's sake:
(defun dashboard-setup-startup-hook (&optional insert-hook init-hook)
  "Setup post initialization hooks unless a command line argument is provided.
If INSERT-HOOK or INIT-HOOK are non-nil, use those instead of the default initalization hooks."
  (when (< (length command-line-args) 2) ;; Assume no file name passed
    (add-hook 'window-size-change-functions #'dashboard-resize-on-hook 100)
    (add-hook 'window-setup-hook #'dashboard-resize-on-hook)
    (add-hook (or insert-hook 'after-init-hook) #'dashboard-insert-startupify-lists)
    (add-hook (or init-hook 'emacs-startup-hook) #'dashboard-initialize)))

That way we avoid extracting the logic from the setup function.
Then the configuration could check for the presence of the `elpaca' feature:

(use-package dashboard
  :ensure t
  :config
  (apply #'dashboard-setup-startup-hook
         (when (featurep 'elpaca) '(elpaca-after-init-hook elpaca-after-init-hook))))

What do you two think of that idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants