felko / neuron-mode

An emacs mode for editing Zettelkasten notes with neuron

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom binary location support

yigitemres opened this issue · comments

Firstly, thanks for the package.

Secondly, can we have custom binary location support for WSL users?
Something like

(setq neuron-binary-location "...."))

I'm not expert on elisp. I look at the code but I can't see anything like that. If it is exit can you put it into Customize setting part?

commented

Hello!
If you installed neuron via nix (which is currently the only way to install it AFAIK), the binary should be in your path assuming nix itself is installed correctly. I have never used WSL, so it's possible that I'm missing something very obvious, but if neuron is in your path, and that emacs runs inside WSL, it should work seamlessly without any further configuration.
Also, hard linking to an executable (or anything, really) inside the nix store is something that shouldn't ever be needed.

My setup is kinda different. When I'm explain the problem you probably understand.

I use WSL2(Gentoo). I install nix. I install neuron. Everything is working under WSL part, no problem.

My problem (or my need) starts when I need to use Windows Emacs. MS actually doesn't recommend using WSL apps while saving files and vice versa. (Maybe this changed in WSL2 I don't know but still, this package is looking so good that I'm ignoring that recommendation.) When emacs send commands uses cmd.exe if I'm correct. While activating neuron-mode emacs return this error:

Command ""neuron" "--zettelkasten-dir" "c:/Users/yigitemres/zettelkasten" "query" "--uri" "z:zettels"" exited with code 1: 

'"neuron"' is not recognized as an internal or external command, operable program or batch file.

This issue probably caused because of emacs try to send directly neuron command to cmd.exe. To fix this issue, we have to send wsl neuron command to cmd.exe. If we have ability to modify neuron bin location (actually maybe location is not the correct word, we need to modify neuron arg itself.) we can fix this issue easily.

(Actually this is not work either unless creating symbolic link to /usr/bin or /usr/local/bin for neuron binary while calling like wsl neuron. For some reason, (maybe its my nix setup inside gentoo idk) cmd.exe cannot find bin if its inside .nix-profile/bin folder. It's probably safety feature or I'm missing something. When calling neuron inside WSL is working flawlessly.)

That's the reason why I need this change basically.

commented

I have to say that I'm not too fond on the idea of adding parameters just for very specific setups, especially if MS warns against using WSL apps while saving files. However, if I get this request from other users I might add it (I have no idea if that kind of workflow is common or not).

In the meantime, here is a small fix that I hope suits your needs: add the following lines somewhere in your emacs configuration, assuming neuron-mode is loaded when they are executed:

(defun wrap-command-in-wsl (cmd)
  (concat "wsl " cmd))

(advice-add 'neuron--make-command :filter-return #'wrap-command-in-wsl)

Let me know if that did the trick

Thanks for your responds.

I think this change is not only good for my setup but also gives user flexibility to setting location of the binary easily. (It's feels like using #!/usr/bin/env python instead of #!/usr/bin/python) While I'm waiting for your response and try to solve the issue by myself, I'm already change the behavior of the neuron--make-command with el-patch. Emacs sends command correctly but for some reason neuron-default-zettelkasten-directory is not read correctly. It prints:

user-error: Invalid zettelkasten: /mnt/c/Users/yigitemres/.config/emacs/var/zettelkasten/ does not exist

But when I use the same dir from eshell and cmd.exe, it creates .md without any error. Until found the whats wrong, I'm gonna close the issue.

Sorry for the late night trouble. Thanks again for the package. Have a nice day. 🥂

commented

I think this change is not only good for my setup but also gives user flexibility to setting location of the binary easily. (It's feels like using #!/usr/bin/env python instead of #!/usr/bin/python)

Okay good point, I read too fast and was thinking about adding a WSL-specific setting. That still doesn't solve your problem, but I think I'll add this feature after all. Feel free to open another issue if you find out any other misbehavior of neuron/neuron-mode on WSL.
Thanks for the suggestion, and have a nice day too

This might also be useful in the hypothetical scenario of something installing neuron via docker image (srid/neuron#146). docker run -v .. neuron ....

commented

Implemented in 039a741

commented

Actually it was buggy when neuron-executable contained space (which is the case for wsl neuron), should be fixed in db9e103