diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 0881626e92..67ce30a93c 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -1103,8 +1103,17 @@ package-generate-autoloads (package-lisp-dir pkg-desc) output-file nil (prin1-to-string - `(add-to-list 'load-path - ,(package-lisp-dir pkg-desc)))) + `(add-to-list + 'load-path + (file-name-concat + ;; Add the directory that will contain the autoload file to + ;; the load path. We don't hard-code `pkg-dir', to avoid + ;; issues if the package directory is moved around. + (or (and load-file-name (file-name-directory load-file-name)) + (car load-path)) + ;; In case the package specification indicates that the lisp + ;; files are found in a subdirectory, append that path. + ,(alist-get :lisp-dir (package-desc-extras pkg-desc)))))) (let ((buf (find-buffer-visiting output-file))) (when buf (kill-buffer buf))) auto-name))