" tab expansion of aliases in e-mail messages. " Copyright (c) 2011 Christian R. Reis " With code borrowed from Sean Reifschneider , tummy.com, ltd. " License: GNU Public License function! s:DefPython() python << PYTHONEOF import vim, os, re ALIAS_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) PYTHONEOF endfunction call s:DefPython() fun! PythonExpandAliases(s) let g:completion = [] execute "python expandAliases('".a:s."')" return g:completion endfunction fun! 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) endif endfun fun! 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) endif endfun let b:savedfo = &fo fun! FixFormatOptions() " Fetch current line let line = getline(line('.')) " Is it a special line? if line =~ '^\(To\|Cc\|Bcc\|From\|Reply-To\):' set fo = inoremap else let &fo = b:savedfo inoremap endif endfun set completefunc=UserComplete autocmd CursorHold,CursorMoved * call FixFormatOptions()