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

Create multiple files at once #41

Closed
wants to merge 3 commits into from
Closed

Create multiple files at once #41

wants to merge 3 commits into from

Conversation

bscuron
Copy link

@bscuron bscuron commented Jul 5, 2022

[Issue #37] Added ability to create multiple files at once using expansion groups.

Example:
test{.c,.txt,.py} => test.c, test.txt, test.py
test{1,2}_test{3,4}/ => test1_test3/, test1_test4/, test2_test3/
test2_test4/

Multiple expansion groups can be in the same filename.

This still does not allow nested directories to be created however.

Added ability to create multiple files at once using expansion groups.

Example:
test{.c,.txt,.py} => test.c, test.txt, test.py
test{1,2}_test{3,4}/ => test1_test3/, test1_test4/, test2_test3/
test2_test4/

Multiple expansion groups can be in the same filename
Copy link
Owner

@elihunter173 elihunter173 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a big fan of this! expand_path() looks but I think should be moved to buffer.lua and used as a preprocessing step before calling planner.build_changes() in dirbuf.sync(). { and } also now need to be in ESCAPE_CHARS in buffer.lua and additional thought needs to be given to escaping commas inside of {}

This feature also warrants some automated behavior tests in tests/full_spec.lua to test that expansions are handled right and to test some edge cases with escaping

Comment on lines 231 to 240
local fnames = expand_path(fs_entry.fname)
local paths = expand_path(fs_entry.path)

for i=1,#fnames do
table.insert(plan, create({
fname = fnames[i],
ftype = fs_entry.ftype,
path = paths[i]
}))
end
Copy link
Owner

@elihunter173 elihunter173 Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing expansion here, I think it's better to do it as a pre-processing step right before calling planner.build_changes(). That leads to more consistent behavior where the {a,b,c} syntax works both for new lines and old lines (and cleaner code too!)

#1 a{b,c}
z{x,y}

expands to

#1 ab
#1 ac
zx
zy

(This does break the current line number tracking but that shouldn't be too hard to fix)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing expansion here, I think it's better to do it as a pre-processing step right before calling planner.build_changes(). That leads to more consistent behavior where the {a,b,c} syntax works both for new lines and old lines (and cleaner code too!)

#1 a{b,c}
z{x,y}

expands to

#1 ab
#1 ac
zx
zy

(This does break the current line number tracking but that shouldn't be too hard to fix)

I also did not run into the line numbering breaking from my testing so far.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I should have been more clear. When I said line number tracking I was thinking about dirbuf.nvim's error messages.

So once you expand a line, all future error messages will be offset by however many more lines that line expanded to. For example this example will report a line 4: Duplicate name 'foo' even tho the duplicate actually occurs on line 3.

foo
a{b,c}
foo

@bscuron
Copy link
Author

bscuron commented Jul 16, 2022

I'm a big fan of this! expand_path() looks but I think should be moved to buffer.lua and used as a preprocessing step before calling planner.build_changes() in dirbuf.sync(). { and } also now need to be in ESCAPE_CHARS in buffer.lua and additional thought needs to be given to escaping commas inside of {}

This feature also warrants some automated behavior tests in tests/full_spec.lua to test that expansions are handled right and to test some edge cases with escaping

I looked into adding '{' and '}' to ESCAPE_CHARS, but I am a little unsure of how to do it correctly. Everything else I think I resolved in this commit. I appreciate the feedback!

@elihunter173
Copy link
Owner

I looked into adding '{' and '}' to ESCAPE_CHARS, but I am a little unsure of how to do it correctly

Ah I just tried myself and saw an error you might have seen. (I used local ESCAPE_CHARS = { n = "\n", t = "\t", ["{"] = "{", ["}"] = "}" }.)

I just realized the current implementation doesn't work with escaping the braces (or nesting braces) and I think a proper implementation of that starts to get gross. Please feel free to work towards making that work; I think automated tests for nested brackets and escaped brackets will help a lot. Feel free to ping me if you want help writing tests. See tests/full_spec.lua for inspiration.

I'll also try some experiments of my own when I have the time and report back to you

@bscuron bscuron closed this by deleting the head repository Jun 13, 2023
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

Successfully merging this pull request may close these issues.

2 participants