aboutsummaryrefslogtreecommitdiff
path: root/runtime/plugin/net.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2026-03-23 06:41:00 -0400
committerGitHub <noreply@github.com>2026-03-23 06:41:00 -0400
commit59eadebe335f54f8cdd6cefe25d9fa00daf01371 (patch)
treef17d1ef14211a5aad899cae4192e0461a25204ad /runtime/plugin/net.lua
parent0a60f32af3c02d538ceae4a6e40e5e0b1faa75cb (diff)
downloadrneovim-59eadebe335f54f8cdd6cefe25d9fa00daf01371.tar.gz
rneovim-59eadebe335f54f8cdd6cefe25d9fa00daf01371.tar.bz2
rneovim-59eadebe335f54f8cdd6cefe25d9fa00daf01371.zip
fix(runtime)!: move "tohtml" to pack/dist/opt/ #34557
Problem: The "tohtml" plugin is loaded by default. Solution: - Move it to `pack/dist/opt/nvim.tohtml/`, it is an "opt-in" plugin now. - Document guidelines. - Also revert the `plugin/` locations of `spellfile.lua` and `net.lua`. That idea was not worth the trouble, it will be too much re-education for too little gain.
Diffstat (limited to 'runtime/plugin/net.lua')
-rw-r--r--runtime/plugin/net.lua45
1 files changed, 45 insertions, 0 deletions
diff --git a/runtime/plugin/net.lua b/runtime/plugin/net.lua
new file mode 100644
index 0000000000..e23c55a115
--- /dev/null
+++ b/runtime/plugin/net.lua
@@ -0,0 +1,45 @@
+vim.g.loaded_remote_file_loader = true
+
+--- Callback for BufReadCmd on remote URLs.
+--- @param ev { buf: integer }
+local function on_remote_read(ev)
+ if vim.fn.executable('curl') ~= 1 then
+ vim.api.nvim_echo({
+ { 'Warning: `curl` not found; remote URL loading disabled.', 'WarningMsg' },
+ }, true, {})
+ return true
+ end
+
+ local bufnr = ev.buf
+ local url = vim.api.nvim_buf_get_name(bufnr)
+ local view = vim.fn.winsaveview()
+
+ vim.api.nvim_echo({ { 'Fetching ' .. url .. ' …', 'MoreMsg' } }, true, {})
+
+ vim.net.request(
+ url,
+ { retry = 3 },
+ vim.schedule_wrap(function(err, content)
+ if err then
+ vim.notify('Failed to fetch ' .. url .. ': ' .. tostring(err), vim.log.levels.ERROR)
+ vim.fn.winrestview(view)
+ return
+ end
+
+ local lines = vim.split(content.body, '\n', { plain = true })
+ vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, lines)
+ vim.api.nvim_exec_autocmds('BufRead', { group = 'filetypedetect', buffer = bufnr })
+ vim.bo[bufnr].modified = false
+
+ vim.fn.winrestview(view)
+ vim.api.nvim_echo({ { 'Loaded ' .. url, 'Normal' } }, true, {})
+ end)
+ )
+end
+
+vim.api.nvim_create_autocmd('BufReadCmd', {
+ group = vim.api.nvim_create_augroup('nvim.net.remotefile', {}),
+ pattern = { 'http://*', 'https://*' },
+ desc = 'Edit remote files (:edit https://example.com)',
+ callback = on_remote_read,
+})