nix-community / emacs-overlay

Bleeding edge emacs overlay [maintainer=@adisbladis]
506 stars 165 forks source link

haskell-mode-autoloads not being loaded causing void-function haskell-doc-current-info #212

Closed ParetoOptimalDev closed 3 months ago

ParetoOptimalDev commented 2 years ago

Reproduce with shell.nix and nix-shell --run test-emacs:

{ pkgs ? import (builtins.fetchTarball {
  url = "https://github.com/nixos/nixpkgs/archive/a7ecde854aee5c4c7cd6177f54a99d2c1ff28a31.tar.gz";
}) {
    overlays = [
      (import (builtins.fetchTarball {
        url = https://github.com/nix-community/emacs-overlay/archive/c4bcf4b66394a4472cc251e2350c557dac13d621.tar.gz;
      }))];}, ... }:
let
    emacsPkgs = epkgs: [
    (builtins.trace "===> ${epkgs.haskell-mode.name}" epkgs.melpaPackages.haskell-mode)
    ];
    pkgsWithOverlay = (import (builtins.fetchTarball {
      url = "https://github.com/nixos/nixpkgs/archive/a7ecde854aee5c4c7cd6177f54a99d2c1ff28a31.tar.gz";
    })) {
      overlays = [
        (import (builtins.fetchTarball {
          url = https://github.com/nix-community/emacs-overlay/archive/master.tar.gz;
        }))
      ];
    };

  # works
  myEmacsGcc = (pkgsWithOverlay.emacsPackagesGen pkgsWithOverlay.emacsGcc).emacsWithPackages (epkgs: ([
      epkgs.haskell-mode
  ]));

  emacsWithOverlay = pkgsWithOverlay.emacsWithPackagesFromUsePackage {
    config = builtins.readFile dotEmacs; # builtins.readFile ./emacs.el;

    # emacs correctly loads autloads with extraEmacsPackages
    # package = pkgsWithOverlay.emacs;
    # extraEmacsPackages = emacsPkgs;

    # emacsGcc does not autoload for packages in extraEmacsPackages
    # eldoc error: (void-function haskell-doc-current-info)
    package = pkgsWithOverlay.emacsGcc;
    extraEmacsPackages = emacsPkgs;

    # using emacsPackagesGen correctly loads autoloads
    # package = myEmacsGcc;

  };
  dotEmacs = pkgs.writeText "dot-emacs" ''
  (require 'haskell-mode)
  '';
  trivialHaskell = pkgs.writeText "foo.hs" ''
  module Main where
  main = undefined
  '';
  testEmacsHaskell = pkgs.writeScriptBin "test-emacs" ''
    exec ${emacsWithOverlay}/bin/emacs -Q -l ${dotEmacs} ${trivialHaskell}
  '';
in pkgs.mkShell {
  buildInputs = [ testEmacsHaskell ];
}
ParetoOptimalDev commented 2 years ago

Note there is a workaround I was given in the Nix Emacs matrix room:

(dolist (path load-path)
  (when (string-match-p "/nix/store/[a-z0-9]\\{32\\}-emacs-packages-deps.*" path)
    (dolist (autoload-file (directory-files path t "-autoloads.el"))
      (with-demoted-errors "init.el error: %s"
        (load autoload-file nil t)))))

This does fix things as you can see if you add it to the repro above:

{ pkgs ? import (builtins.fetchTarball {
  url = "https://github.com/nixos/nixpkgs/archive/a7ecde854aee5c4c7cd6177f54a99d2c1ff28a31.tar.gz";
}) {
    overlays = [
      (import (builtins.fetchTarball {
        url = https://github.com/nix-community/emacs-overlay/archive/c4bcf4b66394a4472cc251e2350c557dac13d621.tar.gz;
      }))];}, ... }:
let
    pkgsWithOverlay = (import (builtins.fetchTarball {
      url = "https://github.com/nixos/nixpkgs/archive/a7ecde854aee5c4c7cd6177f54a99d2c1ff28a31.tar.gz";
    })) {
      overlays = [
        (import (builtins.fetchTarball {
          url = https://github.com/nix-community/emacs-overlay/archive/master.tar.gz;
        }))
      ];
    };
    emacsPkgs = epkgs: [
    (builtins.trace "===> ${epkgs.haskell-mode.name}" epkgs.melpaPackages.haskell-mode)
    ];

  # works... err.. doesn't work?
  myEmacsGcc = (pkgsWithOverlay.emacsPackagesFor pkgsWithOverlay.emacsGcc).emacsWithPackages (epkgs: ([
    epkgs.haskell-mode
  ]));

  myEmacsGccImportedEmacsPackages = (pkgsWithOverlay.emacsPackagesGen pkgsWithOverlay.emacsGcc).emacsWithPackages (import ./emacs-packages.nix);

  emacsWithOverlay = pkgsWithOverlay.emacsWithPackagesFromUsePackage {
    config = builtins.readFile dotEmacs; # builtins.readFile ./emacs.el;
    package = myEmacsGcc;
  };

  dotEmacs = pkgs.writeText "dot-emacs" ''
(dolist (path load-path)
  (when (string-match-p "/nix/store/[a-z0-9]\\{32\\}-emacs-packages-deps.*" path)
    (dolist (autoload-file (directory-files path t "-autoloads.el"))
      (with-demoted-errors "init.el error: %s"
        (load autoload-file nil t)))))
  (message "autoloads hack complete")
  (require 'haskell-mode)
  '';
  trivialHaskell = pkgs.writeText "foo.hs" ''
  module Main where
  main = undefined
  '';
  testEmacsHaskell = pkgs.writeScriptBin "test-emacs" ''
    exec ${emacsWithOverlay}/bin/emacs -q -l ${dotEmacs} ${trivialHaskell}
  '';
in pkgs.mkShell {
  buildInputs = [ testEmacsHaskell ];
}

# nix-shell emacs/flavors/emacs-haskell-mode-repro.nix --run test-emacs

The downside of this being all autoloads in all versions of emacs you have installed are attempted, so it's not very reproducible.

The hack could be improved by getting the actual system deps path from load-path I think.

adisbladis commented 3 months ago

I am closing all issues that looks unrelated to the overlay itself. Issues reported here should only be pertaining to the overlay infrastructure.

Build issues, runtime issues & the like should be reported to nixpkgs, where this code actually lives.