foambubble / foam

A personal knowledge management and sharing system for VSCode
https://foambubble.github.io/
Other
15.26k stars 649 forks source link

FeatReq: Autocomplete links with notes titles, not filenames #1038

Closed XobSod closed 2 years ago

XobSod commented 2 years ago

Is your feature request related to a problem? Please describe.

When autocompleting link opened with [[: Current behavior: Foam shows proposition list, where you can find filenames of available documents with additional preview of the content. When position is picked, Foam fills [[]] link with shortest possible file identifier like [[file1]] for file1.md.

Expected behavior: Foam shows proposition list, where you can find titles of available documents, with additional preview that may (not must) have a path to the document. When position is picked, Foam fills [[]] link with file identifier aliased with file title like [[file1|The title found in the file]] for file1.md.

Motivation: When trying to use Foam to build so called Second Brain using Zettelkasten method I can see this problem. The metod says that each file/note should have unique identifier/filename that should be not mutable after note creation. The easiest approach to achieve this is to use for example timestamp as a filename. But this brings us to the problem described above, when you have several files named like:

20210511022607.md
20210512085325.md
20210515161743.md
20210511124221.md
20210521150143.md

and you try to create a link to another note, the only thing you see is this list of numbers. When you want to find particular note you have to check previews. It would be very helpful instead of seeing this list of filenames, to see list of note titles extracted by for example regex ^# .*$ and presented like this:

Title1 - 20210511022607.md
Some long title - 20210512085325.md
Other title - 20210515161743.md
Another title - 20210511124221.md
Title over 9000 - 20210521150143.md

Filenames may or may not be presented on the list (it may be a part of preview), but most important, the title of the note should be searchable. And after picking the note Foam should fill the link with the filename aliased with the title like this: [[20210512085325|Some long title]].

This new approach also should link with some refactoring. When changing title of the note, all references (aliases in links) should also change (option for that). In this approach the note filename is constant so we don't have to be concerned about filename, link change.

Update: Also, there there should be a setting that enforce new file filename to particular format, so no matter which way the file is created (daily note, placeholder click) the filename should always be the same.

Describe the solution you'd like

Mostly described in the main description.

How would I do this? Add three settings: Link autocompletion method <drop-box>: (filename|note title) Note title regex <string>: default(^# .*$) Change alias on note title change <bool> New file name format <string>: - something like Daily Note file format (update)

And fill autocompletion box with appropriate content.

Describe alternatives you've considered

The idea is coming from Zettelkaster method: 1) I have checked how Obsidian is doing it. Obsidian has a json database, when it connects physical filename, note title and generated uuid as one entity, and fills links with note title. Having this DB application knows how to react to the changes. I think this is one of the best solutions to this problem, but it may be an overkill for what I would want to achieve. 2) the main problem on achieving this is to somehow ensure filenames uniqueness also keeping the autocomplete list readable. It can be also done by naming the file as a sum of NoteTitle and timestamp like Another_title-20210511124221.md. In the list one can see some descriptive text, but link created from this is simply [[Another_title-20210511124221.md]] that have to be manually changed to [[Another_title-20210511124221.md|Another title]], and also there is no synchronization when the note changes title. In that case one must rename the file, and manually follow all references to change the alias (or most probably use sed for this).

Screenshots or Videos

No response

riccardoferretti commented 2 years ago

Thanks for reporting this @XobSod, I think it's a great idea

XobSod commented 2 years ago

@riccardoferretti thank you ;) I have updated the description with filename format requirement, as it is needed here.

I would code this myself, but unfortunately I am not TS developer I am finding it hard to understand what is happening there and where to start :D

XobSod commented 2 years ago

And I accidentally closed it -.-

riccardoferretti commented 2 years ago

There are several elements to this issue, that I believe have different level of both complexity and usage. I see this as a way to help people using Zettelkasten to do it with Foam.

Regarding the solution, I am trying to keep Foam at simple as possible, so I would rather not fill it with lots of specific options. I am thinking of having one property with the style of the autocompletion item:

Another option would be to treat titles as aliases, which would accomplish everything you are asking for (except the refactoring support), which show up in the list of autocompletion items, and are automatically used as label in the link ([[note|alias]]). In this case a simple property Use title as note alias would be enough:

---
alias: ${FOAM_TITLE}
---

So, still figuring out what the best approach is, would love to hear comments, especially from people using Zettelkasten

XobSod commented 2 years ago

Thank you for starting serious work on it ;)

You can already achieve the filename customization using Foam Templates

Unfortunately I cannot agree with that (or maybe I don't know how to achieve this). Foam may create new file on various ways:

Currently I am hardcoding my way through the extension code to use "Daily note format" in every place where the note can be created (I am reusing openDailyNote.filenameFormat with seconds resolution added to format string). image

This is great way to just have time stamps as filenames every time VSCode creates a file, and in my opinion there should be some kind option to enforce that ;)

I am not sure refactoring should apply to titles (note, it already applies to file name), it seems very prone to Foam overstepping and getting in the user's way

Yes, that might be an overkill ;) having previous functionalities is enough.

I have changed some lines in link-completion.ts to check how it will work image

and I think this is very acceptable: image

and after selecting text: image

But unfortunately I am not heavy ZK method user (I just wanted to start to learn, so I am looking for tool for it :D ) so I cannot tell how this fits into purists way of having it.

To sum up my 'hardcodings'

Those two are all it is needed to have ZK work with Foam (in my opinion).

riccardoferretti commented 2 years ago

The reason why that is not possible atm is because VS Code variables cannot be expanded outside of a document, otherwise in Foam we want to allow snippet variables to be used also in the filename property (you can do that for the FOAM_* variables, not for the native VS Code variables).

You can upvote https://github.com/microsoft/vscode/issues/155868 to push for this change

Once that is achieved in the best case you should just need the new-note.md template to achieve what you want (I reckon), and possibly also the daily-note.md template if you want to apply the same idea to daily notes (which I wouldn't, but then again I am not into ZK). To your comment:

create New note - creates file with filename taken from title

uses new-note.md template

create New note from template - as above (I think)

select new-note.md template

open daily note - uses formatter given by used to create filename

uses daily-note.md template

click on placeholder - filename = placeholder text

uses new-note.md template with FOAM_TITLE pre-populated with the text of the placeholder

Thanks for your diffs, I am working on something along those lines :)