nix-community / nix-emacs

A set of useful Emacs modes and functions for users of Nix and Nix OS.
226 stars 32 forks source link

Name collision with nix-mode #48

Closed c0deaddict closed 4 years ago

c0deaddict commented 5 years ago

I'm using nix-mode and would like to also make use of nix-sandbox for Flycheck (and other executables where possible). Unfortunately the example code in the README does not work. When trying to Flycheck a file I get the error:

eval: Wrong number of arguments: (1 . 2), 3

After some digging I found that the bug appears to be that nix-sandbox declares a function called nix-shell which overlaps with a function defined in the nix-mode package.

svenkeidel commented 5 years ago

@c0deaddict, thank you for reporting this issue. I'll take a look.

svenkeidel commented 5 years ago

Yes, there is a name conflict, but I don't think the error you are getting is related to this name conflict. Just to be sure, can you retry without loading the nix-mode package?

c0deaddict commented 5 years ago

Without loading nix-mode it works. I think the problem is that i'm loading nix-sandbox before nix-mode hence nix-shell of nix-sandbox is redefined. Without changing the loading order, this "fix" works:

  (use-package nix-mode
    :ensure t
    :init
    (add-to-list 'interpreter-mode-alist '("nix-shell" . nix-shebang-mode))
    (add-to-list 'auto-mode-alist '("\\.nix\\'" . nix-mode))
    :config
    ;; Override nix-shell defined in nix-mode with this definition from nix-sandbox.
    ;; https://github.com/travisbhartwell/nix-emacs/issues/48
    (defun nix-shell (sandbox &rest command)
      "Run a COMMAND in the given SANDBOX and return the output."
      (shell-command-to-string (apply 'nix-shell-string sandbox command)))
    )
svenkeidel commented 5 years ago

Great, thanks for testing. I'll just rename the function.

c0deaddict commented 5 years ago

Thanks!

thalesmg commented 4 years ago

Hello!

First, thanks for creating and sharing this package! 🍻

I have stumbled upon this problem as well. I've made a PR with a possible solution: #49

Cheers!