From 1e737eee47a5c6a413c1996cd3737ca1e67dfc86 Mon Sep 17 00:00:00 2001 From: Simon H Moore Date: Sun, 16 Mar 2025 19:36:51 +0000 Subject: [PATCH 1/4] feat(attachment): add in-buffer attachment viewer Previously, attachments could only be opened externally using `xdg-open`. This update adds an option to view attachments directly in a Neovim buffer, allowing users to preview text-based attachments without leaving Neovim. Attachments like plain text, markdown, and PDFs (if converted) can now be displayed in a buffer --- ftplugin/notmuch-attach.vim | 1 + lua/notmuch/attach.lua | 34 +++++++++++++++++++++++++++++++++- lua/notmuch/config.lua | 3 +++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/ftplugin/notmuch-attach.vim b/ftplugin/notmuch-attach.vim index 7bf5aef..612c8de 100644 --- a/ftplugin/notmuch-attach.vim +++ b/ftplugin/notmuch-attach.vim @@ -1,4 +1,5 @@ let attach = v:lua.require('notmuch.attach') nmap q :bwipeout nmap s :call attach.save_attachment_part() +nmap o :call attach.open_attachment_part() nmap v :call attach.view_attachment_part() diff --git a/lua/notmuch/attach.lua b/lua/notmuch/attach.lua index c369faf..3cb29c1 100644 --- a/lua/notmuch/attach.lua +++ b/lua/notmuch/attach.lua @@ -16,11 +16,43 @@ local function show_github_patch(link) end -- TODO generalize this: // Date: Sun, 16 Mar 2025 19:39:41 +0000 Subject: [PATCH 2/4] docs(attachment): update README to include in-buffer attachment viewer feature --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e94c72b..b541f24 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ the familiar Vim interface and motions. - 📧 **Email Browsing**: Navigate emails with Vim-like movements. - 🔍 **Search Your Email**: Leverage `notmuch` to search your email interactively. - 🔗 **Thread Viewing**: Messages are loaded with folding and threading intact. -- 📎 **Attachment Management**: View and save attachments easily. +- 📎 **Attachment Management**: View, open and save attachments easily. - ⬇️ **Offline Mail Sync**: Supports `mbsync` for efficient sync processes. - 🔓 **Async Search**: Large mailboxes with thousands of email? No problem. - 🏷️ **Tag Management**: Conveniently add, remove, or toggle email tags. @@ -99,6 +99,7 @@ You can configure several global options to tailor the plugin's behavior: | `notmuch_db_path` | Directory containing the `.notmuch/` dir | `$HOME/Mail` | | `maildir_sync_cmd` | Bash command to run for syncing maildir | `mbsync -a` | | `open_cmd` | Bash command for opening attachments | `xdg-open` | +| `view_handler` | Bash command for converting attachments to text to view in vim buffer | `view-handler` | | `keymaps` | Configure any (WIP) command's keymap | See `config.lua`[1] | [1]: https://github.com/yousefakbar/notmuch.nvim/blob/main/lua/notmuch/config.lua @@ -118,6 +119,20 @@ Example in plugin manager (lazy.nvim): }, ``` +Example `view-handler`: +*make sure the `view-handler` is available in your PATH* + +``` sh +#!/bin/sh + +case "$1" in + *.html ) cat "$1" | w3m -T "text/html" -dump | col ;; + # *.pdf ) pdftohtml "$1" - | w3m -T "text/html" -dump | col ;; + *.pdf ) mutool draw -F html -o - "$1" | w3m -T "text/html" -dump | col ;; + *) echo "Unable to convert to text!" ;; +esac +``` + ## License This project is licensed under the MIT License, granting you the freedom to use, From 938ee90218932063296d0fd5ba24537f31fb7e03 Mon Sep 17 00:00:00 2001 From: Simon H Moore Date: Sun, 16 Mar 2025 20:06:32 +0000 Subject: [PATCH 3/4] refactor(mail)!: rename open_cmd config to open_handler callback BREAKING CHANGE: The `open_cmd` config option has been renamed to `open_handler` to align with the `view_handler` config option. It is now a callback function. Users will need to update their configuration to use `open_handler` instead of `open_cmd`. --- README.md | 2 +- lua/notmuch/attach.lua | 3 ++- lua/notmuch/config.lua | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b541f24..b129698 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ You can configure several global options to tailor the plugin's behavior: | :----------------- | :--------------------------------------: | :------------ | | `notmuch_db_path` | Directory containing the `.notmuch/` dir | `$HOME/Mail` | | `maildir_sync_cmd` | Bash command to run for syncing maildir | `mbsync -a` | -| `open_cmd` | Bash command for opening attachments | `xdg-open` | +| `open_handler` | Bash command for opening attachments | `xdg-open` | | `view_handler` | Bash command for converting attachments to text to view in vim buffer | `view-handler` | | `keymaps` | Configure any (WIP) command's keymap | See `config.lua`[1] | diff --git a/lua/notmuch/attach.lua b/lua/notmuch/attach.lua index 3cb29c1..86ac669 100644 --- a/lua/notmuch/attach.lua +++ b/lua/notmuch/attach.lua @@ -18,7 +18,8 @@ end -- TODO generalize this: //dev/null 2>/dev/null') + end, view_handler = function(attachment) return vim.fn.system({"view-handler", attachment.path}) end, From 23397137891afcba5f37c7801a584404328723c9 Mon Sep 17 00:00:00 2001 From: Simon H Moore Date: Sun, 16 Mar 2025 23:02:10 +0000 Subject: [PATCH 4/4] docs(attachment): update README to reflect handler config change The README configuration options now show that the handler config options are callback functions. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b129698..3ea7482 100644 --- a/README.md +++ b/README.md @@ -94,12 +94,12 @@ Here are the core commands within Notmuch.nvim: You can configure several global options to tailor the plugin's behavior: -| Option | Description | Default value | +| Option | Description | Default | | :----------------- | :--------------------------------------: | :------------ | | `notmuch_db_path` | Directory containing the `.notmuch/` dir | `$HOME/Mail` | | `maildir_sync_cmd` | Bash command to run for syncing maildir | `mbsync -a` | -| `open_handler` | Bash command for opening attachments | `xdg-open` | -| `view_handler` | Bash command for converting attachments to text to view in vim buffer | `view-handler` | +| `open_handler` | Callback function for opening attachments | By default runs `xdg-open` | +| `view_handler` | Callback function for converting attachments to text to view in vim buffer | By default runs `view-handler` | | `keymaps` | Configure any (WIP) command's keymap | See `config.lua`[1] | [1]: https://github.com/yousefakbar/notmuch.nvim/blob/main/lua/notmuch/config.lua