Closed zachary-foster closed 7 months ago
1) Use the first found and stop searching parent directories. 2) Keep a list of config files found and apply them in reverse order, each potentially overwriting the settings of previous one.
I think the first option is the most intuitive.
Ideally the .img-clip.lua
search is done at runtime (when a specific option is requested), so that if the user changes the current working directory or file to be edited it uses the correct config file. However, if the operation of finding the file is costly, this will be done once at init time instead. I'll look into it.
The .img-clip.lua
file will likely have the following format, resembling the opts
table in lazy:
return {
default = {
-- opts here...
},
filetypes = {
-- opts here...
},
-- ...
}
Checking parent directories of the currently edited file for a config file with a defined name like
.img-clip.lua
. There could be a limit on the number of directories searched for performance reasons; perhaps 10 would be a safe default.
Vim has a nice function for this: findfile()
- it can be used in lua with vim.fn.findfile
. See :help finddir
and :help file-searching
for a good specification of how to use this.
Vim has a nice function for this: findfile() - it can be used in lua with vim.fn.findfile. See :help finddir and :help file-searching for a good specification of how to use this.
Thank you. Exactly what I need.
Edit: Seems like this is very fast. No surprise, it's just looking at n number of static paths until it's at the root directory. I think this can be done at runtime, with no caching mechanism. I'll implement this after #30 is merged.
@zachary-foster Is PR #34 working as intended for you?
The
template
,dir_path
, and other options provide a lot of flexibility to customize the pasting of images to fit the needs of a particular project, but defining these options globally makeimg-clip
less useful for multiple projects with mutually exclusive needs on the same system.Although #30, if merged, will address this issue, it would also be useful to be able to define the configuration of
img-clip
in project source directories so that the configuration for the project can be committed to the source code for that project. This could work by:.img-clip.lua
. There could be a limit on the number of directories searched for performance reasons; perhaps 10 would be a safe default.