Skip to content

Commit

Permalink
fix: replace get_filetype with vim.filetype.match (#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathf committed Jul 7, 2023
1 parent a993b35 commit 4e6dbb1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 30 deletions.
16 changes: 0 additions & 16 deletions lua/neorg/external/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,6 @@ neorg.utils = {
return ret
end,
get_filetype = function(file, force_filetype)
local filetype = force_filetype
-- Getting a filetype properly is... difficult
-- This is why we leverage Neovim instead.
-- We create a dummy buffer with the filepath the user wanted to export to
-- and query the filetype from there.
if not filetype then
local dummy_buffer = vim.uri_to_bufnr(vim.uri_from_fname(file))
vim.fn.bufload(dummy_buffer)
filetype = vim.api.nvim_buf_get_option(dummy_buffer, "filetype")
vim.api.nvim_buf_delete(dummy_buffer, { force = true })
end
return filetype
end,
--- Custom neorg notifications. Wrapper around vim.notify
---@param msg string message to send
Expand Down
4 changes: 2 additions & 2 deletions lua/neorg/modules/core/export/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.config.public = {
module.public = {
--- Returns a module that can handle conversion from `.norg` to the target filetype
---@param ftype string #The filetype to export to (as returned by e.g. `get_filetype()`)
---@param ftype string #The filetype to export to
---@return table?,table? #The export module and its configuration, else nil
get_converter = function(ftype)
if not neorg.modules.is_module_loaded("core.export." .. ftype) then
Expand Down Expand Up @@ -219,7 +219,7 @@ module.on_event = function(event)
-- Example: Neorg export to-file my-custom-file markdown
local filepath = vim.fn.expand(event.content[1])
local filetype = neorg.utils.get_filetype(filepath, event.content[2])
local filetype = event.content[2] or vim.filetype.match({ filename = filepath })
local exported = module.public.export(event.buffer, filetype)
vim.loop.fs_open(filepath, "w", 438, function(err, fd)
Expand Down
4 changes: 2 additions & 2 deletions lua/neorg/modules/core/tangle/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ module.public = {
if type(parsed_document_metadata.tangle) == "table" then
if vim.tbl_islist(parsed_document_metadata.tangle) then
for _, file in ipairs(parsed_document_metadata.tangle) do
options.languages[neorg.utils.get_filetype(file)] = file
options.languages[vim.filetype.match({ filename = file })] = file
end
elseif parsed_document_metadata.tangle.languages then
for language, file in pairs(parsed_document_metadata.tangle.languages) do
options.languages[language] = file
end
end
elseif type(parsed_document_metadata.tangle) == "string" then
options.languages[neorg.utils.get_filetype(parsed_document_metadata.tangle)] =
options.languages[vim.filetype.match({ filename = parsed_document_metadata.tangle })] =
parsed_document_metadata.tangle
end
Expand Down
3 changes: 2 additions & 1 deletion lua/neorg/modules/core/ui/calendar/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ module.private = {
local buffer, window = module.required["core.ui"].create_split(
"calendar-" .. tostring(os.clock()):gsub("%.", "-"),
{}, options.height or MIN_HEIGHT + (options.padding or 0)
{},
options.height or MIN_HEIGHT + (options.padding or 0)
)
vim.api.nvim_create_autocmd({ "WinClosed", "BufDelete" }, {
Expand Down
24 changes: 15 additions & 9 deletions lua/neorg/modules/core/ui/calendar/views/monthly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,21 @@ module.private = {
}, "center"),

-- Help text at the bottom left of the screen
help_and_custom_input = module.private.set_decorational_extmark(ui_info, ui_info.height - 1, 0, 0, {
{ "?", "@character" },
{ " - " },
{ "help", "@text.strong" },
{ " " },
{ "i", "@character" },
{ " - " },
{ "custom input", "@text.strong" },
}),
help_and_custom_input = module.private.set_decorational_extmark(
ui_info,
ui_info.height - 1,
0,
0,
{
{ "?", "@character" },
{ " - " },
{ "help", "@text.strong" },
{ " " },
{ "i", "@character" },
{ " - " },
{ "custom input", "@text.strong" },
}
),

-- The current view (bottom right of the screen)
current_view = module.private.set_decorational_extmark(
Expand Down

0 comments on commit 4e6dbb1

Please sign in to comment.