rgroli/other.nvim

Templating behaviour, similar to vim-projectionist?

Closed this issue · 4 comments

First off, fantastic plugin!

This should fit the bill for the issues I'm having with vim-projectionist and irregular folder patterns between like/other-files.

I was wondering if you had considered introducing the templating features of vim-projectionist?

Or a way to hook into https://github.com/glepnir/template.nvim

Which might just work automatically, actually.

Could you describe how would you like to use it with the plugin?
I image you would like the file being created from the filepicker, if non-existent, right?

dnsbty commented

This is the main thing preventing me from using other over vim-projectionist. Ideally any of the other files that don't exist would show as an option in the file picker with some way to show that they don't yet exist, and selecting them would create the new file with the specified template. Like @megalithic mentioned, hooking into template.nvim would be a great way to make that happen and keep the scope of this plugin smaller.

So as an example with Rails, if I'm in the UserController, I could pull up other's filepicker, see that no test file exists yet, and select the test file. Other would then create the test file and fill out the boilerplate for the test.

rgroli commented

The plugin now supports creating non exsting files. I also created a hook to add more control of what happens when the file is opened. So what should be possible now is something like:

require("other-nvim").setup({
    [...]

    hooks = {
	
		-- This hook is called whenever a file is about to be opened.
		onOpenFile = function(filename, exists)
			if (not exists) then
                             -- custom logik to open the file with a different plugin.
                             -- for example to use  https://github.com/glepnir/template.nvim
                             
                             -- when the file should not be opened by the plugin itself return false
                             return false
                        end
		end,
	},
	
   [...]
}

Instead of using another plugin, you could also take a look at (neo)vim standard skeletons. :h skeleton
Plus there are also plugins taking advantage of this like https://github.com/motosir/skel-nvim