I would like to autoload the command f-join from f.el using use-package. Note that the package f.el depends on the packages dash.el and s.el. Here is a minimal example:

(setq debug-on-error t)
(let ((default-directory  "~/test/emacs")
      (packages (list "dash.el" "f.el" "s.el" "use-package")))
  (dolist (package packages)
    (add-to-list 'load-path (expand-file-name package))))

  (require 'use-package))

(use-package dash
  :defer t)

(use-package f
  :after (s dash)   ;; make loading order-independent
  :commands f-join  ;; add autoload for f-join
  :defer t)

(use-package s
  :defer t)

(f-join "a" "b")
(message-box "Everything ok")

Running this with emacs -Q -l gives error:

Debugger entered--Lisp error: (void-function f-join)

Changing :defer to :demand on the dependent packages dash.el and s.el eliminates the error message, but now the packages are no longer autoloaded, which is what I wanted to avoid.

  • Side note: f-join is not a command, it's a function.
    – Stefan
    Nov 7 '18 at 23:10
  • Could you explain why you want f-join autoloaded?
    – Stefan
    Nov 7 '18 at 23:12
  • @Stefan To avoid loading f.el in case I did not use f-join? Nov 8 '18 at 5:23
  • Yes, but what I meant is: how come you sometimes use f-join and sometimes not? [ side note: instead of (f-join A B) you can use (expand-file-name B A) without needing any extra library. f-join here only saves you a few keystrokes, and costs you extra processing. ]
    – Stefan
    Nov 8 '18 at 14:04

Remove :after (s dash), they will be required while loading f.el.

By using M-x emacs-lisp-macroexpand, you can expand your use-package use into

  (defvar use-package--warning281
        (keyword err)
              (format "%s/%s: %s" 'f keyword
                      (error-message-string err))))
          (display-warning 'use-package msg :error))))
  (condition-case-unless-debug err
      (eval-after-load 'dash
        '(eval-after-load 's
                (fboundp 'f-join)
              (autoload #'f-join "f" nil t))))
     (funcall use-package--warning281 :catch err))))

So f-join is not autoloaded in time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.