travisbhartwell / nix-emacs

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

Functions for integrating haskell-mode with ghc mod #33

Open Profpatsch opened 8 years ago

Profpatsch commented 8 years ago

Yesterday I played around a little with nix-sandbox and found the following functions make it work (at least partially):

  ;; haskell with nix
  (setq haskell-process-wrapper-function
        (lambda (args) apply 'nix-shell-command (nix-current-sandbox) args))

  (setq flycheck-command-wrapper-function
        (lambda (command) (apply 'nix-shell-command (nix-current-sandbox) command))
        flycheck-executable-find
        (lambda (cmd) (nix-executable-find (nix-current-sandbox) cmd)))

  (defun my-ghc-mod-setup ()
    (set (make-local-variable 'my-ghc-mod) (nix-executable-find (nix-current-sandbox) "ghc-mod"))
    (message "local ghc-mod is: %S" my-ghc-mod)
    (set (make-local-variable 'ghc-module-command) my-ghc-mod)
    (set (make-local-variable 'ghc-command) my-ghc-mod))
  (add-hook 'haskell-mode-hook 'my-ghc-mod-setup)

The first two are from the docs, the ghc package needs the variables ghc-module-command and ghc-command set to work. I make the buffer local, because they are different for every file, obviously. Maybe there is a better solution than buffer-local? Maybe per folder? On the other hand the nix-build overhead is not that big (I think).

There’s still a bit of duplication, but what’s the general impression?

svenkeidel commented 8 years ago

Consecutive calls to nix-executable-find do not run nix-shell every time. The environment of each sandbox is cached and nix-executable-find searches the cached environment again, i.e. the overhead is not that big. However, I think your solution is also fine. Let me know if you have further questions.