jwiegley / use-package

A use-package declaration for simplifying your .emacs
https://jwiegley.github.io/use-package
GNU General Public License v3.0
4.4k stars 260 forks source link

Does `:custom` run after package loaded? #1016

Closed snowman closed 1 year ago

snowman commented 1 year ago

I use package recentf, which has customize variable recentf-auto-cleanup with default value of mode, which means it'll cleanup some missing file path after turning the recentf-mode on.

(defcustom recentf-auto-cleanup 'mode
  "Define when to automatically cleanup the recent list.
The following values can be set:

- `mode'
    Cleanup when turning the mode on (default).  <--------
- `never'
    Never cleanup the list automatically.

Here is the customization of recentf:

(use-package recentf
  :hook (after-init . recentf-mode)
  :custom
  (recentf-auto-cleanup 'never))

so when loading the package, with :custom keyword defined, what's the value of the variable (mode or never)? and which one should I use, :init or :custom? Thanks

(use-package recentf
  :hook (after-init . recentf-mode)
  :init
  (setq recentf-auto-cleanup 'never))
skangas commented 1 year ago

I would suggest using :custom. Typing M-x pp-macroexpand-last-sexp RET tells me that your first form expands to this, which seems to be what you want:

(progn
  (let
      ((custom--inhibit-theme-enable nil))
    (unless
        (memq 'use-package custom-known-themes)
      (deftheme use-package)
      (enable-theme 'use-package)
      (setq custom-enabled-themes
            (remq 'use-package custom-enabled-themes)))
    (custom-theme-set-variables 'use-package
                                '(recentf-auto-cleanup 'never nil nil "Customized with use-package recentf")))
  (unless
      (fboundp 'recentf-mode)
    (autoload #'recentf-mode "recentf" nil t))
  (add-hook 'after-init-hook #'recentf-mode))