@@ -3,6 +3,12 @@ let g:gitmoji = 1
33
44let s: directory = expand (' <sfile>:p' )- >resolve ()- >fnamemodify (' :h' )
55
6+ function s: warn (... )
7+ echohl WarningMsg
8+ echomsg " gitmoji.vim: " a: 000- >join ()
9+ echohl None
10+ endfunction
11+
612function s: compare (lhs, rhs)
713 if a: lhs .name == a: rhs .name
814 return 0
@@ -20,35 +26,18 @@ function s:findlocal(filename)
2026 return findfile (a: filename , s: directory )
2127endfunction
2228
23- " There needs to be a better way to handle this
24- " TODO: We need to provide a separate way for users to define their aliases
25- " where kind: is set to *not* gitmoji, but 'user', or 'plugin'
2629" TODO: Look into applying iabbrev(s) during the CompleteDonePre or
2730" CompleteDone event.
2831function s: builtin (idx, name)
2932 let gitmoji = s: gitmoji [a: name ]
30- echomsg " Gitmoji.code: " gitmoji.code
3133 let word = g: gitmoji_insert_emoji ? gitmoji.emoji : gitmoji.code
32- let result = << trim EOT
33- #{
34- word: g: gitmoji_insert_emoji ? gitmoji.emoji : gitmoji.code,
35- abbr: gitmoji.emoji .. ' ' .. gitmoji.name,
36- menu : gitmoji.description,
37- kind: ' gitmoji' ,
38- }
39- EOT
40- return result- >join ()- >eval ()
41- endfunction
42-
43- function s: warn (... )
44- echohl WarningMsg
45- echomsg " gitmoji.vim: " a: 000- >join ()
46- echohl None
34+ let abbr = printf (' %s %s' , gitmoji.emoji , gitmoji.name)
35+ let menu = gitmoji.description
36+ let kind = ' builtin'
37+ return #{ word: word, abbr: abbr, menu : menu , kind: kind }
4738endfunction
4839
49- " This will be configurable at some point for additional things, like custom
50- " files
51- function s: load ()
40+ function s: builtins ()
5241 let data = s: findlocal (' gitmojis.json' )- >s: readjson ()
5342 let result = {}
5443 if ! has_key (data, ' gitmojis' )
@@ -62,13 +51,40 @@ function s:load()
6251 return result
6352endfunction
6453
54+ function s: aliases ()
55+ if ! exists (' g:gitmoji_aliases' )
56+ return {}
57+ endif
58+ let type = type (g: gitmoji_aliases )
59+ let data = {}
60+ if type == v: t_string
61+ let data = s: readjson (g: gitmoji_aliases )
62+ elseif type == v: t_dict
63+ let data = g: gitmoji_aliases
64+ elseif type == v: t_func
65+ let data = call g: gitmoji_aliases
66+ if type (data) != v: t_dict
67+ s: warn (' gitmoji.vim' , ' g:gitmoji_aliases function did not return a dictionary' )
68+ return {}
69+ endif
70+ endif
71+ return data
72+ endfunction
73+
6574function gitmoji#builtins ()
6675 if ! exists (' s:gitmoji' )
67- let s: gitmoji = s: load ()
76+ let s: gitmoji = s: builtins ()
6877 endif
6978 return s: gitmoji
7079endfunction
7180
81+ function gitmoji#aliases ()
82+ if ! exists (' s:aliases' )
83+ let s: aliases = s: aliases ()
84+ endif
85+ return s: aliases
86+ endfunction
87+
7288function gitmoji#complete (findstart, base)
7389 call gitmoji#builtins ()
7490 " TODO: Permit configuration setting to allow 'matching' if the line is
@@ -83,7 +99,3 @@ function gitmoji#complete(findstart, base)
8399 endif
84100 return keys - >map (function (' s:builtin' ))
85101endfunction
86-
87- " Registers aliases from a dictionary to be usable as gitmoji names.
88- function gitmoji#register (aliases)
89- endfunction
0 commit comments