mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 13:17:55 +08:00
add copy/move/delete vim features
This commit is contained in:
@@ -18,6 +18,27 @@ function! himalaya#mbox#next_page()
|
||||
call himalaya#msg#list()
|
||||
endfunction
|
||||
|
||||
" Pickers
|
||||
|
||||
function! s:telescope_picker(cb, mboxes)
|
||||
call luaeval("require('himalaya.mbox').mbox_picker")(a:cb, a:mboxes)
|
||||
endfunction
|
||||
|
||||
function! s:fzf_picker(cb, mboxes)
|
||||
call fzf#run({
|
||||
\"source": a:mboxes,
|
||||
\"sink": a:cb,
|
||||
\"down": "25%",
|
||||
\})
|
||||
endfunction
|
||||
|
||||
function! s:native_picker(cb, mboxes)
|
||||
let choice = map(copy(a:mboxes), "printf('%s (%d)', v:val, v:key)")
|
||||
let choice = input(join(choice, ", ") . ": ")
|
||||
redraw | echo
|
||||
call function(a:cb)(a:mboxes[choice])
|
||||
endfunction
|
||||
|
||||
" Mailbox
|
||||
|
||||
let s:curr_mbox = "INBOX"
|
||||
@@ -25,49 +46,23 @@ function! himalaya#mbox#curr_mbox()
|
||||
return s:curr_mbox
|
||||
endfunction
|
||||
|
||||
function! s:telescope_picker(mboxes)
|
||||
call luaeval('require("himalaya.mbox").mbox_picker')(a:mboxes)
|
||||
endfunction
|
||||
|
||||
function! s:fzf_picker(mboxes)
|
||||
call fzf#run({
|
||||
\"source": a:mboxes,
|
||||
\"sink": function("himalaya#mbox#post_input"),
|
||||
\"down": "25%",
|
||||
\})
|
||||
endfunction
|
||||
|
||||
function! s:native_picker(mboxes)
|
||||
let choice = map(copy(a:mboxes), "printf('%s (%d)', v:val, v:key)")
|
||||
let choice = input(join(choice, ", ") . ": ")
|
||||
redraw | echo
|
||||
call himalaya#mbox#post_input(a:mboxes[choice])
|
||||
endfunction
|
||||
|
||||
let s:pickers = {
|
||||
\"telescope": function("s:telescope_picker"),
|
||||
\"fzf": function("s:fzf_picker"),
|
||||
\"native": function("s:native_picker"),
|
||||
\}
|
||||
|
||||
function! himalaya#mbox#input()
|
||||
function! himalaya#mbox#pick(cb)
|
||||
try
|
||||
let mboxes = map(s:cli("mailboxes", [], "Fetching mailboxes", 0), "v:val.name")
|
||||
|
||||
" Get user choice for picker, otherwise check runtimepath
|
||||
if exists("g:himalaya_mailbox_picker")
|
||||
let mbox_picker = g:himalaya_mailbox_picker
|
||||
let picker = g:himalaya_mailbox_picker
|
||||
else
|
||||
if &rtp =~ "telescope"
|
||||
let mbox_picker = "telescope"
|
||||
let picker = "telescope"
|
||||
elseif &rtp =~ "fzf"
|
||||
let mbox_picker = "fzf"
|
||||
let picker = "fzf"
|
||||
else
|
||||
let mbox_picker = "native"
|
||||
let picker = "native"
|
||||
endif
|
||||
endif
|
||||
|
||||
call s:pickers[mbox_picker](mboxes)
|
||||
execute printf("call s:%s_picker(a:cb, mboxes)", picker)
|
||||
catch
|
||||
if !empty(v:exception)
|
||||
redraw | call himalaya#shared#log#err(v:exception)
|
||||
@@ -75,7 +70,7 @@ function! himalaya#mbox#input()
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! himalaya#mbox#post_input(mbox)
|
||||
function! himalaya#mbox#set(mbox)
|
||||
let s:curr_mbox = a:mbox
|
||||
let s:curr_page = 0
|
||||
call himalaya#msg#list()
|
||||
|
||||
@@ -147,6 +147,55 @@ function! himalaya#msg#forward()
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! himalaya#msg#copy(target_mbox)
|
||||
try
|
||||
let pos = getpos(".")
|
||||
let msg_id = stridx(bufname("%"), "Himalaya messages") == 0 ? s:get_focused_msg_id() : s:msg_id
|
||||
let source_mbox = himalaya#mbox#curr_mbox()
|
||||
let msg = s:cli("--mailbox %s copy %d %s", [shellescape(source_mbox), msg_id, shellescape(a:target_mbox)], "Copying message", 1)
|
||||
call himalaya#msg#list_with(source_mbox, himalaya#mbox#curr_page(), 1)
|
||||
call setpos('.', pos)
|
||||
catch
|
||||
if !empty(v:exception)
|
||||
redraw | call himalaya#shared#log#err(v:exception)
|
||||
endif
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
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
|
||||
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)
|
||||
call himalaya#msg#list_with(source_mbox, himalaya#mbox#curr_page(), 1)
|
||||
call setpos('.', pos)
|
||||
catch
|
||||
if !empty(v:exception)
|
||||
redraw | call himalaya#shared#log#err(v:exception)
|
||||
endif
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! himalaya#msg#delete()
|
||||
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 pos = getpos(".")
|
||||
let mbox = himalaya#mbox#curr_mbox()
|
||||
let msg = s:cli("--mailbox %s delete %d", [shellescape(mbox), msg_id], "Deleting message", 1)
|
||||
call himalaya#msg#list_with(mbox, himalaya#mbox#curr_page(), 1)
|
||||
call setpos('.', pos)
|
||||
catch
|
||||
if !empty(v:exception)
|
||||
redraw | call himalaya#shared#log#err(v:exception)
|
||||
endif
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! himalaya#msg#draft_save()
|
||||
let s:draft = join(getline(1, "$"), "\n")
|
||||
redraw | call s:log("Save draft [OK]")
|
||||
|
||||
@@ -2,7 +2,7 @@ function! himalaya#shared#bindings#define(bindings)
|
||||
for [mode, key, name] in a:bindings
|
||||
let plug = substitute(name, "[#_]", "-", "g")
|
||||
let plug = printf("<plug>(himalaya-%s)", plug)
|
||||
execute printf("%snoremap <silent>%s :call himalaya#%s()<cr>", mode, plug, name)
|
||||
execute printf("%snoremap <silent>%s :call himalaya#%s<cr>", mode, plug, name)
|
||||
|
||||
if !hasmapto(plug, mode)
|
||||
execute printf("%smap <nowait><buffer>%s %s", mode, key, plug)
|
||||
|
||||
Reference in New Issue
Block a user