felko / neuron-mode

An emacs mode for editing Zettelkasten notes with neuron
GNU General Public License v3.0
118 stars 21 forks source link

main directory symlink #46

Closed garrett-hopper closed 4 years ago

garrett-hopper commented 4 years ago

I have ~/zet as a symbolic link to another data directory. This works fine for the most part, however when I'm actually in the directory in Emacs (my pwd is a child of that directory), neuron--get-zettelkasten returns the unexpanded ~/zet instead of the full /home/garrett/zet which would work. I was able to fix this by adding an expand-file-name around (neuron--detect-zettelkasten pwd).

(defun neuron--get-zettelkasten (&optional pwd)
  "Return the location of the current zettelkasten.
Assuming the current working directory is PWD, first try to
detect the zettelkasten automatically by traversing the hierarchy
upwards until a neuron.dhall file is found. When no neuron.dhall
file is found, return `neuron-default-zettelkasten-directory'.
Lastly, if the default zettelkasten location doesn't point to
an actual directory, return nil."
  (interactive "P")
  (or
   (expand-file-name (neuron--detect-zettelkasten pwd))
   (let ((root neuron-default-zettelkasten-directory))
     (and (f-exists? root) (f-directory? root) neuron-default-zettelkasten-directory))))

It's worth noting that doing some debugging shows that pwd is nil when neuron--detect-zettelkasten is called.

This is the error I got when ~/zet wasn't being expanded: user-error: Command "neuron --zettelkasten-dir \~/zet/ query --uri z\:zettels" exited with code 1: neuron: user error (Zettelkasten directory ~/zet/ does not exist.)

garrett-hopper commented 4 years ago

Err, it should only be expanded if (neuron--detect-zettelkasten pwd) returns non-nil.

(defun neuron--get-zettelkasten (&optional pwd)
  "Return the location of the current zettelkasten.
Assuming the current working directory is PWD, first try to
detect the zettelkasten automatically by traversing the hierarchy
upwards until a neuron.dhall file is found. When no neuron.dhall
file is found, return `neuron-default-zettelkasten-directory'.
Lastly, if the default zettelkasten location doesn't point to
an actual directory, return nil."
  (interactive "P")
  (or
   (if-let ((x (neuron--detect-zettelkasten pwd)))
       (expand-file-name x))
   (let ((root neuron-default-zettelkasten-directory))
     (and (f-exists? root) (f-directory? root) neuron-default-zettelkasten-directory))))
felko commented 4 years ago

You should be able to expand the path directly when setting neuron-default-zettelkasten-directory, I have tested (setq neuron-default-zettelkasten-directory (expand-file-name "~/zet")) (where ~/zet is a symlink to my actual zk directory) and it appears to work.

I remember voluntarily not expanding the file name automatically, mimicking what I had seen in other emacs lisp code, but actually I don't see any downside to do this, which indeed would be more intuitive.

However, I can't quite reproduce your error. I can see the same error, but it occurs when I am NOT in my actual zettelkasten directory, and it works just fine with neuron--detect-zettelkasten. That is a bit odd, do you mind detailing exactly what were the values of neuron-default-zettelkasten-directory and (pwd)?

felko commented 4 years ago

Maybe you can try with the latest master. The https://github.com/felko/neuron-mode/commit/18d230ce6b126fe7193db9c20ac93811ccfe779d commit expands all file names.

garrett-hopper commented 4 years ago

This appears to be working correctly now, thanks!