From 442dc457b57c7b7563b8cf0fdb6786fc529886b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Mon, 5 Apr 2021 23:57:01 +0200 Subject: [PATCH] add telescope support --- CHANGELOG.md | 5 +++++ vim/README.md | 15 +++++++++++++++ vim/autoload/himalaya/mbox.lua | 22 ++++++++++++++++++++++ vim/autoload/himalaya/mbox.vim | 9 ++++++++- vim/ftplugin/himalaya-msg-list.vim | 4 ---- 5 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 vim/autoload/himalaya/mbox.lua diff --git a/CHANGELOG.md b/CHANGELOG.md index be2fa9d..2b2cf87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Telescope support [#61] + ## [0.2.2] - 2021-04-04 ### Added @@ -113,3 +117,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#39]: https://github.com/soywod/himalaya/issues/39 [#40]: https://github.com/soywod/himalaya/issues/40 [#41]: https://github.com/soywod/himalaya/issues/41 +[#61]: https://github.com/soywod/himalaya/issues/61 diff --git a/vim/README.md b/vim/README.md index 9be85c8..5995dd5 100644 --- a/vim/README.md +++ b/vim/README.md @@ -10,6 +10,7 @@ Vim plugin for [Himalaya](https://github.com/soywod/himalaya) CLI email client. * [Installation](#installation) * [Usage](#usage) * [List messages view](#list-messages-view) + * [List mailboxes](#list-mailboxes) * [Read message view](#read-message-view) * [Write message view](#write-message-view) * [License](https://github.com/soywod/himalaya.vim/blob/master/LICENSE) @@ -81,6 +82,20 @@ nmap gf (himalaya-msg-forward) nmap ga (himalaya-msg-attachments) ``` +### List mailboxes + +Default behaviour (basic prompt): + +![screenshot](https://user-images.githubusercontent.com/10437171/113631817-51eb3180-966a-11eb-8b13-cd1f1f2539ab.jpeg) + +With [telescope](https://github.com/nvim-telescope/telescope.nvim) support: + +![screenshot](https://user-images.githubusercontent.com/10437171/113631294-86122280-9669-11eb-8074-1c43c36b65a9.jpeg) + +With [fzf](https://github.com/junegunn/fzf) support: + +![screenshot](https://user-images.githubusercontent.com/10437171/113631382-acd05900-9669-11eb-817d-c28fd5d9574c.jpeg) + ### Read message view ![gif](https://user-images.githubusercontent.com/10437171/110708073-7b937300-81fa-11eb-9f4c-5472cea22e21.gif) diff --git a/vim/autoload/himalaya/mbox.lua b/vim/autoload/himalaya/mbox.lua new file mode 100644 index 0000000..ab8e360 --- /dev/null +++ b/vim/autoload/himalaya/mbox.lua @@ -0,0 +1,22 @@ +local actions = require('telescope.actions') +local action_state = require('telescope.actions.state') +local finders = require('telescope.finders') +local pickers = require('telescope.pickers') +local sorters = require('telescope.sorters') + +function mbox_picker(mboxes) + pickers.new { + results_title = 'Mailboxes', + finder = finders.new_table(mboxes), + sorter = sorters.fuzzy_with_index_bias(), + attach_mappings = function(prompt_bufnr) + actions.select_default:replace(function() + local selection = action_state.get_selected_entry() + actions.close(prompt_bufnr) + vim.fn['himalaya#mbox#post_input'](selection.display) + end) + + return true + end, + }:find() +end diff --git a/vim/autoload/himalaya/mbox.vim b/vim/autoload/himalaya/mbox.vim index df836e4..ca30bfa 100644 --- a/vim/autoload/himalaya/mbox.vim +++ b/vim/autoload/himalaya/mbox.vim @@ -1,3 +1,4 @@ +let s:dir = expand(":h") let s:cli = function("himalaya#shared#cli#call") " Pagination @@ -27,12 +28,18 @@ endfunction function! himalaya#mbox#input() try let mboxes = map(s:cli("mailboxes", [], "Fetching mailboxes"), "v:val.name") - if &rtp =~ "fzf" + + if &rtp =~ "telescope" + execute printf("luafile %s/mbox.lua", s:dir) + call luaeval(printf("mbox_picker({%s})", join(map(mboxes, "string(v:val)"), ", "))) + + else if &rtp =~ "fzf" call fzf#run({ \"source": mboxes, \"sink": function("himalaya#mbox#post_input"), \"down": "25%", \}) + else let choice = map(copy(mboxes), "printf('%s (%d)', v:val, v:key)") let choice = input(join(choice, ", ") . ": ") diff --git a/vim/ftplugin/himalaya-msg-list.vim b/vim/ftplugin/himalaya-msg-list.vim index 3ffddc4..33b7a68 100644 --- a/vim/ftplugin/himalaya-msg-list.vim +++ b/vim/ftplugin/himalaya-msg-list.vim @@ -4,10 +4,6 @@ setlocal nomodifiable setlocal nowrap setlocal startofline -nnoremap q :bwipeout -nnoremap :bwipeout -nnoremap :bwipeout - call himalaya#shared#bindings#define([ \["n", "gm" , "mbox#input" ], \["n", "gp" , "mbox#prev_page" ],