Subject: Re: bug#60155: 29.0.60; package-vc doesn't detect subdirectories when installing from repositories
From: Philip Kaludercic <[email-masked]>
To: [email-masked]
Date: Sun, 25 Dec 2022 10:22:24 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Philip Kaludercic <[email-masked]> writes:

>   M-x package-vc-install RET https://codeberg.org/martianh/mastodon.el RET
>
> This will fetch the package sources, but since the actual code is
> located in a "lisp" subdirectory, none of the actual files will be added
> to the load-path, making it appear as tough nothing were installed.
>
> This could be fixed by adding a heuristic to package-vc--unpack-1 that
> checks if there is a ./lisp/ directory (with .el files?) and that would
> add that to the load-path.  Are there any other directory names or
> structures that should be considered as well?  Is it common for packages
> to have loadable files in both the root directory of a repository and a
> sub-directory?
>
> I could imagine that this would be enough to resolve the issue:
>
> diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el
> index 8f0eedd2f8..eea5ad6c26 100644
> --- a/lisp/emacs-lisp/package-vc.el
> +++ b/lisp/emacs-lisp/package-vc.el
> @@ -443,6 +443,12 @@ package-vc--unpack-1
>             (auto-name (format "%s-autoloads.el" name))
>             (extras (package-desc-extras pkg-desc))
>             (lisp-dir (alist-get :lisp-dir extras)))
> +      ;; Heuristic to guess a sub-directory with lisp files.
> +      (when-let (((null lisp-dir))
> +                 (dir (expand-file-name "lisp" pkg-dir))
> +                 ((file-directory-p dir)))
> +        (setq lisp-dir dir))
> +
>        (package-generate-autoloads
>         name (file-name-concat pkg-dir lisp-dir))
>        (when lisp-dir

I have installed a variation upon this diff in n06368fef.  Please report
if this heuristic is too aggressive.