Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoload generated with wrong path when .emacs.d is a symlink and find-file-visit-truename is non-nil #944

Open
kisaragi-hiu opened this issue Apr 30, 2022 · 6 comments
Labels

Comments

@kisaragi-hiu
Copy link

What's wrong

My ~/.emacs.d is a symlink to ~/.dotfiles/emacs/.emacs.d, and I set find-file-visit-truename to t.

Autoloaded commands fail to load the files that they are associated with, even though require works.

(I'll explain why this is happening below.)

Directions to reproduce

  1. mkdir -p /tmp/home, cd /tmp/home, export HOME=$(pwd) (to not be affected by existing config)

  2. mkdir -p .dotfiles/emacs/.emacs.d, ln -s .dotfiles/emacs/.emacs.d .emacs.d

  3. Put this into /tmp/home/.emacs.d/init.el:

    ;; straight.el bootstrap
    (defvar bootstrap-version)
    (defvar straight-repository-branch "develop")
    (defvar straight-vc-git-default-clone-depth 1) ; speed this up
    (let ((bootstrap-file
           (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
          (bootstrap-version 5))
      (unless (file-exists-p bootstrap-file)
        (with-current-buffer
            (url-retrieve-synchronously
             "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
             'silent 'inhibit-cookies)
          (goto-char (point-max))
          (eval-print-last-sexp)))
      (load bootstrap-file nil 'nomessage))
    
    (setq find-file-visit-truename t)
    
    ;; Using a package with autoloads for demonstration
    (straight-use-package 'ag)
  4. Try to run ag; this will fail as the autoloads file looks like this (docstring omitted):

    (autoload 'ag "../../../../../../.emacs.d/straight/build/ag/ag" ...)
    

Why this is happening

(I don't know why it didn't happen in Emacs 27. Perhaps it's a change introduced by make-directory-autoloads.)

make-directory-autoloads does not resolve symlinks in its DIR argument (or files within that directory) even when find-file-visit-truename is non-nil — this is as expected.

However, it does visit its OUTPUT-FILE argument with find-file in a call to autoload-find-generated-file.

In the example, one of the input files in make-directory-autoloads would be /tmp/home/.emacs.d/straight/build/ag/ag.el, but its associated output file would be resolved to /tmp/home/.dotfiles/emacs/.emacs.d/straight/build/ag/ag-autoloads.el. This then turns into the train of ../s when it's made relative.

To work around this, find-file-visit-truename should probably be let-bound to nil in straight--build-autoloads.

(This also happens for package.el, which makes it seem like an upstream bug.)

Version information

  • Emacs version: 28.1
  • Operating system: Arch Linux
  • straight.el: 4517e11
@progfolio
Copy link
Contributor

Duplicate of: #701

Your assessment is correct. I suggest adding to the upstream bug thread linked in #701 so this can be fixed in Emacs proper.

kisaragi-hiu added a commit to kisaragi-hiu/straight.el that referenced this issue Apr 30, 2022
…an-software#701)

When find-file-visit-truename, a user option, is non-nil,
make-directory-autoloads resolves symlinks in its second argument (as
it uses find-file-noselect under the hood) but not in its first. This
results in relative paths that are invalid when loaded.

See radian-software#701, radian-software#944, and upstream bug report
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=52292.
kisaragi-hiu added a commit to kisaragi-hiu/straight.el that referenced this issue Apr 30, 2022
…an-software#701)

In Emacs 28.1, when find-file-visit-truename, a user option, is
non-nil, make-directory-autoloads resolves symlinks in its second
argument (as it uses find-file-noselect under the hood) but not in its
first. This results in relative paths that are invalid when loaded.

See radian-software#701, radian-software#944, and upstream bug report
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=52292.
@kisaragi-hiu
Copy link
Author

I'll add the details to the upstream bug report; in the meantime I'm opening #945 to work around it in Emacs 28.

@progfolio
Copy link
Contributor

I'll add the details to the upstream bug report; in the meantime I'm opening #945 to work around it in Emacs 28.

Sounds good. I'll take a look at the pull once the upstream report thread has been bumped.
I don't disagree that we should be able to work around this, but it's important that the problem is addressed upstream, too.

@progfolio
Copy link
Contributor

I did not notice the Emacs bug thread getting bumped. Took the liberty of suggesting a patch there first.

https://lists.gnu.org/archive/html/bug-gnu-emacs/2022-05/msg00795.html

kisaragi-hiu added a commit to kisaragi-hiu/straight.el that referenced this issue Jun 15, 2022
…an-software#701)

In Emacs 28.1, when find-file-visit-truename, a user option, is
non-nil, make-directory-autoloads resolves symlinks in its second
argument (as it uses find-file-noselect under the hood) but not in its
first. This results in relative paths that are invalid when loaded.

See radian-software#701, radian-software#944, and upstream bug report
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=52292.
@doolio
Copy link

doolio commented Oct 16, 2023

Just encountered this issue with Emacs 28.2. I take it the upstream issue has not been resolved yet. Is this only affecting straight users?

@progfolio
Copy link
Contributor

progfolio commented Oct 16, 2023

Just encountered this issue with Emacs 28.2. I take it the upstream issue has not been resolved yet. Is this only affecting straight users?

#701 (comment)

Problem hasn't been addressed upstream. I suggest adding to any of the upstream threads mentioned here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants