LintaoAmons / scratch.nvim

Create temporary playground files effortlessly. Find them later without worrying about filenames or locations.
Other
225 stars 9 forks source link

Help - Callback after scratch file created? #34

Open Ajaymamtora opened 4 months ago

Ajaymamtora commented 4 months ago

I'm looking to create a scratch file in the middle of a shortcut that sets up a REPL. Is there any way for me to run code once the filetype has been selected from the new scratchfile select?

Rizhiy commented 3 months ago

The way I've done it is just to have an autocommand which is run for files in my scratch directory:

vim.api.nvim_create_autocmd({ "BufEnter" }, {
    pattern = vim.fn.stdpath("cache") .. "/scratch.nvim/*",
    command = "Codi", -- You can also execute a lua function using `callback` key
})
Ajaymamtora commented 3 months ago

Thanks, I don't always want to setup a REPL with every scratch file, not sure how I could leverage that to conditionally do a callback?

Rizhiy commented 3 months ago

You can prompt for confirmation inside the lua function? Or write a function which first creates a scratchpad using this plugin and then sets up whatever is required.

Ajaymamtora commented 3 months ago

Then the prompt would fire every time I create a scratch file right? I don't really want that. Also the 2nd thing is what I'm trying to do, I don't know how to create a scratch file after the plugin has created a file because calling the API pops up the telescope picker.

I've created a fork of this repo instead it seems to work ok