-
Notifications
You must be signed in to change notification settings - Fork 0
/
winvimtoever.vim
65 lines (50 loc) · 1.62 KB
/
winvimtoever.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
" winvimtoever.vim
" vim script, send current buffer to evernote
if !exists("g:winVimToEverUseFilename")
let g:winVimToEverUseFilename = 0
endif
if !exists("g:winVimToEverPath")
let g:winVimToEverPath = 'C:\Progra~1\Evernote\Evernote3.5\ENScript.exe'
endif
if !exists("g:winVimToEverNote")
let g:winVimToEverNote = ""
end
if !exists("g:winVimToEverAttachment")
let g:winVimToEverAttachment = 0
endif
function! WinVimToEver()
if g:winVimToEverUseFilename
let title = expand("%:t")
else
let title = getline(1)
endif
"let tag = ...
let tmpdir = tempname()
call mkdir(tmpdir)
let bodyfile = fnamemodify(tempname(), ":p:r").'.txt'
let lines = getline(1, line("$"))
let body = iconv(join(lines, "\r\n"), &fileencoding, "cp932")
" for japanese
if has('iconv')
let title = iconv(title, &fileencoding, "cp932")
let body = iconv(body, &fileencoding, "cp932")
end
call writefile(split(body, "\r\n", 1), bodyfile, "b")
let cmd = g:winVimToEverPath.' createNote /s '.shellescape(bodyfile).' /i '.shellescape(title)
if g:winVimToEverAttachment
let filename = expand("%:t")
if filename == ''
let filename = 'attachment.txt'
end
let tmpfile = tmpdir . '\' . filename
call writefile(split(body, "\r\n", 1), tmpfile, "b")
let cmd = cmd.' /a '.shellescape(tmpfile)
end
if g:winVimToEverNote
let cmd = cmd.' /n '.shellescape(g:winVimToEverNote)
endif
let ret = system(cmd)
" FIXME!
call system("rmdir /S /Q ".shellescape(tmpdir))
call delete(bodyfile)
endfunction