Foam: Create new note from template improvements

Created on 19 Nov 2020  路  15Comments  路  Source: foambubble/foam

  • [ ] When there are no templates, we should show an appropriate message in (or in place of) the quick pick
  • [ ] Simplify the steps by merging directory and file name questions into one ("Enter note path"), include a pre-filled value with the current directory (as it is now) and the filename "new-note.md" and pre-highlight "new-note"
  • [ ] pressing ESC at any step should stop the flow of input boxes

from comments in #346 :

  • [ ] Setting a daily note template to be the ID of one of the templates
  • [ ] A "create new template" command that can also be presented when no templates exist!
foam-vscode

Most helpful comment

@ingalless I see what you mean, I personally don't see an issue with having and "Insert from template" command.

The main reasons are:

  • source of truth (the ./foam/templates/ dir, instead of snippets, which IMO is a bit nicer)
  • if someone prefers snippets, they can still use them
  • because you are using snippets expansion in your templates, any enhancement to snippets is directly available to templates (so that's good :) )
  • maybe in the future access to foam specific variables (which we couldn't do with vscode snippets)

A possible drawback I see is for the templates/ directory to become a kitchen sink, but then again who am I to judge.. if someone prefers it that way, we are not taking options away from them.

TLDR;
I am open to it, I don't feel strongly about it, and happy to have a conversation on the topic if people disagree

All 15 comments

Also, we should add documentation :) (also mentioned in #355)

This all looks great @riccardoferretti. I'd also add some tests would be good to have

I'm happy to look at this next week?

sound good @ingalless!

Marsop in discord suggested:

  • "Use the name of the file as one of the variables"

This should probably kick off a broader discussion of what "dynamic" variables we should support.

"date (_or datetime_) of creation" would be a good candidate for dynamic variable (similar as how "daily" notes receive a name based on when they have been created.

@marsop it would be worth checking if the above is available in the list of snippet variables:

https://code.visualstudio.com/docs/editor/userdefinedsnippets#_variables

Tested and working!

Example template:

# ${TM_FILENAME_BASE}

- Date: ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}

when creating file with name "test5.md" generates..

# test5

- Date: 2020-11-20

Would be amazing to have also a command like "Insert from template" to insert at the cursor's position in your current document the content stored in a template.

This, plus what you are discussing about variables, I think would be a very useful feature. What do you think?

@danielarmengolaltayo we could do something like that, sure

But then I wonder: are we straying back into the functionality of snippets (which has the benefit of Microsoft maintaining it)?

@riccardoferretti any thoughts?

@ingalless I see what you mean, I personally don't see an issue with having and "Insert from template" command.

The main reasons are:

  • source of truth (the ./foam/templates/ dir, instead of snippets, which IMO is a bit nicer)
  • if someone prefers snippets, they can still use them
  • because you are using snippets expansion in your templates, any enhancement to snippets is directly available to templates (so that's good :) )
  • maybe in the future access to foam specific variables (which we couldn't do with vscode snippets)

A possible drawback I see is for the templates/ directory to become a kitchen sink, but then again who am I to judge.. if someone prefers it that way, we are not taking options away from them.

TLDR;
I am open to it, I don't feel strongly about it, and happy to have a conversation on the topic if people disagree

@ingalless I agree with you about how templates are overlapping with snippets' functionality. Never created a snippet before and now I see how it's barely the same.

My proposal was made before playing around with snippets a bit and it was made as a reaction to the new template's feature. I was just imagining a use case out from what the nature of the feature suggested to me.

I also agree with @riccardoferretti regarding the source of truth point, but I don't know if it is worth the cost of developing and maintaining a template's feature (not just insert but also create new note), understanding that the same is completely achievable through snippets.

The only reason that comes into my mind at the moment, to append to @riccardoferretti 's list is about UX. For non-tech savvy users, templates seems a better way to go IMO, if you are not thinking of variables for now, just plain text.

Ok, more thoughts about this.

I have the file containing the snippets' configuration inside the .vscode folder inside my foam project. For me, this is equivalent to .foam/templates and a file per template, regarding the source of truth point.

I can open the snippets' file easily and fast through "search by files name" (cmd+P in mac) and typing "templates" (if I name the snippets' file something like "templates.code-snippets"), which is the same experience as retrieving a template file.

In conclusion, if there are no more functionalities in mind for templates, IMO we can have the same results with proper documentation explaining how to create your templates using snippets. What do you think @ingalless @riccardoferretti ?

@danielarmengolaltayo I agree on @riccardoferretti's point that it doesn't hurt for us to add a "insert at cursor" command. You're right, the "templates" mindset works better for non-technical users than snippets do (they're a bit awkward to work with). It's good we support non-technical users as it's part of Foam's core values.

@ingalless And also, sometimes it is nice to have multiple ways to achieve the same result so that each person can decide what works best for him/her. My last concern was more about the effort required to "replicate" and maintain a functionality like this, but if you feel like it doesn't hurt, I don't see why not ;)

I think it's a nice to have, and I agree that as a first quick iteration documenting the "workaround" can be just as good.
I am happy to defer to @ingalless to make the call as to whether to add it now or later based on his cost/benefit analysis.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fmagin picture fmagin  路  7Comments

srid picture srid  路  3Comments

ituri picture ituri  路  3Comments

amorriscode picture amorriscode  路  6Comments

Josh2K picture Josh2K  路  3Comments