Subject: bug#48181: incremental autoloads update can put output in wrong file

From: Eli Zaretskii <[email-masked]>
Date: Mon, 03 May 2021 14:37:44 +0300

> From: Glenn Morris <[email-masked]>
> Date: Sun, 02 May 2021 21:08:57 -0400
> Cc: Stefan Monnier <[email-masked]>
> 
> 1) before 68bf917896, lisp/loaddefs.el contains sections like this:
> 
>   ;;;### (autoloads nil "texnfo-upd" "textmodes/texnfo-upd.el" (0 0
>   ;;;;;;  0 0))
>   ;;; Generated autoloads from textmodes/texnfo-upd.el
> 
>   (register-definition-prefixes "texnfo-upd" '("texinfo-"))

(The other 2 files, makeinfo.el and texinfo.el, are also related,
right?)

> So even though there aren't any real autoloads in texnfo-upd.el, it's
> not in the "no autoloads" section.
> 
> 2) 68bf917896 added real autoload cookies to texnfo-upd.el, and set
> generated-autoload-file to texinfo-loaddefs.el.
> 
> 3) make-directory-autoloads correctly finds that texnfo-upd.el is newer
> than loaddefs.el, so we execute this branch:
>   
>   (t
>    (setq changed t)
>    (autoload-remove-section (match-beginning 0))
>    (if (autoload-generate-file-autoloads
>          ;; Passing `current-buffer' makes it insert at point.   
>          file (current-buffer) buffer-file-name)
>         (push file no-autoloads)))
> 
> Because a non-nil OUTBUF is passed to autoload-generate-file-autoloads,
> it ignores the buffer-local setting for generated-autoload-file,
> and so puts the autoloads in the main loaddefs.el file, which is wrong.
> 
> 
> In contrast, if the input loaddefs.el file in step 1 had texnfo-upd.el
> in the "no loaddefs" section, then we would execute this branch:
> 
>   ;; Passing nil as second argument forces                             
>   ;; autoload-generate-file-autoloads to look for the right            
>   ;; spot where to insert each autoloads section.                      
>   ((setq file-time
>          (autoload-generate-file-autoloads file nil buffer-file-name))
>  
> As the comment says, this version has OUTBUF nil, so the loaddefs end up
> the right file.

Yes, I've also figured out that by suitable editing of the nascent
loaddefs.el I could fix the original problem.  But such manual editing
sounded gross to me.

Or are you saying something else?