From 6b88eb112fc28cf1dcb909e2930de97bbdefb0b0 Mon Sep 17 00:00:00 2001 From: Antoine Saez Dumas Date: Wed, 21 Jan 2026 20:49:45 +0100 Subject: [PATCH 1/4] refactor(handlers): use vim.system instead of vim.fn.system when possible --- lua/notmuch/handlers.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lua/notmuch/handlers.lua b/lua/notmuch/handlers.lua index 67346a2..410dc50 100644 --- a/lua/notmuch/handlers.lua +++ b/lua/notmuch/handlers.lua @@ -35,13 +35,18 @@ H.default_view_handler = function(attachment) -- Check if the tool exists if vim.fn.executable(cmd.tool) == 1 then local output - if type(cmd.command(path)) == 'table' then - output = vim.fn.system(cmd.command(path)) + local success + local command = cmd.command(path) + if type(command) == 'table' then + local obj = vim.system(command):wait() + output = obj.stdout + success = obj.stderr else - output = vim.fn.system(cmd.command(path)) + output = vim.fn.system(command) + success = (vim.v.shell_error == 0) end - if vim.v.shell_error == 0 then + if success then return output end end From 6f9c59279ff989eebedebd0a3a0b76470af2adba Mon Sep 17 00:00:00 2001 From: Antoine Saez Dumas Date: Wed, 21 Jan 2026 20:50:02 +0100 Subject: [PATCH 2/4] perf(handlers): anchor patterns where possible --- lua/notmuch/handlers.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/notmuch/handlers.lua b/lua/notmuch/handlers.lua index 410dc50..e542218 100644 --- a/lua/notmuch/handlers.lua +++ b/lua/notmuch/handlers.lua @@ -59,7 +59,7 @@ H.default_view_handler = function(attachment) local ext = path:match('%.([^%.]+)$') or '' -- HTML files (most common) - if filetype:match('text/html') or ext:match('^html?$') then + if filetype:match('^text/html$') or ext:match('^html?$') then return try_commands({ { tool = 'w3m', command = function(p) return { 'w3m', '-T', 'text/html', '-dump', p } end }, { tool = 'lynx', command = function(p) return { 'lynx', '-dump', '-nolist', p } end }, @@ -68,7 +68,7 @@ H.default_view_handler = function(attachment) end -- PDF files - if filetype:match('application/pdf') or ext == 'pdf' then + if filetype:match('^application/pdf$') or ext == 'pdf' then return try_commands({ { tool = 'pdftotext', command = function(p) return { 'pdftotext', '-layout', p, '-' } end }, { tool = 'mutool', command = function(p) return { 'mutool', 'draw', '-F', 'txt', p } end }, @@ -95,7 +95,7 @@ H.default_view_handler = function(attachment) end -- Markdown - if filetype:match('text/markdown') or ext:match('^md$') then + if filetype:match('^text/markdown$') or ext:match('^md$') then return try_commands({ { tool = 'pandoc', command = function(p) return { 'pandoc', '-t', 'plain', p } end }, { tool = 'mdcat', command = function(p) return { 'mdcat', p } end }, From 13267b45515075e526aacd0c5cae2fc82467d5ed Mon Sep 17 00:00:00 2001 From: Antoine Saez Dumas Date: Sat, 7 Feb 2026 11:03:09 +0100 Subject: [PATCH 3/4] fix(handlers): use exit code to determine command success --- lua/notmuch/handlers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/notmuch/handlers.lua b/lua/notmuch/handlers.lua index e542218..7b841c4 100644 --- a/lua/notmuch/handlers.lua +++ b/lua/notmuch/handlers.lua @@ -40,7 +40,7 @@ H.default_view_handler = function(attachment) if type(command) == 'table' then local obj = vim.system(command):wait() output = obj.stdout - success = obj.stderr + success = (obj.code == 0) else output = vim.fn.system(command) success = (vim.v.shell_error == 0) From 8143bb6866ed0f4672746bfb222de4b05e421e54 Mon Sep 17 00:00:00 2001 From: Antoine Saez Dumas Date: Sat, 7 Feb 2026 11:05:00 +0100 Subject: [PATCH 4/4] style(handlers): use tabs instead of spaces --- lua/notmuch/handlers.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lua/notmuch/handlers.lua b/lua/notmuch/handlers.lua index 7b841c4..b960c82 100644 --- a/lua/notmuch/handlers.lua +++ b/lua/notmuch/handlers.lua @@ -35,15 +35,15 @@ H.default_view_handler = function(attachment) -- Check if the tool exists if vim.fn.executable(cmd.tool) == 1 then local output - local success - local command = cmd.command(path) + local success + local command = cmd.command(path) if type(command) == 'table' then - local obj = vim.system(command):wait() - output = obj.stdout - success = (obj.code == 0) + local obj = vim.system(command):wait() + output = obj.stdout + success = (obj.code == 0) else output = vim.fn.system(command) - success = (vim.v.shell_error == 0) + success = (vim.v.shell_error == 0) end if success then