Last active
November 12, 2016 23:09
-
-
Save alyssarosenzweig/6c84870659871ea4eca75cc4abb7a9d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python3 << EOF | |
import ctypes, vim | |
markov = ctypes.cdll.LoadLibrary("/usr/local/lib/libmarkov.so") | |
markov.initialize_chain(b"/usr/local/share/markov-chain") | |
def insert(): | |
out = ctypes.create_string_buffer(128) | |
ln = vim.current.line.encode() | |
s = markov.nextWord(out, 128, ctypes.create_string_buffer(ln), len(ln)) | |
vim.current.line += out.value.decode() | |
return s | |
def substitute(): | |
words = vim.current.line.rstrip().split(" ") | |
vim.current.line = " ".join(words[:-1]) + " " | |
if insert() == 0: | |
vim.current.line += words[-1] | |
EOF | |
inoremap <Esc>:python3 substitute()<CR>$a | |
inoremap ` <Esc>:python3 insert()<CR>$a | |
inoremap ` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment