~mgmarlow/public-inbox

2

[BUG] autoloads should not assume project.el is loaded

Details
Message ID
<877cp94iyl.fsf@gmail.com>
DKIM signature
missing
Download raw message
Your autoloads file will fail to load with the following error:

void-function project-vc-extra-root-markers


Instead of:

;;;###autoload
(dolist (file '("deno.json" deno.jsonc"))
  (add-to-list 'project-vc-extra-root markers file))

You should wrap the form in with-eval-after-load:

;;;###autoload
(with-eval-after-load "project"
  (dolist (file '("deno.json" deno.jsonc"))
    (add-to-list 'project-vc-extra-root markers file)))

That should do the right thing.
Details
Message ID
<619c92d2-934f-47e1-9cbd-0123e7979a86@mgmarlow.com>
In-Reply-To
<877cp94iyl.fsf@gmail.com> (view parent)
DKIM signature
missing
Download raw message
> 
> Your autoloads file will fail to load with the following error:
> 
> void-function project-vc-extra-root-markers

Great catch, thank you. I just pushed your fix to main.
Details
Message ID
<617ef50d-e6c6-4cab-b1af-d44e38034ff8@mgmarlow.com>
In-Reply-To
<877cp94iyl.fsf@gmail.com> (view parent)
DKIM signature
missing
Download raw message
> Instead of:
> 
> ;;;###autoload
> (dolist (file '("deno.json" deno.jsonc"))
>   (add-to-list 'project-vc-extra-root markers file))
> 
> You should wrap the form in with-eval-after-load:
> 
> ;;;###autoload
> (with-eval-after-load "project"
>   (dolist (file '("deno.json" deno.jsonc"))
>     (add-to-list 'project-vc-extra-root markers file)))
> 
> That should do the right thing.

I was also considering requiring dependencies in the autoload to make 
the file extensions available to `auto-mode-alist' automatically without 
an extra function call. What do you think of using a regular `require' 
statement in the autoloads instead of a `with-eval-after-load'? Not sure 
I fully understand the differences, but it seems like `require' might be 
preferred for this situation based on the manual.

;;;###autoload
(progn
   (require 'project)
   (add-to-list 'auto-mode-alist '("\\.ts\\'" . deno-ts--ts-auto-mode))
   (add-to-list 'auto-mode-alist '("\\.tsx\\'" . deno-ts--tsx-auto-mode)))

;;;###autoload
(progn
   (require 'project)
   (dolist (file '("deno.json" "deno.jsonc"))
     (add-to-list 'project-vc-extra-root-markers file)))
Reply to thread Export thread (mbox)