Skip to content

Commit

Permalink
fix(api): vim.filetype.get_option()
Browse files Browse the repository at this point in the history
- Fix a bug in the cache
- Set some buffer options on the dummy buffer
  • Loading branch information
lewis6991 committed Mar 22, 2023
1 parent 3285cd6 commit 3ae94a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion runtime/lua/vim/filetype/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ local api = vim.api
local M = {}

local function get_ftplugin_runtime(filetype)
return api.nvim__get_runtime({
local files = api.nvim__get_runtime({
string.format('ftplugin/%s.vim', filetype),
string.format('ftplugin/%s_*.vim', filetype),
string.format('ftplugin/%s/*.vim', filetype),
string.format('ftplugin/%s.lua', filetype),
string.format('ftplugin/%s_*.lua', filetype),
string.format('ftplugin/%s/*.lua', filetype),
}, true, {}) --[[@as string[] ]]

local r = {} ---@type string[]
for _, f in ipairs(files) do
if not vim.startswith(f, vim.env.VIMRUNTIME) then
r[#r + 1] = f
end
end
return r
end

-- Keep track of ftplugin files
Expand Down
4 changes: 4 additions & 0 deletions src/nvim/api/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ static buf_T *do_ft_buf(char *filetype, aco_save_T *aco, Error *err)

// Allocate a buffer without putting it in the buffer list.
buf_T *ftbuf = buflist_new(NULL, NULL, 1, BLN_DUMMY);
set_option_value("bufhidden", 0L, "hide", OPT_LOCAL);
set_option_value("buftype", 0L, "nofile", OPT_LOCAL);
set_option_value("swapfile", 0L, NULL, OPT_LOCAL);
set_option_value("modeline", 0L, NULL, OPT_LOCAL); // 'nomodeline'
if (ftbuf == NULL) {
api_set_error(err, kErrorTypeException, "Could not create internal buffer");
return NULL;
Expand Down

0 comments on commit 3ae94a9

Please sign in to comment.