neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 69b286c3bfb386597af9fc66625fdb6934594544
parent e0308dc14730052032f2b172c6d8b7abe398c755
Author: Michele Sorcinelli <michelesr@users.noreply.github.com>
Date:   Thu, 20 Nov 2025 06:04:59 +0000

fix(vim.net): filetype detection, mark unmodified #36297

Problem:
When running ":edit <url>", filetype detection is not triggered.

Solution:
Run the autocmds in the filetypedetect group after loading the content.

Problem:
After fetching remote content from a URL and adding it to the buffer,
the buffer is marked as modified. This is inconsistent with the original
netrw behavior, and it causes problems with `:e` to refresh or `:q` as
it prompts for saving the file even if the user hasn't touched the
content at all.

Solution:
Mark the buffer as unmodified right after adding the remote content to
the buffer.
Diffstat:
Mruntime/plugin/nvim/net.lua | 2++
Mtest/functional/lua/net_spec.lua | 31+++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/runtime/plugin/nvim/net.lua b/runtime/plugin/nvim/net.lua @@ -28,6 +28,8 @@ local function on_remote_read(args) 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, {}) diff --git a/test/functional/lua/net_spec.lua b/test/functional/lua/net_spec.lua @@ -39,6 +39,37 @@ describe('vim.net.request', function() ) end) + it('detects filetype for remote content', function() + t.skip(skip_integ, 'NVIM_TEST_INTEG not set: skipping network integration test') + + local ft = exec_lua([[ + vim.cmd('runtime! plugin/nvim/net.lua') + vim.cmd('runtime! filetype.lua') + -- github raw dump of a small lua file in the neovim repo + vim.cmd('edit https://raw.githubusercontent.com/neovim/neovim/master/runtime/syntax/tutor.lua') + vim.wait(2000, function() return vim.bo.filetype ~= '' end) + return vim.bo.filetype + ]]) + + assert(ft == 'lua', 'Expected filetype to be "lua", got: ' .. tostring(ft)) + end) + + it('removes the modified flag from the buffer for remote content', function() + t.skip(skip_integ, 'NVIM_TEST_INTEG not set: skipping network integration test') + + local buffer_modified = exec_lua([[ + vim.cmd('runtime! plugin/nvim/net.lua') + vim.cmd('runtime! filetype.lua') + vim.cmd('edit https://raw.githubusercontent.com/neovim/neovim/master/runtime/syntax/tutor.lua') + -- wait for buffer to have content + vim.wait(2000, function() return vim.fn.wordcount().bytes > 0 end) + vim.wait(2000, function() return vim.bo.modified == false end) + return vim.bo.modified + ]]) + + assert(not buffer_modified, 'Expected buffer to be unmodified for remote content') + end) + it('calls on_response with error on 404 (async failure)', function() t.skip(skip_integ, 'NVIM_TEST_INTEG not set: skipping network integration test') local err = exec_lua([[