All pastes #2068635 Raw Edit

vim-mutt-complete

public python v1 · immutable
#2068635 ·published 2011-05-24 20:29 UTC
rendered paste body
"  tab expansion of aliases in e-mail messages."  Copyright (c) 2011 Christian R. Reis <kiko@linaro.org>"  With code borrowed from Sean Reifschneider <jafo@tummy.com>, tummy.com, ltd."  License: GNU Public Licensefunction! s:DefPython()python << PYTHONEOFimport vim, os, reALIAS_FILE = ".mutt_aliases"fp = open(os.path.join(os.environ['HOME'], ALIAS_FILE), 'r')lines = fp.readlines()fp.close()####################def expandAliases(search):    '''Look for aliases in the current line and expand them.'''    #  find match    search = search.lower().strip()    if not search:        return    matches = []    for line in lines:        m = re.match(r'^alias\s+(\S+)\s(.+)$', line)        if not m: continue        if m.group(1).lower().startswith(search):            matches.append(m.group(2).strip())    for m in matches:        vim.command("call add(g:completion, ' %s')" % m)PYTHONEOFendfunctioncall s:DefPython()fun! PythonExpandAliases(s)    let g:completion = []    execute "python expandAliases('".a:s."')"    return g:completionendfunctionfun! CompleteEmails(findstart, base)    if a:findstart        let line = getline('.')        "locate the start of the word        let start = col('.') - 1        while start > 0 && line[start - 1] =~ '[^:,]'            let start -= 1        endwhile        return start    else        return PythonExpandAliases(a:base)    endifendfunfun! UserComplete(findstart, base)    " Fetch current line    let line = getline(line('.'))    " Is it a special line?    if line =~ '^\(To\|Cc\|Bcc\|From\|Reply-To\):'        return CompleteEmails(a:findstart, a:base)    endifendfunlet b:savedfo = &fofun! FixFormatOptions()    " Fetch current line    let line = getline(line('.'))    " Is it a special line?    if line =~ '^\(To\|Cc\|Bcc\|From\|Reply-To\):'        set fo =        inoremap <tab> <C-x><C-u>    else        let &fo = b:savedfo        inoremap <tab> <tab>    endifendfunset completefunc=UserCompleteautocmd CursorHold,CursorMoved * call FixFormatOptions()