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

Optional Template for New File - Feature Request #360

Open
NicholasLinderWood opened this issue Nov 29, 2024 · 1 comment
Open

Optional Template for New File - Feature Request #360

NicholasLinderWood opened this issue Nov 29, 2024 · 1 comment

Comments

@NicholasLinderWood
Copy link

hello hello! Thank you for creating babi as well as for all of your other educational material! I've been using babi and was wondering about a possible new feature which would (optionally) populate the editor with template text when creating a new file. After looking through the source code, here is one idea I've come up with for how this might be implemented.

  1. Add an optional command line argument indicating whether to use a template (and if so which. only applicable if no filename is given or if the given filename doesn't exist)
  2. Pass that argument along to the File.ensure_loaded method.
  3. In the case where the passed filename does not exist or filename is None, instead of passing the empty string to get_lines, call a function which returns a string to pass in based on that command line argument (and perhaps other info).
  4. Create babi/resources/templates.py which will:
    a. Store various text templates
    b. Contain the function referenced in 3.

If we think there would reasonably be only one template per file extension, then I'd lean toward making the command line argument a flag and then parse the filename to determine which flag to use. Then we could have something like babi t.py --template yielding

image

If not, then I think the command line argument would need to indicate which template to use.

I'd be very interested in hearing your thoughts. Thanks for your time and consideration!

@asottile
Copy link
Owner

asottile commented Dec 1, 2024

I don't think a command line argument is a good idea as it's really only usable outside the editor (and only on empty files). I was thinking more of a <esc> command like :m macroname and a way for the user to have snippets in ~/.config/babi/snippets/... or something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants