On Tue, Feb 10, at 07:32 Agathoklis D. Hatzimanikas wrote:
> On Tue, Feb 10, at 09:00 Tom Link wrote:
> > 
> > > For example, with a such entry in my aliases file :
> > > alias chuck Chuck Nurris <his.em...@invalid.invalid>
> > > could have a (case insensitive) completion based on the alias, the first
> > > name, name or the email.
> > 
> > The simplest solution would be to keep the e-mails in a dictionary but
> > that wouldn't meet your requirements. I think you could write a
> > completefunc, that reads the file with readfile() and returns a list
> > of lines (but without the alias part) that match the arglead.
> >
> 
> Here is one I use, (substitute the path to your aliases file):
> 
> function! Reademailaddress(A,L,P)
>     let list = readfile(expand("$HOME")."/.mutt/aliases")
>     call map(list, 'substitute(v:val, ''.*<\(.*\)>'', ''\1'', ''g'')')
>     return filter(list[0:-2], 'v:val =~ "^".a:A')
> endfunction
> 
> call input("To: ", "", "customlist,Reademailaddress")
> 

Here is another most complete example, it will complete aliases entries
based on the alias (adjust accordingly to match your preferences, just
change the 'key' variable with another line[index]):

(save those two functions in ~/.vim/autoload/mail.vim and substitute
the path to your aliases)


function! mail#read(A,L,P)
    let list = readfile(expand("$HOME")."/.mutt/aliases")
    let s:dic = {}
    let keylist = []
    for alias in list
        let line = split(alias)
        let key = line[1]
        let s:dic[key] = line[2:]
        call add(keylist, key)
    endfor
    return filter(keylist, 'v:val =~ "^".a:A')
endfunction

function! mail#alias()
    let to = input("To: ", "", "customlist,mail#read")
    return join(s:dic[to])
endfunction

To use it - let's say while you are in insert mode, use the expression
register, like e.g.,

    <C-R>=mail#alias()

Then type the first alias letter for auto completion.


You can add some tests, like filereadable('path/to/aliases') to make it
more robust.

Regards,
Ag.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to