/
emoticon.vim
122 lines (108 loc) · 3.06 KB
/
emoticon.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
" emoticon vim plugin
"
" Author: Cornelius
" Email: cornelius.howl@gmail.com
" Date: 二 11/17 20:30:28 2009
" Version: 0.1
"
" http://github.com/c9s
scriptencoding utf8
fun! s:randselect(list)
let s = len( a:list )
let r = reltime()
let t = str2nr( r[1] ) % s
return a:list[t]
endf
fun! s:generate()
let rinkaku = s:randselect([
\['(',')'] ,
\['(', ')'],
\['|', '|'],
\['[', ']']
\])
let otete = s:randselect([
\['∑','','','',''],
\['', '', '', '', ''],
\['', '', 'm', '', ''],
\['', '', 'ლ', '', ''],
\['ლ', '', '', 'ლ', ''],
\['', '「', '', '', '「'],
\['', ' つ', '', '', 'つ'],
\['', ' ', '', '', 'o彡゚'],
\['⊚', '', '', '', '⊚'],
\['', 'n', '', '', 'η'],
\['', '∩', '', '∩', ''], ['∩', '', '', '', '∩'], ['ヽ', '', '', '', 'ノ'], ['┐', '', '', '', '┌']])
let omeme = s:randselect([['╹', '╹'], ['>', '<'], ['^', '^'], ['・', '・'], ['´・', '・`'], ['`・', '・´'], ['´', '`'], ['≧', '≦'], ['゚', '゚'], ['''', ''''], ['・ิ', '・ิ'], ['❛', '❛']])
let okuti = s:randselect(['⇔','x','=','"','~','_','д','ω', '∀', '▽', '△', 'Д', '◡', 'A', '□', '~', 'ー', 'ェ', 'ρ', 'o'])
let hoppe = s:randselect([['', ''], ['*', ''], ['', '*'], ['', '#'], ['#', ''], ['✿', ''], ['', '✿'], ['', ';'], [';', ''], ['', '。']])
let ot1 = otete[1]
let ot2 = otete[2]
let ot3 = otete[3]
if ot1 == '' && otete[3]
let ot1 = ''
elseif ot1 == '' && otete[3] == ''
let ot1 = hoppe[0]
endif
if ot2 == ''
let ot2 = okuti
endif
if ot3 == '' && otete[1]
let ot3 = ''
elseif ot3 == '' && otete[1] == ''
let ot3 = hoppe[1]
endif
let text = [
\ otete[0],
\ rinkaku[0],
\ ot1,
\ omeme[0],
\ otete[2],
\ omeme[1],
\ ot2,
\ rinkaku[1],
\ otete[4]
\]
return join( text , "" )
endf
fun! s:newEmoticon()
echo s:generate()
endf
fun! s:appendEmoticon()
cal append(line('.'), s:generate() )
endf
fun! s:newEmoticonCB()
if has('clipboard')
cal setreg('*', s:generate() )
else
echomsg "You dont have clipboard supported"
endif
endf
fun! s:gen_key(i)
let key = ""
let k = a:i
while k > 0
let key = nr2char( k % 26 + 97 ) . key
let k = float2nr(k / 26)
endwhile
return key
endf
fun! CompleteEmoticon(s,base)
if a:s
" locate the start of the word
let line = getline('.')
let start = col('.') - 1
while start > 0 && line[start - 1] =~ '\a'
let start -= 1
endwhile
return start
else
for i in range(1,200)
let key = s:gen_key(i)
cal complete_add( { 'word': s:generate() , 'menu': key } )
endfor
endif
endf
com! NewEmoticon :cal s:newEmoticon()
com! NewEmoticonCB :cal s:newEmoticonCB()
com! AppendEmoticon :cal s:appendEmoticon()
com! EnableEmoticonOmni :setlocal omnifunc=CompleteEmoticon