davraamides / todotxt-mode

MIT License
59 stars 12 forks source link

Working directory path #51

Closed cureau closed 2 years ago

cureau commented 2 years ago

Big thank you for this project!—it's helped me a lot over the last year.

When setting these variables:

    "todotxtmode.todoFilename": "/todo.md",
    "todotxtmode.waitingFilename": "/waiting.md",
    "todotxtmode.somedayFilename": "/someday.md",

How do you refer to the root of the project? I've tried ./ (used in some projects like Foam) and the / used above. When using the "Move to Waiting File" command or similar, it works fine if I'm in the same directory as the active file. But if I'm a directory up, then it creates a new file.

In other words, how does todotxt-mode determine the root project for those filenames?

Thanks again!

davraamides commented 2 years ago

Hi @cureau. The extension bases them off the path of the document you are currently editing, that is, the todo.txt file. Here is the code for moving tasks, for example.

let destinationPathName = path.dirname(currDoc.fileName) + path.sep + destinationFileName;

So if your file is "waiting.md" it will just end up in the same directory as "todo.txt". If your file was "../waiting.md" it would end up in the parent folder. If your file was "stuff/waiting.md" it would put it in the "stuff" subdirectory.

Hope that helps.

cureau commented 2 years ago

Hi @davraamides

That makes sense and I can confirm I'm getting the behavior you described.

Given the example file structure below, when I'm in today.txt and I "Move task to Todo file" it creates a new file daily/todo.txt As you pointed out, I can change settings to point to ../todo.txt which would make this action work. However, as soon as I'm back in the project root directory the ../todo.txt setting would point to the parent of the root folder.

todo.txt
waiting.txt
daily/today.txt

I might be unique in trying to use this across nested folders. When I was messing around with settings, I expected setting the filename to todo.txt would work as you described and setting the filename as /todo.txt would work as I described. I.e., relative paths use path.dirname(currDoc.fileName) and absolute ones use the project directory. (E.g., the Foam extension behaves in this way).

That said, I might be the only user trying to use this across nested directories, and I can happily work around it. Feel free to close the issue. Just feedback in case it's useful in the future.

davraamides commented 2 years ago

@cureau, you may be right that using this across nested folders is an edge case and certainly is not the way I use it (I tend to have a separate set of todo.txt and related files in each VS Code workspace).

But I think you've also identified a bug: filenames with a leading slash do not work properly as the path of the current todo file is always prepended. I added this as a new issue: https://github.com/davraamides/todotxt-mode/issues/52