1

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))))

(eval-when-compile
  (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.

4
  • Side note: f-join is not a command, it's a function.
    – Stefan
    Nov 7, 2018 at 23:10
  • Could you explain why you want f-join autoloaded?
    – Stefan
    Nov 7, 2018 at 23:12
  • @Stefan To avoid loading f.el in case I did not use f-join? Nov 8, 2018 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, 2018 at 14:04

1 Answer 1

3

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

(progn
  (defvar use-package--warning281
    #'(lambda
        (keyword err)
        (let
            ((msg
              (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
           '(unless
                (fboundp 'f-join)
              (autoload #'f-join "f" nil t))))
    (error
     (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 and acknowledge you have read our privacy policy.

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