-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvim-voicecode.vim
More file actions
35 lines (29 loc) · 1.02 KB
/
vim-voicecode.vim
File metadata and controls
35 lines (29 loc) · 1.02 KB
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
function! SetVoicecodeMode(newMode)
python << endPython
import vim
import socket
KNOWN_FILE_TYPES = {"python": "Python",
"clojure": "Clojure",
"ruby": "Ruby",
"c": "C",
"coffee": "Coffee",
"vim": "Vim",
"javascript": "Javascript"}
def set_mode():
try:
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect('/tmp/voicecode.sock')
file_type = vim.eval('&ft')
if file_type in KNOWN_FILE_TYPES:
sock.sendall('set mode {}'.format(''.join([vim.eval('a:newMode'), KNOWN_FILE_TYPES[file_type]])))
else:
sock.sendall('set mode {}'.format(vim.eval('a:newMode')))
except:
pass
set_mode()
endPython
endfunction
autocmd VimEnter * call SetVoicecodeMode('vimNormal')
autocmd VimLeave * call SetVoicecodeMode('exitedVim')
autocmd InsertEnter * call SetVoicecodeMode('vimInsert')
autocmd InsertLeave * call SetVoicecodeMode('vimNormal')