From fada081115139c2b07ea657c749ec7e7c44b3cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Sat, 8 May 2021 21:55:07 +0200 Subject: [PATCH] add vim deletion range --- vim/autoload/himalaya/msg.vim | 22 ++++++++++++++++------ vim/ftplugin/himalaya-msg-list.vim | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/vim/autoload/himalaya/msg.vim b/vim/autoload/himalaya/msg.vim index 53610f8..a710a0c 100644 --- a/vim/autoload/himalaya/msg.vim +++ b/vim/autoload/himalaya/msg.vim @@ -166,7 +166,8 @@ function! himalaya#msg#move(target_mbox) try let msg_id = stridx(bufname("%"), "Himalaya messages") == 0 ? s:get_focused_msg_id() : s:msg_id let choice = input(printf("Are you sure you want to move the message %d? (y/N) ", msg_id)) - if tolower(choice) != "y" | redraw | echo | return | endif + redraw | echo + if choice != "y" | return | endif let pos = getpos(".") let source_mbox = himalaya#mbox#curr_mbox() let msg = s:cli("--mailbox %s move %d %s", [shellescape(source_mbox), msg_id, shellescape(a:target_mbox)], "Moving message", 1) @@ -179,14 +180,15 @@ function! himalaya#msg#move(target_mbox) endtry endfunction -function! himalaya#msg#delete() +function! himalaya#msg#delete() range try - let msg_id = stridx(bufname("%"), "Himalaya messages") == 0 ? s:get_focused_msg_id() : s:msg_id - let choice = input(printf("Are you sure you want to delete the message %d? (y/N) ", msg_id)) - if tolower(choice) != "y" | redraw | echo | return | endif + let msg_ids = stridx(bufname("%"), "Himalaya messages") == 0 ? s:get_focused_msg_ids(a:firstline, a:lastline) : s:msg_id + let choice = input(printf("Are you sure you want to delete message(s) %s? (y/N) ", msg_ids)) + redraw | echo + if choice != "y" | return | endif let pos = getpos(".") let mbox = himalaya#mbox#curr_mbox() - let msg = s:cli("--mailbox %s delete %d", [shellescape(mbox), msg_id], "Deleting message", 1) + let msg = s:cli("--mailbox %s delete %s", [shellescape(mbox), msg_ids], "Deleting message(s)", 1) call himalaya#msg#list_with(mbox, himalaya#mbox#curr_page(), 1) call setpos('.', pos) catch @@ -292,3 +294,11 @@ function! s:get_focused_msg_id() throw "message not found" endtry endfunction + +function! s:get_focused_msg_ids(from, to) + try + return join(map(range(a:from, a:to), "s:trim(split(getline(v:val), '|')[0])"), ",") + catch + throw "messages not found" + endtry +endfunction diff --git a/vim/ftplugin/himalaya-msg-list.vim b/vim/ftplugin/himalaya-msg-list.vim index 1434dfe..3e5db2f 100644 --- a/vim/ftplugin/himalaya-msg-list.vim +++ b/vim/ftplugin/himalaya-msg-list.vim @@ -17,4 +17,5 @@ call himalaya#shared#bindings#define([ \["n", "gC" , "mbox#pick('himalaya#msg#copy')"], \["n", "gM" , "mbox#pick('himalaya#msg#move')"], \["n", "gD" , "msg#delete()" ], + \["v", "gD" , "msg#delete()" ], \])