"=============================================================== " File : Mail_Re_set.vim " Initial Author: Dominique Baldo " Maintained by : Luc Hermitte " " URL: http://hermitte.free.fr/vim/ressources/vimfiles/ftplugin/mail/Mail_Re_set.vim " Version : 2.0 " Last update : 15th Oct 2003 "--------------------------------------------------------------- " Purpose : Merge the occurencies of "Re:" and "Re[n]" within " e-mails'subject in only one. " " Calling conv. : Source this file and invoke :MailCondenseRe " define -> nnoremap ,re :MailCondenseRe " Installation : {{{1 " * Drop this file into {rtp}/ftplugin/mail/ " * There are two available options you can customize into your .vimrc : " + Customize the way you want the "Re" string to be built thanks to " g:mail_re_fmt or b:mail_re_fmt : " "Re:" -- use "Re:" " "Re[]:" -- use "Re[n]:" when {n}>1 ; "Re:" when {n}=1 " "Re[1]:" -- use "Re[n]:" even when {n}>1 " "Mimic:" -- use what the correspondant used [default] " + Customize the placement order between "Re:" and "[TAGS]" thanks to " g:mail_tag_placement or b:mail_tag_placement : " "detect_news" -- use "Re: [TAG]" for usenet, "[TAG] Re:" otherwise " [default] " "tag_second" -- use "Re: [TAG]" ; seems to be the right option on " usenet according to trn " "tag_first" -- use "[TAG] Re:" ; seems to be the option used on " tagged mailing lists " }}}1 "--------------------------------------------------------------- " History: {{{1 " * Ver 2.0 : Also merges the various forward indicators " * Ver 1.4d : Fix a bug when g:mail_tag_placement is set " Use "normal!" instead of "normal" " New kind of whitespace managed: some people composing " their messages from yahogroups web site may use very odd " whitespace characters to write "Re :" " * Ver 1.4c : Fix a small bug " * Ver 1.4b : "Rép:" added to the list of "Re:" equivalents " * ver 1.4 : "Re:" can be placed before or after the first [tag] present " according to g:mail_tag_placement " * ver 1.3 : Requires VIM 6.x " Export a command: :MailCondenseRe " count the Re: thanks to the global length of strings " The subject build can be customized thanks to g:mail_re_fmt " or b:mail_re_fmt. " The "Re:" will be placed after the [Tags] if present. " * ver 1.2 : Translation of the comments " * ver 1.1 : Handle "Réf" produced by some french e-mailers " Answer by "Re:" most of the time " * ver 1.0 : Replace "Re: Re: ..." n times by "Re[n]:" " " TODO: {{{1 " * Add an option to add equivalents to "Re:" -- only "Réf.:" and "Rép:" are " supported at this time. " * Support "Re: Fwd: Fw: " " }}}1 "=============================================================== if exists("b:loaded_local_Mail_Re_set_vim") | finish | endif let b:loaded_local_Mail_Re_set_vim = 1 command! -b -nargs=0 MailCondenseRe :call Mail_Merge_Re_n_Fwd(1,0) command! -b -nargs=0 MailCondenseFwd :call Mail_Merge_Re_n_Fwd(0,1) command! -b -nargs=0 MailCondenseReAndFwd :call Mail_Merge_Re_n_Fwd(1,1) "=============================================================== " Global definitions {{{1 if exists("g:loaded_Mail_Re_set_vim") | finish | endif let g:loaded_Mail_Re_set_vim = 1 "=============================================================== " Options {{{2 "--------------------------------------------------------------- " Function: s:SetVar() to global or default {{{3 function! s:SetVar(var,default) if exists('b:'.a:var) | let s:{a:var} = b:{a:var} elseif exists('g:'.a:var) | let s:{a:var} = g:{a:var} else | exe "let s:{a:var} =".a:default " Rem: doing :exe to dequote a:default endif endfunction command! -nargs=+ SetVar :call SetVar() " }}}3 "--------------------------------------------------------------- SetVar mail_re_fmt 'Mimic:' " SetVar mail_re_fmt 'Re[1]:' " Possible formats : " "Re:" -- use "Re:" " "Re[]:" -- use "Re[n]:" when {n}>1 ; "Re:" when {n}=1 " "Re[1]:" -- use "Re[n]:" even when {n}>1 " "Mimic:" -- use what the correspondant used " In order to override the default, set g:mail_re_fmt or b:mail_re_fmt to one " of the previous values. SetVar mail_tag_placement 'tag_second' " Possible values : " "detect_news" -- use "Re: [TAG]" for usenet, "[TAG] Re:" otherwise " "tag_second" -- use "Re: [TAG]" ; seems the right option on usenet " accordingto trn " "tag_first" -- use "[TAG] Re:" ; seems the option used on taggued " mailing lists "--------------------------------------------------------------- delcommand SetVar " Options }}}2 "=============================================================== " Functions {{{2 "--------------------------------------------------------------- " Function: ErrorMsg(msg) {{{3 function! s:ErrorMsg(msg) if has('gui_running') call confirm(a:msg, '&Ok', 1, "Error") else echohl ErrorMsg echo a:msg echohl None endif endfunction command! -buffer -nargs=1 MailErrMsg :call ErrorMsg() " }}}3 "--------------------------------------------------------------- " Function: InsertReToSubject(Re_expr, Subject, Tag) {{{3 " Purpose: Add the Re expression to the subject according to the possible " presence of tags in the subject. " So, "[Tag] subject" will be changed to "[Tag] Re: subject" and " not "Re: [Tag] subject" function! s:InsertReToSubject(Re_expr, Subject, Tag) let tag = (''!=a:Tag) ? a:Tag . ' ' : a:Tag if "detect_news" == s:mail_tag_placement normal! 1G let l = search('^\s*$') let l = search('^Newsgroups:', 'bW') let tag_after = (0!=l) ? 1 : 0 elseif "tag_second" == s:mail_tag_placement | let tag_after = 1 elseif "tag_first" == s:mail_tag_placement | let tag_after = 0 else | let tag_after = 0 MailErrMsg "<".s:mail_tag_placement."> is not a valid value for mail_tag_placement" " behave as tag first ! endif if tag_after return 'Subject: '.a:Re_expr. tag . a:Subject else return 'Subject: '. tag .a:Re_expr. a:Subject endif " return substitute(a:Subject, '^\(\[.*\] \=\)\=', ' \1'.a:Re_expr, '') endfunction " }}}3 "--------------------------------------------------------------- " Function : MergeRe(string) {{{3 " Purpose : Substitute "Re:Re:Re:Re" by "Re:" and "Re:Re[2]" by "Re[3]" let s:tag = '\[.\{-}\]' let s:Re = '\1) ? 1 : 0 elseif "Re:" ==s:mail_re_fmt | let do_num = 0 else | MailErrMsg "<".s:mail_re_fmt."> is not a valid value for mail_re_fmt" " behave as "mimic" ! let do_num = (""!=num) ? 1 : 0 endif " Build the subject of the response {{{4 if 1==do_num " add num to n (the number of "Re:") let n = n + n2 let subject = s:InsertReToSubject('Re['.n.']: ', subject, tag) " let subject = 'Subject: '.tag.'Re['.n.']: ' .subject " let subject = 'Subject: '.'Re['.n.']: '.tag .subject else let subject = s:InsertReToSubject('Re: ', subject, tag) " let subject = 'Subject: '.tag.'Re: ' .subject " let subject = 'Subject: '.'Re: '.tag .subject endif " Finally, we return the new subject {{{4 return subject endf " }}}3 "--------------------------------------------------------------- " Function : MergeFwd(string) {{{3 " Purpose : Substitute "Fwd:Fwd:Fwd:Fwd" by "Fwd:" let s:Fwd = '\