# HG changeset patch
# User Marc Weber <marco-oweber@gmx.de>
# Date 1370016898 -7200
There are two important problems with python support:
1) you still have to use .viml in order to load python
2) when using python its you having to remember which python to use despite
  most codes may work with python and python3 interpreter.
  Using the same (only one) interpreter is very important, because
  many vims will only support one, and loading both is slower

So this patch
- adds some of the commands to python.vim syntax file
- introduces the the option loadpyplugins, which is disabled by default
  like loadplugins it tells vim to load plugin/*.py files
- Special commands like "# requires python 2.x" can be used to force Vim using
  pyfile or py3file. If such a comment is missing the pythonx python version setting
  is used to decide upon which interpreter to use. Obviously this setting
  should be set early in your .vimrc and not be touched again
  Likewise there are :pyxfile :pydo :pythonx :pyx pyxeval() to run python code
  depending on 'pythonx' setting.

diff -r 737271b5eedb -r 70a9b975218d runtime/doc/eval.txt
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1884,6 +1884,7 @@
 printf( {fmt}, {expr1}...)	String	format text
 pumvisible()			Number	whether popup menu is visible
 pyeval( {expr})			any	evaluate |Python| expression
+pyxeval( {expr})		any	See |python_x|
 py3eval( {expr})		any	evaluate |python3| expression
 range( {expr} [, {max} [, {stride}]])
 				List	items from {expr} to {max}
diff -r 737271b5eedb -r 70a9b975218d runtime/doc/if_pyth.txt
--- a/runtime/doc/if_pyth.txt
+++ b/runtime/doc/if_pyth.txt
@@ -15,6 +15,8 @@
 7. pyeval(), py3eval() Vim functions		|python-pyeval|
 8. Dynamic loading				|python-dynamic|
 9. Python 3					|python3|
+10. Python 3					|python_x|
+11. Python plugins				|python_plugins|
 
 {Vi does not have any of these commands}
 
@@ -494,8 +496,9 @@
 ==============================================================================
 7. pyeval() and py3eval() Vim functions			*python-pyeval*
 
-To facilitate bi-directional interface, you can use |pyeval()| and |py3eval()| 
-functions to evaluate Python expressions and pass their values to VimL.
+To facilitate bi-directional interface, you can use |pyeval()|, |py3eval()|
+and |pyxeval()|| functions to evaluate Python expressions and pass their
+values to VimL.
 
 ==============================================================================
 8. Dynamic loading					*python-dynamic*
@@ -576,4 +579,35 @@
 the other one from being available.
 
 ==============================================================================
+10. python_x 				*python_x*  *:pyx* *:pyfile*  *pyxdo*
+
+Because much python code can be written so that it works with python 2.6+ and
+python 3 the pyx* functions and commansd have been writen.
+They work exactly the same, but they depend on |pythonx| setting
+
+You should set this in your .vimrc to prefer python or python3 using pyx
+commands. If you change this setting at runtime you may risk that state of
+plugins (such as initialization) may be lost.
+
+|pyxfile| *python_x-special-comments*
+This command is different. You can add these comments to force Vim using
+pyfile or py3file: >
+  # requires python 2.x"
+  # requires python 3.x"
+>
+If Vim does not support than python version a silent message will be printed.
+Use |:messages| to read them
+
+==============================================================================
+11. Python plugins			*python_plugins*  *loadpyplugins*
+
+Enabling |loadpyplugins| in your .vimrc and placing .py files into your
+.vim/plugin directory whill make Vim load those py files on startup.
+|python_x| determines the py version to be used, unless
+|python_x-special-comments| are used.
+
+You have to opt-in enabling |loadpyplugins| because some people may have .py
+files in plugin/ wich should not be loaded always.
+
+==============================================================================
  vim:tw=78:ts=8:ft=help:norl:
diff -r 737271b5eedb -r 70a9b975218d runtime/doc/index.txt
--- a/runtime/doc/index.txt
+++ b/runtime/doc/index.txt
@@ -1408,6 +1408,10 @@
 |:python|	:py[thon]	execute Python command
 |:pydo|		:pyd[o]		execute Python command for each line
 |:pyfile|	:pyf[ile]	execute Python script file
+|:pyx|		:pyx		execute Python x command
+|:pythonx|	:pythonx	same as :pyx
+|:pyxdo|	:pyxd[o]	execute Python x command for each line
+|:pyxfile|	:pyxf[ile]	execute Python x script file
 |:quit|		:q[uit]		quit current window (when one window quit Vim)
 |:quitall|	:quita[ll]	quit Vim
 |:qall|		:qa[ll]		quit Vim
diff -r 737271b5eedb -r 70a9b975218d runtime/syntax/vim.vim
--- a/runtime/syntax/vim.vim
+++ b/runtime/syntax/vim.vim
@@ -19,25 +19,25 @@
 
 " regular vim commands {{{2
 syn keyword vimCommand contained	a arga[dd] ar[gs] bar bn[ext] breaka[dd] bu bw[ipeout] caddf[ile] cd cgete[xpr] checkt[ime] cmdname cnf com con[tinue] cq[uit] cw[indow] delc[ommand] diffg[et] diffpu[t] dig[raphs] dr[op] earlier el[se] endfo[r] ene[w] filename fin[d] folddoc[losed] fu[nction] gui helpg[rep] ia in j[oin] kee[pmarks] laddf[ile] lb[uffer] le[ft] lgetb[uffer] l[ist] lN lNf lo[adview] lpf[ile] luado mak[e] menut[ranslate] mks[ession] mod[e] n new noautocmd on[ly] pc[lose] popu p[rint] promptr[epl] ptn pts[elect] py[thon] quote redi[r] res[ize] ru rv[iminfo] sbf[irst] sbr[ewind] scscope sfir[st] sim[alt] sme snoreme spe spellw[rong] star stj[ump] sunme sy t tabe[dit] tabN tabp[revious] tc[l] th[row] tn to[pleft] ts[elect] una[bbreviate] unl ve vie[w] vmapc[lear] wh[ile] win[size] wqa[ll] x xmenu xterm
-syn keyword vimCommand contained	ab argd[elete] argu[ment] bd[elete] bN[ext] breakd[el] buf c cal[l] ce[nter] cg[etfile] cl cn cNf comc[lear] cope[n] cr[ewind] d d[elete] diffo diffsplit di[splay] ds[earch] ec elsei[f] endfun ex files fini[sh] foldd[oopen] g gvim helpt[ags] iabc[lear] index ju[mps] l lan lc[d] lefta[bove] lgete[xpr] ll lne lnf[ile] locale lp[revious] luafile Man mes mksp[ell] m[ove] N n[ext] noh[lsearch] o[pen] pe popu[p] P[rint] ps[earch] ptN pu[t] python3 r red[o] ret[ab] rub[y] sal[l] sbl[ast] sb[uffer] se[t] sh[ell] sl smenu snoremenu spelld[ump] sp[lit] start st[op] sunmenu syn ta tabf[ind] tabnew tabr[ewind] tcld[o] tj[ump] tN tp[revious] tu u[ndo] unlo[ckvar] verb[ose] vim[grep] vne[w] win wn[ext] w[rite] xa[ll] XMLent xunme
+syn keyword vimCommand contained	ab argd[elete] argu[ment] bd[elete] bN[ext] breakd[el] buf c cal[l] ce[nter] cg[etfile] cl cn cNf comc[lear] cope[n] cr[ewind] d d[elete] diffo diffsplit di[splay] ds[earch] ec elsei[f] endfun ex files fini[sh] foldd[oopen] g gvim helpt[ags] iabc[lear] index ju[mps] l lan lc[d] lefta[bove] lgete[xpr] ll lne lnf[ile] locale lp[revious] luafile Man mes mksp[ell] m[ove] N n[ext] noh[lsearch] o[pen] pe popu[p] P[rint] ps[earch] ptN pu[t] python3 pythonx r red[o] ret[ab] rub[y] sal[l] sbl[ast] sb[uffer] se[t] sh[ell] sl smenu snoremenu spelld[ump] sp[lit] start st[op] sunmenu syn ta tabf[ind] tabnew tabr[ewind] tcld[o] tj[ump] tN tp[revious] tu u[ndo] unlo[ckvar] verb[ose] vim[grep] vne[w] win wn[ext] w[rite] xa[ll] XMLent xunme
 syn keyword vimCommand contained	abc[lear] argdo as[cii] bel[owright] bo[tright] breakl[ist] bufdo cabc[lear] cat[ch] cex[pr] c[hange] cla[st] cN cnf[ile] comment co[py] cs de delf diffoff difft dj[ump] dsp[lit] echoe[rr] em[enu] endf[unction] exi[t] filet fir[st] foldo[pen] get h hi if intro k la lan[guage] lch[dir] let@ lg[etfile] lla[st] lnew[er] lNf[ile] loc[kmarks] lr[ewind] lv[imgrep] ma[rk] messages mkv mv nbc[lose] N[ext] nu[mber] opt[ions] ped[it] pp[op] pro pta[g] ptn[ext] pw[d] q re redr[aw] retu[rn] rubyd[o] san[dbox] sbm[odified] scrip setf[iletype] si sla[st] sn[ext] s@\n@\=\r" spe[llgood] spr[evious] startg[replace] stopi[nsert] sus[pend] sync tab tabfir[st] tabn[ext] tabs tclf[ile] tl[ast] tn[ext] tr tu[nmenu] undoj[oin] uns[ilent] ve[rsion] vimgrepa[dd] vs[plit] winc[md] wN[ext] ws[verb] x[it] XMLns xunmenu
 syn keyword vimCommand contained	abo[veleft] arge[dit] au bf[irst] bp[revious] br[ewind] b[uffer] cad cb[uffer] cf[ile] changes cl[ist] cnew[er] cNf[ile] comp[iler] count cscope debug delf[unction] DiffOrig diffthis dl[ist] dwim echom[sg] emenu* en[dif] exu[sage] filetype fix[del] for go[to] ha[rdcopy] hid[e] ij[ump] is[earch] keepa lad la[st] lcl[ose] lex[pr] lgr[ep] lli[st] lne[xt] lo lockv[ar] ls lvimgrepa[dd] marks mk mkvie[w] mz nb[key] nkf o ownsyntax pe[rl] pr profd[el] ptf[irst] ptN[ext] py qa[ll] r[ead] redraws[tatus] rew[ind] rubyf[ile] sa[rgument] sbn[ext] scripte[ncoding] setg[lobal] sig sl[eep] sN[ext] so spelli[nfo] sre[wind] star[tinsert] sts[elect] sv[iew] syncbind tabc[lose] tabl[ast] tabN[ext] ta[g] te[aroff] tm tN[ext] tr[ewind] u undol[ist] up[date] vert[ical] vi[sual] w windo wp[revious] wundo xmapc[lear] xnoreme xwininfo
-syn keyword vimCommand contained	al[l] argg[lobal] bad[d] bl[ast] br bro[wse] buffers caddb[uffer] cc cfir[st] chd[ir] clo[se] cn[ext] col[der] con cpf[ile] cstag debugg[reedy] delm[arks] diffp diffu[pdate] do e echon en endt[ry] f fin fo[ld] fu gr[ep] h[elp] his[tory] il[ist] isp[lit] keepalt laddb[uffer] lat lcs lf[ile] lgrepa[dd] lmak[e] lN[ext] loadk lol[der] lt[ag] lw[indow] mat[ch] mkdir mkv[imrc] mzf[ile] nbs[tart] nmapc[lear] ol[dfiles] p perld[o] pre[serve] prof[ile] ptj[ump] ptp[revious] py3 q[uit] rec[over] reg[isters] ri[ght] rundo sav[eas] sbN[ext] scrip[tnames] setl[ocal] sign sm[agic] sni[ff] sor[t] spellr[epall] st startr[eplace] sun[hide] sw[apname] synlist tabd[o] tabm[ove] tabo[nly] tags tf[irst] tm[enu] TOhtml try un unh[ide] v vi viu[sage] wa[ll] winp[os] wq wv[iminfo] xme xnoremenu y[ank]
+syn keyword vimCommand contained	al[l] argg[lobal] bad[d] bl[ast] br bro[wse] buffers caddb[uffer] cc cfir[st] chd[ir] clo[se] cn[ext] col[der] con cpf[ile] cstag debugg[reedy] delm[arks] diffp diffu[pdate] do e echon en endt[ry] f fin fo[ld] fu gr[ep] h[elp] his[tory] il[ist] isp[lit] keepalt laddb[uffer] lat lcs lf[ile] lgrepa[dd] lmak[e] lN[ext] loadk lol[der] lt[ag] lw[indow] mat[ch] mkdir mkv[imrc] mzf[ile] nbs[tart] nmapc[lear] ol[dfiles] p perld[o] pre[serve] prof[ile] ptj[ump] ptp[revious] py3 pydo py3do pyfile pyxfile pyx q[uit] rec[over] reg[isters] ri[ght] rundo sav[eas] sbN[ext] scrip[tnames] setl[ocal] sign sm[agic] sni[ff] sor[t] spellr[epall] st startr[eplace] sun[hide] sw[apname] synlist tabd[o] tabm[ove] tabo[nly] tags tf[irst] tm[enu] TOhtml try un unh[ide] v vi viu[sage] wa[ll] winp[os] wq wv[iminfo] xme xnoremenu y[ank]
 syn keyword vimCommand contained	ar argl[ocal] ba[ll] bm[odified] brea[k] browseset bun[load] cad[dexpr] ccl[ose] cgetb[uffer] che[ckpath] cmapc[lear] cN[ext] colo[rscheme] conf[irm] cp[revious] cuna[bbrev] del di diffpatch dig doau ea e[dit] endf endw[hile] f[ile] fina[lly] foldc[lose] fun grepa[dd] helpf[ind] i imapc[lear] iuna[bbrev] keepj[umps] lad[dexpr] later lcscope lfir[st] lh[elpgrep] lmapc[lear] lnf loadkeymap lop[en] lua ma menut mk[exrc] mo mz[scheme] ne noa omapc[lear] P po[p] prev[ious] promptf[ind] ptl[ast] ptr[ewind] pyf[ile] quita[ll] red Ren rightb[elow] ru[ntime] sba[ll] sbp[revious] scs sf[ind] sil[ent] sm[ap] sno[magic] so[urce] spellu[ndo] sta[g] 
 syn match   vimCommand contained	"\<z[-+^.=]\="
 
 " vimOptions are caught only when contained in a vimSet {{{2
 syn keyword vimOption contained	acd ambiwidth arabicshape autowriteall backupdir bdlay binary breakat bufhidden cd ci cinw co commentstring confirm cpoptions cscoperelative csre cursorcolumn delcombine diffopt ea efm ep et fdc fdo ffs fk foldcolumn foldmethod formatoptions gd go guifont guitabtooltip hid hkp iconstring imd include inex isi js kp linebreak lm lz matchpairs maxmemtot mkspellmem mod mousef mouset nf oft pa path pheader previewheight printmbcharset pvw remap rl ruf sc scrollopt selectmode shellpipe shellxquote showcmd sidescroll smartindent sol spellsuggest sr stal sua swf syntax taglength tbidi terse tildeop tl tpm ttimeoutlen ttymouse udf undoreload vbs vi vop wcm whichwrap wildignore winaltkeys winminwidth wmnu write
 syn keyword vimOption contained	ai ambw ari aw backupext beval biosk brk buflisted cdpath cin cinwords cocu compatible consk cpt cscopetag cst cursorline dex digraph ead ei equalalways eventignore fde fdt fileencoding fkmap foldenable foldminlines formatprg gdefault gp guifontset helpfile hidden hl ignorecase imdisable includeexpr inf isident key langmap lines lmap ma matchtime mco ml modeline mousefocus mousetime nrformats ofu para pdev pi previewwindow printmbfont qe report rlc ruler scb scs sessionoptions shellquote shiftround showfulltag sidescrolloff smarttab sp spf srr startofline suffixes switchbuf ta tagrelative tbis textauto timeout tm tr ttm ttyscroll udir updatecount vdir viewdir wa wd wi wildignorecase window winwidth wmw writeany
-syn keyword vimOption contained	akm anti arshape awa backupskip bex bioskey browsedir buftype cedit cindent clipboard cole complete conskey crb cscopetagorder csto cwh dg dip eadirection ek equalprg ex fdi fen fileencodings flp foldexpr foldnestmax fp gfm grepformat guifontwide helpheight highlight hlg im imi incsearch infercase isk keymap langmenu linespace loadplugins macatsui maxcombine mef mls modelines mousehide mp nu omnifunc paragraphs penc pm printdevice printoptions quoteescape restorescreen rnu rulerformat scr sect sft shellredir shiftwidth showmatch siso smc spc spl ss statusline suffixesadd sws tabline tags tbs textmode timeoutlen to ts tty ttytype ul updatetime ve viewoptions wak weirdinvert wic wildmenu winfixheight wiv wop writebackup
-syn keyword vimOption contained	al antialias autochdir background balloondelay bexpr bk bs casemap cf cink cmdheight colorcolumn completefunc copyindent cryptmethod cscopeverbose csverb debug dict dir eb enc errorbells expandtab fdl fenc fileformat fml foldignore foldopen fs gfn grepprg guiheadroom helplang history hls imactivatekey iminsert inde insertmode iskeyword keymodel laststatus lisp lpl magic maxfuncdepth menuitems mm modifiable mousem mps number opendevice paste pex pmbcs printencoding prompt rdt revins ro runtimepath scroll sections sh shellslash shm showmode sj smd spell splitbelow ssl stl sw sxe tabpagemax tagstack tenc textwidth title toolbar tsl ttybuiltin tw undodir ur verbose viminfo warn wfh wig wildmode winfixwidth wiw wrap writedelay
+syn keyword vimOption contained	akm anti arshape awa backupskip bex bioskey browsedir buftype cedit cindent clipboard cole complete conskey crb cscopetagorder csto cwh dg dip eadirection ek equalprg ex fdi fen fileencodings flp foldexpr foldnestmax fp gfm grepformat guifontwide helpheight highlight hlg im imi incsearch infercase isk keymap langmenu linespace loadplugins loadpyplugins macatsui maxcombine mef mls modelines mousehide mp nu omnifunc paragraphs penc pm printdevice printoptions quoteescape restorescreen rnu rulerformat scr sect sft shellredir shiftwidth showmatch siso smc spc spl ss statusline suffixesadd sws tabline tags tbs textmode timeoutlen to ts tty ttytype ul updatetime ve viewoptions wak weirdinvert wic wildmenu winfixheight wiv wop writebackup
+syn keyword vimOption contained	al antialias autochdir background balloondelay bexpr bk bs casemap cf cink cmdheight colorcolumn completefunc copyindent cryptmethod cscopeverbose csverb debug dict dir eb enc errorbells expandtab fdl fenc fileformat fml foldignore foldopen fs gfn grepprg guiheadroom helplang history hls imactivatekey iminsert inde insertmode iskeyword keymodel laststatus lisp lpl lpypl magic maxfuncdepth menuitems mm modifiable mousem mps number opendevice paste pex pmbcs printencoding prompt rdt revins ro runtimepath scroll sections sh shellslash shm showmode sj smd spell splitbelow ssl stl sw sxe tabpagemax tagstack tenc textwidth title toolbar tsl ttybuiltin tw undodir ur verbose viminfo warn wfh wig wildmode winfixwidth wiw wrap writedelay
 syn keyword vimOption contained	aleph ar autoindent backspace ballooneval bg bkc bsdir cb cfu cinkeys cmdwinheight columns completeopt cot cscopepathcomp cspc cuc deco dictionary directory ed encoding errorfile exrc fdls fencs fileformats fmr foldlevel foldtext fsync gfs gtl guioptions hf hk hlsearch imak ims indentexpr is isp keywordprg lazyredraw lispwords ls makeef maxmapdepth mfd mmd modified mousemodel msm numberwidth operatorfunc pastetoggle pexpr pmbfn printexpr pt readonly ri rs sb scrollbind secure shcf shelltemp shortmess showtabline slm sn spellcapcheck splitright ssop stmp swapfile sxq tabstop tal term tf titlelen toolbariconsize tsr ttyfast tx undofile ut verbosefile virtualedit wb wfw wildchar wildoptions winheight wm wrapmargin ws
 syn keyword vimOption contained	allowrevins arab autoread backup balloonexpr bh bl bsk cc ch cino cmp com concealcursor cp cscopeprg csprg cul def diff display edcompatible endofline errorformat fcl fdm fex filetype fo foldlevelstart formatexpr ft gfw gtt guipty hh hkmap ic imc imsearch indentkeys isf isprint km lbr list lsp makeprg maxmem mh mmp more mouses mzq nuw opfunc patchexpr pfn popt printfont pumheight redrawtime rightleft rtp sbo scrolljump sel shell shelltype shortname shq sm so spellfile spr st sts swapsync syn tag tb termbidi tgst titleold top ttimeout ttym uc undolevels vb vfile visualbell wc wh wildcharm wim winminheight wmh wrapscan ww
 syn keyword vimOption contained	altkeymap arabic autowrite backupcopy bdir bin bomb bt ccv charconvert cinoptions cms comments conceallevel cpo cscopequickfix csqf cursorbind define diffexpr dy ef eol esckeys fcs fdn ff fillchars foldclose foldmarker formatlistpat gcr ghr guicursor guitablabel hi hkmapp icon imcmdline inc indk isfname joinspaces kmp lcs listchars lw mat maxmempattern mis mmt mouse mouseshape mzquantum odev osfiletype patchmode ph preserveindent printheader pvh relativenumber rightleftcmd ru sbr scrolloff selection shellcmdflag shellxescape showbreak si smartcase softtabstop spelllang sps sta su swb synmaxcol tagbsearch tbi termencoding thesaurus titlestring 
 
 " vimOptions: These are the turn-off setting variants {{{2
-syn keyword vimOption contained	noacd noallowrevins noantialias noarabic noarshape noautoread noaw noballooneval nobinary nobk nobuflisted nocin noconfirm nocopyindent nocscopetag nocsverb nocursorbind nodeco nodiff noeb noek noequalalways noesckeys noex noexrc nofk nofoldenable nogdefault nohid nohk nohkmapp nohls noic noignorecase noimc noimd noincsearch noinfercase nois nojs nolbr nolisp noloadplugins nolz nomacatsui nomh nomod nomodifiable nomore nomousefocus nonu noodev nopaste nopreserveindent noprompt noreadonly noremap norevins norightleft nornu nors noruler nosc noscrollbind nosecure noshellslash noshiftround noshowcmd noshowmatch nosi nosmartcase nosmarttab nosn nospell nosplitright nosr nosta nostmp noswf notagbsearch notagstack notbidi notermbidi notextauto notf notildeop notitle notop nottimeout nottyfast novb nowa nowb nowfh nowildignorecase* * nowinfixheight nowiv nowrap nowrite nowritebackup
-syn keyword vimOption contained	noai noaltkeymap noar noarabicshape noautochdir noautowrite noawa nobeval nobiosk nobl nocf nocindent noconsk nocp nocscopeverbose nocuc nocursorcolumn nodelcombine nodigraph noed noendofline noerrorbells noet noexpandtab nofen nofkmap nogd noguipty nohidden nohkmap nohkp nohlsearch noicon noim noimcmdline noimdisable noinf noinsertmode nojoinspaces nolazyredraw nolinebreak nolist nolpl noma nomagic noml nomodeline nomodified nomousef nomousehide nonumber noopendevice nopi nopreviewwindow nopvw norelativenumber norestorescreen nori norl noro noru nosb noscb noscs nosft noshelltemp noshortname noshowfulltag noshowmode nosm nosmartindent nosmd nosol nosplitbelow nospr nossl nostartofline noswapfile nota notagrelative notbi notbs noterse notextmode notgst notimeout noto notr nottybuiltin notx novisualbell nowarn noweirdinvert nowfw nowildmenu nowinfixwidth nowmnu nowrapscan nowriteany nows
+syn keyword vimOption contained	noacd noallowrevins noantialias noarabic noarshape noautoread noaw noballooneval nobinary nobk nobuflisted nocin noconfirm nocopyindent nocscopetag nocsverb nocursorbind nodeco nodiff noeb noek noequalalways noesckeys noex noexrc nofk nofoldenable nogdefault nohid nohk nohkmapp nohls noic noignorecase noimc noimd noincsearch noinfercase nois nojs nolbr nolisp noloadplugins noloadpyplugins nolz nomacatsui nomh nomod nomodifiable nomore nomousefocus nonu noodev nopaste nopreserveindent noprompt noreadonly noremap norevins norightleft nornu nors noruler nosc noscrollbind nosecure noshellslash noshiftround noshowcmd noshowmatch nosi nosmartcase nosmarttab nosn nospell nosplitright nosr nosta nostmp noswf notagbsearch notagstack notbidi notermbidi notextauto notf notildeop notitle notop nottimeout nottyfast novb nowa nowb nowfh nowildignorecase* * nowinfixheight nowiv nowrap nowrite nowritebackup
+syn keyword vimOption contained	noai noaltkeymap noar noarabicshape noautochdir noautowrite noawa nobeval nobiosk nobl nocf nocindent noconsk nocp nocscopeverbose nocuc nocursorcolumn nodelcombine nodigraph noed noendofline noerrorbells noet noexpandtab nofen nofkmap nogd noguipty nohidden nohkmap nohkp nohlsearch noicon noim noimcmdline noimdisable noinf noinsertmode nojoinspaces nolazyredraw nolinebreak nolist nolpl nopypl noma nomagic noml nomodeline nomodified nomousef nomousehide nonumber noopendevice nopi nopreviewwindow nopvw norelativenumber norestorescreen nori norl noro noru nosb noscb noscs nosft noshelltemp noshortname noshowfulltag noshowmode nosm nosmartindent nosmd nosol nosplitbelow nospr nossl nostartofline noswapfile nota notagrelative notbi notbs noterse notextmode notgst notimeout noto notr nottybuiltin notx novisualbell nowarn noweirdinvert nowfw nowildmenu nowinfixwidth nowmnu nowrapscan nowriteany nows
 syn keyword vimOption contained	noakm noanti noarab noari noautoindent noautowriteall nobackup nobin nobioskey nobomb noci nocompatible noconskey nocrb nocst nocul nocursorline nodg noea noedcompatible noeol 
 
 " vimOptions: These are the invertible variants {{{2
@@ -75,7 +75,7 @@
 " Function Names {{{2
 syn keyword vimFuncName contained	abs and argidx atan browsedir bufloaded bufwinnr call char2nr col complete_check cos cscope_connection delete diff_hlID eval exists expr8 filereadable finddir floor fnamemodify foldlevel foreground get getchar getcmdpos getfontname getftime getloclist getpos getregtype getwinposx glob has_key histadd histnr hostname index inputlist inputsecret isdirectory join libcall line2byte log map match matchdelete matchstr mkdir nextnonblank pathshorten printf pyeval reltime remote_foreground remote_read remove repeat reverse search searchpair searchpos serverlist setcmdpos setloclist setpos setreg settabwinvar shellescape simplify sinh soundfold spellsuggest sqrt str2nr strdisplaywidth stridx strlen strridx strwidth substitute synID synIDtrans system tabpagenr tagfiles tan tempname toupper trunc undofile values visualmode wincol winline winrestcmd winsaveview writefile
 syn keyword vimFuncName contained	acos append argv atan2 bufexists bufname byte2line ceil cindent complete confirm cosh cursor did_filetype empty eventhandler exp extend filewritable findfile fmod foldclosed foldtext function getbufline getcharmod getcmdtype getfperm getftype getmatches getqflist gettabvar getwinposy globpath haslocaldir histdel hlexists iconv input inputrestore insert islocked keys libcallnr lispindent log10 maparg matchadd matchend max mode nr2char pow pumvisible range reltimestr remote_peek remote_send rename resolve round searchdecl searchpairpos server2client setbufvar setline setmatches setqflist settabvar setwinvar shiftwidth sin sort spellbadword split str2float strchars strftime string strpart strtrans submatch synconcealed synIDattr synstack tabpagebuflist tabpagewinnr taglist tanh tolower tr type undotree virtcol winbufnr winheight winnr winrestview winwidth xor
-syn keyword vimFuncName contained	add argc asin browse buflisted bufnr byteidx changenr clearmatches complete_add copy count deepcopy diff_filler escape executable expand feedkeys filter float2nr fnameescape foldclosedend foldtextresult garbagecollect getbufvar getcmdline getcwd getfsize getline getpid getreg gettabwinvar getwinvar has hasmapto histget hlID indent inputdialog inputsave invert items len line localtime luaeval mapcheck matcharg matchlist min mzeval or prevnonblank py3eval readfile remote_expr 
+syn keyword vimFuncName contained	add argc asin browse buflisted bufnr byteidx changenr clearmatches complete_add copy count deepcopy diff_filler escape executable expand feedkeys filter float2nr fnameescape foldclosedend foldtextresult garbagecollect getbufvar getcmdline getcwd getfsize getline getpid getreg gettabwinvar getwinvar has hasmapto histget hlID indent inputdialog inputsave invert items len line localtime luaeval mapcheck matcharg matchlist min mzeval or prevnonblank py3eval readfile remote_expr  pyxeval
 
 "--- syntax here and above generated by mkvimvim ---
 " Special Vim Highlighting (not automatic) {{{1
diff -r 737271b5eedb -r 70a9b975218d src/eval.c
--- a/src/eval.c
+++ b/src/eval.c
@@ -639,6 +639,9 @@
 #ifdef FEAT_PYTHON
 static void f_pyeval __ARGS((typval_T *argvars, typval_T *rettv));
 #endif
+#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
+static void f_pyxeval __ARGS((typval_T *argvars, typval_T *rettv));
+#endif
 static void f_range __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_readfile __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_reltime __ARGS((typval_T *argvars, typval_T *rettv));
@@ -8024,6 +8027,9 @@
 #ifdef FEAT_PYTHON
     {"pyeval",		1, 1, f_pyeval},
 #endif
+#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
+    {"pyxeval",		1, 1, f_pyxeval},
+#endif
     {"range",		1, 3, f_range},
     {"readfile",	1, 3, f_readfile},
     {"reltime",		0, 2, f_reltime},
@@ -14583,6 +14589,24 @@
 }
 #endif
 
+#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
+/*
+ * "pyxeval()" function
+ */
+    static void
+f_pyxeval(argvars, rettv)
+    typval_T	*argvars;
+    typval_T	*rettv;
+{
+#ifdef FEAT_PYTHON
+    if (p_pyx == 2) f_pyeval(argvars, rettv);
+#endif
+#ifdef FEAT_PYTHON3
+    if (p_pyx == 3) f_py3eval(argvars, rettv);
+#endif
+}
+#endif
+
 /*
  * "range()" function
  */
diff -r 737271b5eedb -r 70a9b975218d src/ex_cmds.h
--- a/src/ex_cmds.h
+++ b/src/ex_cmds.h
@@ -751,6 +751,14 @@
 			RANGE|EXTRA|NEEDARG|CMDWIN),
 EX(CMD_py3file,		"py3file",	ex_py3file,
 			RANGE|FILE1|NEEDARG|CMDWIN),
+EX(CMD_pyx,		"pyx",		ex_pyx,
+			RANGE|EXTRA|NEEDARG|CMDWIN),
+EX(CMD_pyxdo,		"pyxdo",	ex_pyxdo,
+			RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN),
+EX(CMD_pythonx,		"pythonx",	ex_pyx,
+			RANGE|EXTRA|NEEDARG|CMDWIN),
+EX(CMD_pyxfile,		"pyxfile",	ex_pyxfile,
+			RANGE|FILE1|NEEDARG|CMDWIN),
 EX(CMD_quit,		"quit",		ex_quit,
 			BANG|TRLBAR|CMDWIN),
 EX(CMD_quitall,		"quitall",	ex_quit_all,
diff -r 737271b5eedb -r 70a9b975218d src/ex_cmds2.c
--- a/src/ex_cmds2.c
+++ b/src/ex_cmds2.c
@@ -2701,6 +2701,135 @@
     return do_in_runtimepath(name, all, source_callback, NULL);
 }
 
+
+#if defined (FEAT_PYTHON3) || defined (FEAT_PYTHON)
+
+// Does a file contain one of the following strings at the beginning of any
+// line?
+// "# requires python 2.x"  => returns 2
+// "# requires python 3.x"  => returns 3
+// otherwise return 0
+int requires_py_version(char_u * filename)
+{
+   FILE *file = fopen ( filename, "r" );
+   int requires_py_version = 0;
+   if ( file != NULL )
+   {
+      // if a line is longer than 2048 characters worst thing which can
+      // happen is that "# requires .." gets matched at multiples of 2048 bytes
+      char line [ 2048 ]; 
+      while ( fgets ( line, sizeof line, file ) != NULL )
+      {
+         line[21] = '\0';
+         if (strcmp("# requires python 2.x", line) == 0) {
+           requires_py_version = 2;
+           break;
+         }
+         if (strcmp("# requires python 3.x", line) == 0) {
+           requires_py_version = 3;
+           break;
+         }
+      }
+      fclose ( file );
+   }
+   return requires_py_version;
+}
+
+
+/*
+ * source a python file using the requested python version (:pyxfile or on startup)
+ */
+void source_pyx_file(fname)
+    char_u	*fname;
+{
+    int v = requires_py_version(fname);
+    char msg_buf[2048];
+    if (v == 0){ // user didn't choose a preference, arbitrarely prefer 2.x
+        v = p_pyx;
+    }
+
+    // now source, if required python version is not supported show
+    // unobstrusive message
+    exarg_T ex;
+    vim_memset(&ex, 0, sizeof(ex));
+    ex.arg = fname;
+    ex.cmd = v == 2 ? "pyfile" : "pyfile3";
+
+    if (v == 2){
+#ifdef FEAT_PYTHON
+        ex_pyfile(&ex);
+#else
+	vim_snprintf((char *)msg_buf, sizeof(msg_buf), "required python version 2.x not supported, ignoring file: %s", fname);
+        MSG(&msg_buf[0]);
+#endif
+        return;
+    }
+    if (v == 3){
+#ifdef FEAT_PYTHON3
+        ex_py3file(&ex);
+#else
+	vim_snprintf((char *)msg_buf, sizeof(msg_buf), "required python version 3.x not supported, ignoring file: %s", fname);
+        MSG(&msg_buf[0]);
+#endif
+        return;
+    }
+    // this should never happen ..
+    vim_snprintf((char *)msg_buf, sizeof(msg_buf), "no python not supported, ignoring file: %s", fname);
+    MSG(&msg_buf[0]);
+}
+
+static void source_callback_py __ARGS((char_u *fname, void *cookie));
+
+    static void
+source_callback_py(fname, cookie)
+    char_u	*fname;
+    void	*cookie UNUSED;
+{
+    source_pyx_file(fname);
+}
+
+// see source_runtime, same for .py files
+    int
+source_runtime_py(name, all)
+    char_u	*name;
+    int		all;
+{
+    return do_in_runtimepath(name, all, source_callback_py, NULL);
+}
+
+/*
+ * ":pyxfile {fname}"
+ */
+    void
+ex_pyxfile(eap)
+    exarg_T	*eap;
+{
+    source_pyx_file(eap->arg);
+}
+
+
+void ex_pyx __ARGS((exarg_T *eap))
+{
+#ifdef FEAT_PYTHON
+  if (p_pyx == 2) ex_python(eap);
+#endif
+#ifdef FEAT_PYTHON3
+  if (p_pyx == 3) ex_py3(eap);
+#endif
+}
+void ex_pyxdo __ARGS((exarg_T *eap))
+{
+#ifdef FEAT_PYTHON
+  if (p_pyx == 2) ex_pydo(eap);
+#endif
+#ifdef FEAT_PYTHON3
+  if (p_pyx == 3) ex_py3do(eap);
+#endif
+}
+
+#endif
+
+
 /*
  * Find "name" in 'runtimepath'.  When found, invoke the callback function for
  * it: callback(fname, "cookie")
diff -r 737271b5eedb -r 70a9b975218d src/ex_docmd.c
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -276,6 +276,11 @@
 # define ex_py3do		ex_ni
 # define ex_py3file		ex_ni
 #endif
+#if (!defined(FEAT_PYTHON) && (!defined(FEAT_PYTHON3)))
+# define ex_pyxfile		ex_ni
+# define ex_pyx			ex_ni
+# define ex_pyxdo		ex_ni
+#endif
 #ifndef FEAT_TCL
 # define ex_tcl			ex_script_ni
 # define ex_tcldo		ex_ni
diff -r 737271b5eedb -r 70a9b975218d src/main.c
--- a/src/main.c
+++ b/src/main.c
@@ -620,6 +620,17 @@
     }
 #endif
 
+#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
+    if (p_lpypl)
+    {
+# ifdef VMS	/* Somehow VMS doesn't handle the "**". */
+	source_runtime_py((char_u *)"plugin/*.py", TRUE);
+# else
+	source_runtime_py((char_u *)"plugin/**/*.py", TRUE);
+# endif
+    }
+#endif
+
 #ifdef FEAT_DIFF
     /* Decide about window layout for diff mode after reading vimrc. */
     if (params.diff_mode && params.window_layout == 0)
@@ -1865,6 +1876,11 @@
 		}
 		else if (STRNICMP(argv[0] + argv_idx, "noplugin", 8) == 0)
 		    p_lpl = FALSE;
+#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
+		else if (STRNICMP(argv[0] + argv_idx, "nopyplugin", 10) == 0)
+		    p_lpypl = FALSE;
+#endif
+
 		else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0)
 		{
 		    want_argument = TRUE;
@@ -2932,7 +2948,12 @@
 		use_gvimrc = parmp->use_vimrc;
 #endif
 	    if (parmp->use_vimrc[2] == 'N')
+            {
 		p_lpl = FALSE;		    /* don't load plugins either */
+#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
+		p_lpypl = FALSE;	    /* don't load python plugins either */
+#endif
+            }
 	}
 	else
 	{
diff -r 737271b5eedb -r 70a9b975218d src/option.c
--- a/src/option.c
+++ b/src/option.c
@@ -1715,6 +1715,14 @@
     {"loadplugins", "lpl",  P_BOOL|P_VI_DEF,
 			    (char_u *)&p_lpl, PV_NONE,
 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
+    {"loadpyplugins", "lpypl",  P_BOOL|P_VI_DEF,
+#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
+			    (char_u *)&p_lpypl, PV_NONE,
+#else
+			    NULL, PV_NONE,
+#endif
+                            // not enabling this feature, people may have .py plugins in .py
+			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
 #ifdef FEAT_GUI_MAC
     {"macatsui",    NULL,   P_BOOL|P_VI_DEF|P_RCLR,
 			    (char_u *)&p_macatsui, PV_NONE,
@@ -2055,6 +2063,23 @@
 			    (char_u *)NULL, PV_NONE,
 #endif
 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
+    {"pythonx",   "pyx",   P_NUM,
+
+#ifdef FEAT_PYTHON
+#define DEFAULT_PYTHON_V 2
+#elif defined(FEAT_PYTHON3)
+#define DEFAULT_PYTHON_V 3
+#else
+#define DEFAULT_PYTHON_V 0
+#endif
+
+#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
+			    (char_u *)&p_pyx, PV_NONE,
+#else
+			    (char_u *)NULL, PV_NONE,
+#endif
+                            {(char_u *)DEFAULT_PYTHON_V, (char_u *)DEFAULT_PYTHON_V} SCRIPTID_INIT},
+
     {"quoteescape", "qe",   P_STRING|P_ALLOCED|P_VI_DEF,
 #ifdef FEAT_TEXTOBJ
 			    (char_u *)&p_qe, PV_QE,
diff -r 737271b5eedb -r 70a9b975218d src/option.h
--- a/src/option.h
+++ b/src/option.h
@@ -392,6 +392,9 @@
 EXTERN char_u	*p_cot;		/* 'completeopt' */
 EXTERN long	p_ph;		/* 'pumheight' */
 #endif
+#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
+EXTERN long	p_pyx;		/* 'pythonx' */
+#endif
 EXTERN char_u	*p_cpo;		/* 'cpoptions' */
 #ifdef FEAT_CSCOPE
 EXTERN char_u	*p_csprg;	/* 'cscopeprg' */
@@ -593,6 +596,9 @@
 
 EXTERN int	p_lz;		/* 'lazyredraw' */
 EXTERN int	p_lpl;		/* 'loadplugins' */
+#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
+EXTERN int	p_lpypl;	/* 'loadpyplugins' */
+#endif
 #ifdef FEAT_GUI_MAC
 EXTERN int	p_macatsui;	/* 'macatsui' */
 #endif
diff -r 737271b5eedb -r 70a9b975218d src/proto/ex_cmds2.pro
--- a/src/proto/ex_cmds2.pro
+++ b/src/proto/ex_cmds2.pro
@@ -59,9 +59,14 @@
 void ex_compiler __ARGS((exarg_T *eap));
 void ex_runtime __ARGS((exarg_T *eap));
 int source_runtime __ARGS((char_u *name, int all));
+int source_runtime_py __ARGS((char_u *name, int all));
 int do_in_runtimepath __ARGS((char_u *name, int all, void (*callback)(char_u *fname, void *ck), void *cookie));
 void ex_options __ARGS((exarg_T *eap));
 void ex_source __ARGS((exarg_T *eap));
+void ex_pyxfile __ARGS((exarg_T *eap));
+void ex_pyx __ARGS((exarg_T *eap));
+void ex_pyxdo __ARGS((exarg_T *eap));
+void ex_pyxfile __ARGS((exarg_T *eap));
 linenr_T *source_breakpoint __ARGS((void *cookie));
 int *source_dbg_tick __ARGS((void *cookie));
 int source_level __ARGS((void *cookie));
