Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
XobSod opened this issue Jul 19, 2022 · 6 comments · Fixed by #1059
Closed

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

XobSod opened this issue Jul 19, 2022 · 6 comments · Fixed by #1059
Labels
enhancement New feature or request foam-vscode Foam for VSCode extension in packages/foam-vscode good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@XobSod
Copy link

XobSod commented Jul 19, 2022

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

@XobSod XobSod changed the title Autocomplete links with notes titles, not filenames FeatReq: Autocomplete links with notes titles, not filenames Jul 19, 2022
@riccardoferretti riccardoferretti added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers foam-vscode Foam for VSCode extension in packages/foam-vscode labels Jul 19, 2022
@riccardoferretti
Copy link
Collaborator

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

@XobSod
Copy link
Author

XobSod commented Jul 20, 2022

@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 XobSod closed this as completed Jul 20, 2022
@XobSod
Copy link
Author

XobSod commented Jul 20, 2022

And I accidentally closed it -.-

@XobSod XobSod reopened this Jul 20, 2022
@riccardoferretti
Copy link
Collaborator

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.

  • You can already achieve the filename customization using Foam Templates
  • I completely agree with the ability to show the title of the note instead of the path
  • I can totally see how the title needs to be used in the link as the label to make the file readable
  • 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

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:

  • path
  • title (useful for Zettelkasten)
  • identifier (useful for repos with a directory structure and non-unique file names)

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:

  • it would make the title searchable
  • it would still show the note paths in the completion list
    Actually this could also easily be implemented via a template that automatically adds the alias property, like:
---
alias: ${FOAM_TITLE}
---

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

@riccardoferretti riccardoferretti added this to the backlog milestone Jul 24, 2022
@XobSod
Copy link
Author

XobSod commented Jul 25, 2022

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:

  • create New note - creates file with filename taken from title
  • create New note from template - as above (I think)
  • open daily note - uses formatter given by used to create filename
  • click on placeholder - filename = placeholder text

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'

  • there must be a way to enforce Foam to always use format when creating new file.
  • show titles in complete window and fill link with filename|Title (same for clicking placeholder)

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

@riccardoferretti
Copy link
Collaborator

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 microsoft/vscode#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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request foam-vscode Foam for VSCode extension in packages/foam-vscode good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants