-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
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
There was a problem hiding this 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
lua/dirbuf/planner.lua
Outdated
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 |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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! |
Ah I just tried myself and saw an error you might have seen. (I used 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 I'll also try some experiments of my own when I have the time and report back to you |
[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.