protesilaos / denote

Simple notes for Emacs with an efficient file-naming scheme
https://protesilaos.com/emacs/denote
GNU General Public License v3.0
455 stars 49 forks source link

denote-dired-mode ("fontification") not triggered in subdirectory if subdirectory is symlinked #346

Open julian-hoch opened 1 month ago

julian-hoch commented 1 month ago

I am not sure if this is a defect in Denote, or something that is just not possible in Emacs, but if you

you will get dired mode only for subdirectories that are physical subdirectories, not symlinks. I am wondering if there is a way to make sure dired follows the symlink when determining whether to enable the denote mode.

A workaround is to manually add the symlinked directories to "denote-dired-directories", but obviously this only works if there are few subdirectories (and makes it a bit cumbersome to configure for cases where the same config is used on different computers with a different subfolder structure on the respective denote directory).

protesilaos commented 1 month ago

From: Julian Hoch @.***> Date: Sat, 11 May 2024 10:46:06 -0700

I am not sure if this is a defect in Denote, or something that is just not possible in Emacs, but if you

  • set up multiple subdirectories below your main denote directory
  • configure the hook for dired-mode
  • enable denote-mode in dired for subdirectories using denote-dired-directories-include-subdirectories

Okay, let's try to find out:

-- Protesilaos Stavrou https://protesilaos.com

julian-hoch commented 1 month ago

Hi Prot! Yeah, the directories are all set up correctly. I suspect that the issue lies here:

;; denote.el - defun denote-dired-mode-in-directories
[...]
             ((or (member (file-truename default-directory) dirs)
[...]

"file-truename" resolves symlinks, so this will compare the directories I configured in my emacs config with the "true" path of the dorectory I am in - which will not resolve to the same path in my case.

In my case, I set up the denote directories as ~/denote/private, ~/denote/customer, which link to ~/git/denote-private-kb and ~/git/denote-customer-kb, just for convenience. So the "member" test will fail if I access them via the symlink (but it works if I dired into the "real" path).

I suspect this could be fixed by also applying file-truename to all the directories in the "dirs" list. Julian

protesilaos commented 1 month ago

Thank you for looking into this!

I suspect this could be fixed by also applying file-truename to all the directories in the "dirs" list.

Maybe we can just remove the file-truename? It has always been there but I am not sure it is necessary.

julian-hoch commented 1 month ago

My understanding is that the advantage of using file-truename is that it does not matter if you use a symlink to look at your files. So if you have your denote directory in one physical location, and then link to it from various other places, I would think people would typically want to enable the dired mode for all of these, I don't see a reason why you would not want that. You could also make it optional - a configuration variable "follow-symlinks" or something (similar in the way ripgrep and other utilities handle it) so that if it is set to

protesilaos commented 4 weeks ago

Since I am new to emacs and elisp I am not super confident I can implement this myself, but if you don't have the time for it I can give it a go.

What we can do is introduce a variable like denote-directory-check-path-function. Its default value will be the function we are using right now. Then we arrange to funcall this variable, so users who experience this problem can define the alternative that works for them.