diff --git a/vimfiles.stefan/plugin/tools.vim b/vimfiles.stefan/plugin/tools.vim index 3a8860a..c92b6dc 100644 --- a/vimfiles.stefan/plugin/tools.vim +++ b/vimfiles.stefan/plugin/tools.vim @@ -34,16 +34,18 @@ function GetAllMakefiles(...) let makefilePaths = [] " Get Makefiles from g:WA or ArgLead - let path = g:WA - if a:0 == 3 - let ArgLead = a:1 - let CmdLine = a:2 - let CursorPos = a:3 - if ArgLead != '' - let path = expand(ArgLead) + if exists('g:WA') + let path = g:WA + if a:0 == 3 + let ArgLead = a:1 + let CmdLine = a:2 + let CursorPos = a:3 + if ArgLead != '' + let path = expand(ArgLead) + endif endif + let makefilePaths += s:GetAllMakefilesInPath(path) endif - let makefilePaths += s:GetAllMakefilesInPath(path) if makefilePaths == [] " Get Projects from project.txt @@ -356,11 +358,13 @@ function s:AddAllKnownProjectsToMenu() endfor " Projects in g:WA - exec 'anoremenu '. s:VimSuiteMenuName. - \'&Project.-sep3- :' - for makefilePath in s:GetAllMakefilesInPath(g:WA) - call s:AddMakefileToProjectMenu(makefilePath) - endfor + if exists('g:WA') + exec 'anoremenu '. s:VimSuiteMenuName. + \'&Project.-sep3- :' + for makefilePath in s:GetAllMakefilesInPath(g:WA) + call s:AddMakefileToProjectMenu(makefilePath) + endfor + endif endfunction " function s:InitProjectMenu() diff --git a/vimfiles/plugin/getscriptPlugin.vim b/vimfiles/plugin/getscriptPlugin.vim index cea6e93..2464c98 100644 --- a/vimfiles/plugin/getscriptPlugin.vim +++ b/vimfiles/plugin/getscriptPlugin.vim @@ -1,38 +1,38 @@ -" --------------------------------------------------------------------- -" getscriptPlugin.vim -" Author: Charles E. Campbell, Jr. -" Date: Jul 18, 2006 -" Installing: :help glvs-install -" Usage: :help glvs -" -" GetLatestVimScripts: 642 1 :AutoInstall: GetLatestVimScripts.vim -" -" (Rom 15:11 WEB) Again, "Praise the Lord, all you Gentiles! Let -" all the peoples praise Him." -" --------------------------------------------------------------------- -" Initialization: {{{1 -" if you're sourcing this file, surely you can't be -" expecting vim to be in its vi-compatible mode -if &cp || exists("g:loaded_getscriptPlugin") - if &verbose - echo "GetLatestVimScripts is not vi-compatible; not loaded (you need to set nocp)" - endif - finish -endif -let g:loaded_getscriptPlugin = 1 -let s:keepfo = &fo -let s:keepcpo = &cpo -set cpo&vim - -" --------------------------------------------------------------------- -" Public Interface: {{{1 -com! -nargs=0 GetLatestVimScripts call getscript#GetLatestVimScripts() -com! -nargs=0 GetScripts call getscript#GetLatestVimScripts() -silent! com -nargs=0 GLVS call getscript#GetLatestVimScripts() - -" Restore Options: {{{1 -let &fo = s:keepfo -let &cpo= s:keepcpo - -" --------------------------------------------------------------------- -" vim: ts=8 sts=2 fdm=marker nowrap +" --------------------------------------------------------------------- +" getscriptPlugin.vim +" Author: Charles E. Campbell, Jr. +" Date: Jul 18, 2006 +" Installing: :help glvs-install +" Usage: :help glvs +" +" GetLatestVimScripts: 642 1 :AutoInstall: GetLatestVimScripts.vim +" +" (Rom 15:11 WEB) Again, "Praise the Lord, all you Gentiles! Let +" all the peoples praise Him." +" --------------------------------------------------------------------- +" Initialization: {{{1 +" if you're sourcing this file, surely you can't be +" expecting vim to be in its vi-compatible mode +if &cp || exists("g:loaded_getscriptPlugin") + if &verbose + echo "GetLatestVimScripts is not vi-compatible; not loaded (you need to set nocp)" + endif + finish +endif +let g:loaded_getscriptPlugin = 1 +let s:keepfo = &fo +let s:keepcpo = &cpo +set cpo&vim + +" --------------------------------------------------------------------- +" Public Interface: {{{1 +com! -nargs=0 GetLatestVimScripts call getscript#GetLatestVimScripts() +com! -nargs=0 GetScripts call getscript#GetLatestVimScripts() +silent! com -nargs=0 GLVS call getscript#GetLatestVimScripts() + +" Restore Options: {{{1 +let &fo = s:keepfo +let &cpo= s:keepcpo + +" --------------------------------------------------------------------- +" vim: ts=8 sts=2 fdm=marker nowrap diff --git a/vimfiles/plugin/netrwPlugin.vim b/vimfiles/plugin/netrwPlugin.vim index 9cb9ad5..152eb32 100644 --- a/vimfiles/plugin/netrwPlugin.vim +++ b/vimfiles/plugin/netrwPlugin.vim @@ -1,180 +1,180 @@ -" netrwPlugin.vim: Handles file transfer and remote directory listing across a network -" PLUGIN SECTION -" Date: Jan 05, 2007 -" Maintainer: Charles E Campbell, Jr -" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim -" Copyright: Copyright (C) 1999-2005 Charles E. Campbell, Jr. {{{1 -" Permission is hereby granted to use and distribute this code, -" with or without modifications, provided that this copyright -" notice is copied with it. Like anything else that's free, -" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided -" *as is* and comes with no warranty of any kind, either -" expressed or implied. By using this plugin, you agree that -" in no event will the copyright holder be liable for any damages -" resulting from the use of this software. -" -" But be doers of the Word, and not only hearers, deluding your own selves {{{1 -" (James 1:22 RSV) -" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- - -" --------------------------------------------------------------------- -" Load Once: {{{1 -if &cp || exists("g:loaded_netrwPlugin") - finish -endif -let g:loaded_netrwPlugin = 1 -let s:keepcpo = &cpo -if v:version < 700 - echohl WarningMsg | echo "***netrw*** you need vim version 7.0 for this version of netrw" | echohl None - finish -endif -let s:keepcpo= &cpo -set cpo&vim - -" --------------------------------------------------------------------- -" Public Interface: {{{1 - -" Local Browsing: {{{2 -augroup FileExplorer - au! - au BufEnter * silent! call s:LocalBrowse(expand("")) - if has("win32") || has("win95") || has("win64") || has("win16") - au BufEnter .* silent! call s:LocalBrowse(expand("")) - endif -augroup END - -" Network Browsing Reading Writing: {{{2 -augroup Network - au! - if has("win32") || has("win95") || has("win64") || has("win16") - au BufReadCmd file://* exe "silent doau BufReadPre ".netrw#RFC2396(expand(""))|exe 'e '.substitute(netrw#RFC2396(expand("")),'file://\(.*\)','\1',"")|exe "silent doau BufReadPost ".netrw#RFC2396(expand("")) - else - au BufReadCmd file://* exe "silent doau BufReadPre ".netrw#RFC2396(expand(""))|exe 'e '.substitute(netrw#RFC2396(expand("")),'file://\(.*\)','\1',"")|exe "silent doau BufReadPost ".netrw#RFC2396(expand("")) - au BufReadCmd file://localhost/* exe "silent doau BufReadPre ".netrw#RFC2396(expand(""))|exe 'e '.substitute(netrw#RFC2396(expand("")),'file://localhost/\(.*\)','\1',"")|exe "silent doau BufReadPost ".netrw#RFC2396(expand("")) - endif - au BufReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "silent doau BufReadPre ".expand("")|exe '2Nread "'.expand("").'"'|exe "silent doau BufReadPost ".expand("") - au FileReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "silent doau FileReadPre ".expand("")|exe 'Nread "' .expand("").'"'|exe "silent doau FileReadPost ".expand("") - au BufWriteCmd ftp://*,rcp://*,scp://*,dav://*,rsync://*,sftp://* exe "silent doau BufWritePre ".expand("")|exe 'Nwrite "' .expand("").'"'|exe "silent doau BufWritePost ".expand("") - au FileWriteCmd ftp://*,rcp://*,scp://*,dav://*,rsync://*,sftp://* exe "silent doau FileWritePre ".expand("")|exe "'[,']".'Nwrite "' .expand("").'"'|exe "silent doau FileWritePost ".expand("") - try - au SourceCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe 'Nsource "'.expand("").'"' - catch /^Vim\%((\a\+)\)\=:E216/ - au SourcePre ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe 'Nsource "'.expand("").'"' - endtry -augroup END - -" Commands: :Nread, :Nwrite, :NetUserPass {{{2 -com! -count=1 -nargs=* Nread call netrw#NetSavePosn()call netrw#NetRead(,)call netrw#NetRestorePosn() -com! -range=% -nargs=* Nwrite call netrw#NetSavePosn(),call netrw#NetWrite()call netrw#NetRestorePosn() -com! -nargs=* NetUserPass call NetUserPass() -com! -nargs=+ Ncopy call netrw#NetObtain() -com! -nargs=* Nsource call netrw#NetSavePosn()call netrw#NetSource()call netrw#NetRestorePosn() - -" Commands: :Explore, :Sexplore, Hexplore, Vexplore {{{2 -com! -nargs=* -bar -bang -count=0 -complete=dir Explore call netrw#Explore(,0,0+0,) -com! -nargs=* -bar -bang -count=0 -complete=dir Sexplore call netrw#Explore(,1,0+0,) -com! -nargs=* -bar -bang -count=0 -complete=dir Hexplore call netrw#Explore(,1,2+0,) -com! -nargs=* -bar -bang -count=0 -complete=dir Vexplore call netrw#Explore(,1,4+0,) -com! -nargs=* -bar -count=0 -complete=dir Texplore call netrw#Explore(,0,6 ,) -com! -nargs=* -bar -bang Nexplore call netrw#Explore(-1,0,0,) -com! -nargs=* -bar -bang Pexplore call netrw#Explore(-2,0,0,) - -" Commands: NetrwSettings {{{2 -com! -nargs=0 NetrwSettings :call netrwSettings#NetrwSettings() - -" Maps: -if !exists("g:netrw_nogx") && maparg('g','n') == "" - if !hasmapto('NetrwBrowseX') - nmap gx NetrwBrowseX - endif - nno NetrwBrowseX :call netrw#NetBrowseX(expand(""),0) -endif - -" --------------------------------------------------------------------- -" LocalBrowse: {{{2 -fun! s:LocalBrowse(dirname) - " unfortunate interaction -- debugging calls can't be used here; - " the BufEnter event causes triggering when attempts to write to - " the DBG buffer are made. -" echomsg "dirname<".a:dirname.">" - if has("amiga") - " The check against '' is made for the Amiga, where the empty - " string is the current directory and not checking would break - " things such as the help command. - if a:dirname != '' && isdirectory(a:dirname) - silent! call netrw#LocalBrowseCheck(a:dirname) - endif - elseif isdirectory(a:dirname) -" echomsg "dirname<".dirname."> isdir" - silent! call netrw#LocalBrowseCheck(a:dirname) - endif - " not a directory, ignore it -endfun - -" --------------------------------------------------------------------- -" NetrwStatusLine: {{{1 -fun! NetrwStatusLine() -" let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr("%")." Xline#".w:netrw_explore_line." line#".line(".") - if !exists("w:netrw_explore_bufnr") || w:netrw_explore_bufnr != bufnr("%") || !exists("w:netrw_explore_line") || w:netrw_explore_line != line(".") || !exists("w:netrw_explore_list") - let &stl= s:netrw_explore_stl - if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif - if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif - return "" - else - return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen - endif -endfun - -" ------------------------------------------------------------------------ -" NetUserPass: set username and password for subsequent ftp transfer {{{1 -" Usage: :call NetUserPass() -- will prompt for userid and password -" :call NetUserPass("uid") -- will prompt for password -" :call NetUserPass("uid","password") -- sets global userid and password -fun! NetUserPass(...) - - " get/set userid - if a:0 == 0 -" call Dfunc("NetUserPass(a:0<".a:0.">)") - if !exists("g:netrw_uid") || g:netrw_uid == "" - " via prompt - let g:netrw_uid= input('Enter username: ') - endif - else " from command line -" call Dfunc("NetUserPass(a:1<".a:1.">) {") - let g:netrw_uid= a:1 - endif - - " get password - if a:0 <= 1 " via prompt -" call Decho("a:0=".a:0." case <=1:") - let g:netrw_passwd= inputsecret("Enter Password: ") - else " from command line -" call Decho("a:0=".a:0." case >1: a:2<".a:2.">") - let g:netrw_passwd=a:2 - endif -" call Dret("NetUserPass") -endfun - -" ------------------------------------------------------------------------ -" NetReadFixup: this sort of function is typically written by the user {{{1 -" to handle extra junk that their system's ftp dumps -" into the transfer. This function is provided as an -" example and as a fix for a Windows 95 problem: in my -" experience, win95's ftp always dumped four blank lines -" at the end of the transfer. -if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp - fun! NetReadFixup(method, line1, line2) -" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")") - if method == 3 " ftp (no <.netrc>) - let fourblanklines= line2 - 3 - silent fourblanklines.",".line2."g/^\s*/d" - endif -" call Dret("NetReadFixup") - endfun -endif - -" ------------------------------------------------------------------------ -" Modelines And Restoration: {{{1 -let &cpo= s:keepcpo -unlet s:keepcpo -" vim:ts=8 fdm=marker +" netrwPlugin.vim: Handles file transfer and remote directory listing across a network +" PLUGIN SECTION +" Date: Jan 05, 2007 +" Maintainer: Charles E Campbell, Jr +" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim +" Copyright: Copyright (C) 1999-2005 Charles E. Campbell, Jr. {{{1 +" Permission is hereby granted to use and distribute this code, +" with or without modifications, provided that this copyright +" notice is copied with it. Like anything else that's free, +" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided +" *as is* and comes with no warranty of any kind, either +" expressed or implied. By using this plugin, you agree that +" in no event will the copyright holder be liable for any damages +" resulting from the use of this software. +" +" But be doers of the Word, and not only hearers, deluding your own selves {{{1 +" (James 1:22 RSV) +" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- + +" --------------------------------------------------------------------- +" Load Once: {{{1 +if &cp || exists("g:loaded_netrwPlugin") + finish +endif +let g:loaded_netrwPlugin = 1 +let s:keepcpo = &cpo +if v:version < 700 + echohl WarningMsg | echo "***netrw*** you need vim version 7.0 for this version of netrw" | echohl None + finish +endif +let s:keepcpo= &cpo +set cpo&vim + +" --------------------------------------------------------------------- +" Public Interface: {{{1 + +" Local Browsing: {{{2 +augroup FileExplorer + au! + au BufEnter * silent! call s:LocalBrowse(expand("")) + if has("win32") || has("win95") || has("win64") || has("win16") + au BufEnter .* silent! call s:LocalBrowse(expand("")) + endif +augroup END + +" Network Browsing Reading Writing: {{{2 +augroup Network + au! + if has("win32") || has("win95") || has("win64") || has("win16") + au BufReadCmd file://* exe "silent doau BufReadPre ".netrw#RFC2396(expand(""))|exe 'e '.substitute(netrw#RFC2396(expand("")),'file://\(.*\)','\1',"")|exe "silent doau BufReadPost ".netrw#RFC2396(expand("")) + else + au BufReadCmd file://* exe "silent doau BufReadPre ".netrw#RFC2396(expand(""))|exe 'e '.substitute(netrw#RFC2396(expand("")),'file://\(.*\)','\1',"")|exe "silent doau BufReadPost ".netrw#RFC2396(expand("")) + au BufReadCmd file://localhost/* exe "silent doau BufReadPre ".netrw#RFC2396(expand(""))|exe 'e '.substitute(netrw#RFC2396(expand("")),'file://localhost/\(.*\)','\1',"")|exe "silent doau BufReadPost ".netrw#RFC2396(expand("")) + endif + au BufReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "silent doau BufReadPre ".expand("")|exe '2Nread "'.expand("").'"'|exe "silent doau BufReadPost ".expand("") + au FileReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "silent doau FileReadPre ".expand("")|exe 'Nread "' .expand("").'"'|exe "silent doau FileReadPost ".expand("") + au BufWriteCmd ftp://*,rcp://*,scp://*,dav://*,rsync://*,sftp://* exe "silent doau BufWritePre ".expand("")|exe 'Nwrite "' .expand("").'"'|exe "silent doau BufWritePost ".expand("") + au FileWriteCmd ftp://*,rcp://*,scp://*,dav://*,rsync://*,sftp://* exe "silent doau FileWritePre ".expand("")|exe "'[,']".'Nwrite "' .expand("").'"'|exe "silent doau FileWritePost ".expand("") + try + au SourceCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe 'Nsource "'.expand("").'"' + catch /^Vim\%((\a\+)\)\=:E216/ + au SourcePre ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe 'Nsource "'.expand("").'"' + endtry +augroup END + +" Commands: :Nread, :Nwrite, :NetUserPass {{{2 +com! -count=1 -nargs=* Nread call netrw#NetSavePosn()call netrw#NetRead(,)call netrw#NetRestorePosn() +com! -range=% -nargs=* Nwrite call netrw#NetSavePosn(),call netrw#NetWrite()call netrw#NetRestorePosn() +com! -nargs=* NetUserPass call NetUserPass() +com! -nargs=+ Ncopy call netrw#NetObtain() +com! -nargs=* Nsource call netrw#NetSavePosn()call netrw#NetSource()call netrw#NetRestorePosn() + +" Commands: :Explore, :Sexplore, Hexplore, Vexplore {{{2 +com! -nargs=* -bar -bang -count=0 -complete=dir Explore call netrw#Explore(,0,0+0,) +com! -nargs=* -bar -bang -count=0 -complete=dir Sexplore call netrw#Explore(,1,0+0,) +com! -nargs=* -bar -bang -count=0 -complete=dir Hexplore call netrw#Explore(,1,2+0,) +com! -nargs=* -bar -bang -count=0 -complete=dir Vexplore call netrw#Explore(,1,4+0,) +com! -nargs=* -bar -count=0 -complete=dir Texplore call netrw#Explore(,0,6 ,) +com! -nargs=* -bar -bang Nexplore call netrw#Explore(-1,0,0,) +com! -nargs=* -bar -bang Pexplore call netrw#Explore(-2,0,0,) + +" Commands: NetrwSettings {{{2 +com! -nargs=0 NetrwSettings :call netrwSettings#NetrwSettings() + +" Maps: +if !exists("g:netrw_nogx") && maparg('g','n') == "" + if !hasmapto('NetrwBrowseX') + nmap gx NetrwBrowseX + endif + nno NetrwBrowseX :call netrw#NetBrowseX(expand(""),0) +endif + +" --------------------------------------------------------------------- +" LocalBrowse: {{{2 +fun! s:LocalBrowse(dirname) + " unfortunate interaction -- debugging calls can't be used here; + " the BufEnter event causes triggering when attempts to write to + " the DBG buffer are made. +" echomsg "dirname<".a:dirname.">" + if has("amiga") + " The check against '' is made for the Amiga, where the empty + " string is the current directory and not checking would break + " things such as the help command. + if a:dirname != '' && isdirectory(a:dirname) + silent! call netrw#LocalBrowseCheck(a:dirname) + endif + elseif isdirectory(a:dirname) +" echomsg "dirname<".dirname."> isdir" + silent! call netrw#LocalBrowseCheck(a:dirname) + endif + " not a directory, ignore it +endfun + +" --------------------------------------------------------------------- +" NetrwStatusLine: {{{1 +fun! NetrwStatusLine() +" let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr("%")." Xline#".w:netrw_explore_line." line#".line(".") + if !exists("w:netrw_explore_bufnr") || w:netrw_explore_bufnr != bufnr("%") || !exists("w:netrw_explore_line") || w:netrw_explore_line != line(".") || !exists("w:netrw_explore_list") + let &stl= s:netrw_explore_stl + if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif + if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif + return "" + else + return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen + endif +endfun + +" ------------------------------------------------------------------------ +" NetUserPass: set username and password for subsequent ftp transfer {{{1 +" Usage: :call NetUserPass() -- will prompt for userid and password +" :call NetUserPass("uid") -- will prompt for password +" :call NetUserPass("uid","password") -- sets global userid and password +fun! NetUserPass(...) + + " get/set userid + if a:0 == 0 +" call Dfunc("NetUserPass(a:0<".a:0.">)") + if !exists("g:netrw_uid") || g:netrw_uid == "" + " via prompt + let g:netrw_uid= input('Enter username: ') + endif + else " from command line +" call Dfunc("NetUserPass(a:1<".a:1.">) {") + let g:netrw_uid= a:1 + endif + + " get password + if a:0 <= 1 " via prompt +" call Decho("a:0=".a:0." case <=1:") + let g:netrw_passwd= inputsecret("Enter Password: ") + else " from command line +" call Decho("a:0=".a:0." case >1: a:2<".a:2.">") + let g:netrw_passwd=a:2 + endif +" call Dret("NetUserPass") +endfun + +" ------------------------------------------------------------------------ +" NetReadFixup: this sort of function is typically written by the user {{{1 +" to handle extra junk that their system's ftp dumps +" into the transfer. This function is provided as an +" example and as a fix for a Windows 95 problem: in my +" experience, win95's ftp always dumped four blank lines +" at the end of the transfer. +if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp + fun! NetReadFixup(method, line1, line2) +" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")") + if method == 3 " ftp (no <.netrc>) + let fourblanklines= line2 - 3 + silent fourblanklines.",".line2."g/^\s*/d" + endif +" call Dret("NetReadFixup") + endfun +endif + +" ------------------------------------------------------------------------ +" Modelines And Restoration: {{{1 +let &cpo= s:keepcpo +unlet s:keepcpo +" vim:ts=8 fdm=marker diff --git a/vimfiles/plugin/visincr.vim b/vimfiles/plugin/visincr.vim index 8361e42..aac340a 100644 --- a/vimfiles/plugin/visincr.vim +++ b/vimfiles/plugin/visincr.vim @@ -1,864 +1,864 @@ -" visincr.vim: Visual-block incremented lists -" Author: Charles E. Campbell, Jr. Ph.D. -" Date: Sep 19, 2006 -" Version: 17 -" -" Visincr assumes that a block of numbers selected by a -" ctrl-v (visual block) has been selected for incrementing. -" This function will transform that block of numbers into -" an incrementing column starting from that topmost number -" in the visual block. Also handles dates, daynames, and -" monthnames. -" -" Fancy Stuff: -" * If the visual block is ragged right (as can happen when "$" -" is used to select the right hand side), the block will have -" spaces appended to straighten it out -" * If the strlen of the count exceeds the visual-block -" allotment of spaces, then additional spaces will be inserted -" * Handles leading tabs by using virtual column calculations -" GetLatestVimScripts: 670 1 :AutoInstall: visincr.vim -" 1Cor 16:14 : Let all that you do be done in love. {{{1 - -" --------------------------------------------------------------------- -" Load Once: {{{1 -if &cp || exists("g:loaded_visincr") - finish -endif -let s:keepcpo = &cpo -let g:loaded_visincr = "v17" -set cpo&vim - -" --------------------------------------------------------------------- -" Methods: {{{1 -let s:I = 0 -let s:II = 1 -let s:IMDY = 2 -let s:IYMD = 3 -let s:IDMY = 4 -let s:ID = 5 -let s:IM = 6 -let s:IA = 7 -let s:IX = 8 -let s:IIX = 9 -let s:IO = 10 -let s:IIO = 11 -let s:IR = 12 -let s:IIR = 13 -let s:RI = 14 -let s:RII = 15 -let s:RIMDY = 16 -let s:RIYMD = 17 -let s:RIDMY = 18 -let s:RID = 19 -let s:RIM = 20 - -" ------------------------------------------------------------------------------ -" Options: {{{1 -if !exists("g:visincr_leaddate") - " choose between dates such as 11/ 5/04 and 11/05/04 - let g:visincr_leaddate = '0' -endif -if !exists("g:visincr_datedivset") - let g:visincr_datedivset= '[-./]' -endif - -" ============================================================================== -" Functions: {{{1 - -" ------------------------------------------------------------------------------ -" VisBlockIncr: {{{2 -fun! visincr#VisBlockIncr(method,...) -" call Dfunc("VisBlockIncr(method<".a:method.">) a:0=".a:0) - - " avoid problems with user options {{{3 - call s:SaveUserOptions() - - " visblockincr only uses visual-block! {{{3 -" call Decho("visualmode<".visualmode().">") - if visualmode() != "\" - echoerr "Please use visual-block mode (ctrl-v)!" - call s:RestoreUserOptions() -" call Dret("VisBlockIncr") - return - endif - - " save boundary line numbers and set up method {{{3 - let y1 = line("'<") - let y2 = line("'>") - let method = (a:method >= s:RI)? a:method - s:RI : a:method - let leaddate= g:visincr_leaddate - - " get increment (default=1) {{{3 - if a:0 > 0 - let incr= a:1 - if a:method == s:IX || a:method == s:IIX - let incr= s:Hex2Dec(incr) - elseif a:method == s:IO || a:method == s:IIO - let incr= s:Oct2Dec(incr) - endif - else - let incr= 1 - endif -" call Decho("incr=".incr) - - " set up restriction pattern {{{3 - let leftcol = virtcol("'<") - let rghtcol = virtcol("'>") - if leftcol > rghtcol - let leftcol = virtcol("'>") - let rghtcol = virtcol("'<") - endif - let width= rghtcol - leftcol + 1 -" call Decho("width= [rghtcol=".rghtcol."]-[leftcol=".leftcol."]+1=".width) - - if a:method == s:RI - let restrict= '\%'.col(".").'c\d' -" call Decho(":I restricted<".restrict.">") - - elseif a:method == s:RII - let restrict= '\%'.col(".").'c\s\{,'.width.'}\d' -" call Decho(":II restricted<".restrict.">") - - elseif a:method == s:RIMDY - let restrict= '\%'.col(".").'c\d\{1,2}'.g:visincr_datedivset.'\d\{1,2}'.g:visincr_datedivset.'\d\{2,4}' -" call Decho(":IMDY restricted<".restrict.">") - - elseif a:method == s:RIYMD - let restrict= '\%'.col(".").'c\d\{2,4}'.g:visincr_datedivset.'\d\{1,2}'.g:visincr_datedivset.'\d\{1,2}' -" call Decho(":IYMD restricted<".restrict.">") - - elseif a:method == s:RIDMY - let restrict= '\%'.col(".").'c\d\{1,2}'.g:visincr_datedivset.'\d\{1,2}'.g:visincr_datedivset.'\d\{2,4}' -" call Decho(":IDMY restricted<".restrict.">") - - elseif a:method == s:RID - if exists("g:visincr_dow") - let dowlist = substitute(g:visincr_dow,'\(\a\{1,3}\)[^,]*\%(,\|$\)','\1\\|','ge') - let dowlist = substitute(dowlist,'\\|$','','e') - let restrict= '\c\%'.col(".").'c\('.substitute(dowlist,',','\\|','ge').'\)' -" call Decho("restrict<".restrict.">") - else - let restrict= '\c\%'.col(".").'c\(mon\|tue\|wed\|thu\|fri\|sat\|sun\)' - endif -" call Decho(":ID restricted<".restrict.">") - - elseif a:method == s:RIM - if exists("g:visincr_month") - let monlist = substitute(g:visincr_month,'\(\a\{1,3}\)[^,]*\%(,\|$\)','\1\\|','ge') - let monlist = substitute(monlist,'\\|$','','e') - let restrict= '\c\%'.col(".").'c\('.substitute(monlist,',','\\|','ge').'\)' -" call Decho("restrict<".restrict.">") - else - let restrict= '\c\%'.col(".").'c\(jan\|feb\|mar\|apr\|may\|jun\|jul\|aug\|sep\|oct\|nov\|dec\)' - endif -" call Decho(":IM restricted<".restrict.">") - endif - - " determine zfill {{{3 -" call Decho("a:0=".a:0." method=".method) - if a:0 > 1 && ((s:IMDY <= method && method <= s:IDMY) || (s:RIMDY <= method && method <= s:RIDMY)) - let leaddate= a:2 -" call Decho("set leaddate<".leaddate.">") - elseif a:0 > 1 && method - let zfill= a:2 - if zfill == "''" || zfill == '""' - let zfill="" - endif -" call Decho("set zfill<".zfill.">") - else - " default zfill (a single space) - let zfill= ' ' -" call Decho("set default zfill<".zfill.">") - endif - - " IMDY IYMD IDMY ID IM IA: {{{3 - if s:IMDY <= method && method <= s:IA - let rghtcol = rghtcol + 1 - let curline = getline("'<") - - " ID: {{{3 - if method == s:ID - let pat = '^.*\%'.leftcol.'v\(\a\+\)\%'.rghtcol.'v.*$' - let dow = substitute(substitute(curline,pat,'\1','e'),' ','','ge') - let dowlen = strlen(dow) -" call Decho("pat<".pat."> dow<".dow."> dowlen=".dowlen) - - " set up long daynames - if exists("g:visincr_dow") - let dow_0= substitute(g:visincr_dow,'^\([^,]*\),.*$', '\1','') - let dow_1= substitute(g:visincr_dow,'^\%([^,]*,\)\{1}\([^,]*\),.*$','\1','') - let dow_2= substitute(g:visincr_dow,'^\%([^,]*,\)\{2}\([^,]*\),.*$','\1','') - let dow_3= substitute(g:visincr_dow,'^\%([^,]*,\)\{3}\([^,]*\),.*$','\1','') - let dow_4= substitute(g:visincr_dow,'^\%([^,]*,\)\{4}\([^,]*\),.*$','\1','') - let dow_5= substitute(g:visincr_dow,'^\%([^,]*,\)\{5}\([^,]*\),.*$','\1','') - let dow_6= substitute(g:visincr_dow,'^\%([^,]*,\)\{6}\([^,]*\)$', '\1','') - else - let dow_0= "Monday" - let dow_1= "Tuesday" - let dow_2= "Wednesday" - let dow_3= "Thursday" - let dow_4= "Friday" - let dow_5= "Saturday" - let dow_6= "Sunday" - endif - - " if the daynames under the cursor is <= 3, transform - " long daynames to short daynames - if strlen(dow) <= 3 -" call Decho("transform long daynames to short daynames") - let dow_0= strpart(dow_0,0,3) - let dow_1= strpart(dow_1,0,3) - let dow_2= strpart(dow_2,0,3) - let dow_3= strpart(dow_3,0,3) - let dow_4= strpart(dow_4,0,3) - let dow_5= strpart(dow_5,0,3) - let dow_6= strpart(dow_6,0,3) - endif - - " identify day-of-week under cursor - let idow= 0 - while idow < 7 -" call Decho("dow<".dow."> dow_".idow."<".dow_{idow}.">") - if dow =~ '\c\<'.strpart(dow_{idow},0,3) - break - endif - let idow= idow + 1 - endwhile - if idow >= 7 - echoerr "***error*** misspelled day-of-week <".dow.">" - call s:RestoreUserOptions() -" call Dret("VisBlockIncr : unable to identify day-of-week") - return - endif - - " generate incremented dayname list - norm! `< - norm! gUl - norm! `< - let l = y1 - while l < y2 - norm! j -" call Decho("while [l=".l."] < [y2=".y2."]: line=".line(".")." col[".leftcol.",".rghtcol."] width=".width) - if exists("restrict") && getline(".") !~ restrict - let l= l + 1 - continue - endif - let idow= (idow + incr)%7 - exe 's/\%'.leftcol.'v.\{'.width.'\}/'.dow_{idow}.'/e' - let l= l + 1 - endw - " return from ID - call s:RestoreUserOptions() -" call Dret("VisBlockIncr : ID") - return - endif - - " IM: {{{3 - if method == s:IM - let pat = '^.*\%'.leftcol.'v\(\a\+\)\%'.rghtcol.'v.*$' - let mon = substitute(substitute(curline,pat,'\1','e'),' ','','ge') - let monlen = strlen(mon) - if exists("g:visincr_month") - let mon_0 = substitute(g:visincr_month,'^\([^,]*\),.*$', '\1','') - let mon_1 = substitute(g:visincr_month,'^\%([^,]*,\)\{1}\([^,]*\),.*$', '\1','') - let mon_2 = substitute(g:visincr_month,'^\%([^,]*,\)\{2}\([^,]*\),.*$', '\1','') - let mon_3 = substitute(g:visincr_month,'^\%([^,]*,\)\{3}\([^,]*\),.*$', '\1','') - let mon_4 = substitute(g:visincr_month,'^\%([^,]*,\)\{4}\([^,]*\),.*$', '\1','') - let mon_5 = substitute(g:visincr_month,'^\%([^,]*,\)\{5}\([^,]*\),.*$', '\1','') - let mon_6 = substitute(g:visincr_month,'^\%([^,]*,\)\{6}\([^,]*\),.*$', '\1','') - let mon_7 = substitute(g:visincr_month,'^\%([^,]*,\)\{7}\([^,]*\),.*$', '\1','') - let mon_8 = substitute(g:visincr_month,'^\%([^,]*,\)\{8}\([^,]*\),.*$', '\1','') - let mon_9 = substitute(g:visincr_month,'^\%([^,]*,\)\{9}\([^,]*\),.*$', '\1','') - let mon_10= substitute(g:visincr_month,'^\%([^,]*,\)\{10}\([^,]*\),.*$','\1','') - let mon_11= substitute(g:visincr_month,'^\%([^,]*,\)\{11}\([^,]*\)$', '\1','') - else - let mon_0 = "January" - let mon_1 = "February" - let mon_2 = "March" - let mon_3 = "April" - let mon_4 = "May" - let mon_5 = "June" - let mon_6 = "July" - let mon_7 = "August" - let mon_8 = "September" - let mon_9 = "October" - let mon_10= "November" - let mon_11= "December" - endif - - " identify month under cursor - let imon= 0 - while imon < 12 - if mon =~ '\c\<'.strpart(mon_{imon},0,3) - break - endif - let imon= imon + 1 - endwhile - if imon >= 12 - echoerr "***error*** misspelled month <".mon.">" - call s:RestoreUserOptions() -" call Dret("VisBlockIncr") - return - endif - - " if monthname is three or fewer characters long, - " transform monthnames to three character versions - if strlen(mon) <= 3 -" call Decho("transform monthnames to short versions") - let jmon= 0 - while jmon < 12 - let mon_{jmon} = strpart(mon_{jmon},0,3) - let jmon = jmon + 1 - endwhile - endif - - " generate incremented monthname list - norm! `< - norm! gUl - norm! `< - let l = y1 - while l < y2 - norm! j - if exists("restrict") && getline(".") !~ restrict - let l= l + 1 - continue - endif - let imon= (imon + incr)%12 - exe 's/\%'.leftcol.'v.\{'.width.'\}/'.mon_{imon}.'/e' - let l= l + 1 - endw - " return from IM - call s:RestoreUserOptions() -" call Dret("VisBlockIncr : IM") - return - endif - - " IA: {{{3 - if method == s:IA - let pat = '^.*\%'.leftcol.'v\(\a\).*$' - let letter = substitute(curline,pat,'\1','e') - if letter !~ '\a' - let letter= 'A' - endif - if letter =~ '[a-z]' - let alphabet='abcdefghijklmnopqrstuvwxyz' - else - let alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZ' - endif - let ilet= stridx(alphabet,letter) - - norm! `< - let l = y1 - while l <= y2 -" call Decho("letter<".letter."> l=".l." ilet=".ilet) - exe 's/\%'.leftcol.'v.*\%'.rghtcol.'v/'.letter.'/e' - let ilet = (ilet + incr)%26 - let letter = strpart(alphabet,ilet,1) - if l < y2 - silent norm! j - endif - let l= l + 1 - endw - " return from IA - call s:RestoreUserOptions() -" call Dret("VisBlockIncr : IA") - return - endif - - let pat = '^.*\%'.leftcol.'v\( \=[0-9]\{1,4}\)'.g:visincr_datedivset.'\( \=[0-9]\{1,2}\)'.g:visincr_datedivset.'\( \=[0-9]\{1,4}\)\%'.rghtcol.'v.*$' - let datediv= substitute(curline,'^.*\%'.leftcol.'v\%( \=[0-9]\{1,4}\)\('.g:visincr_datedivset.'\).*$','\1','') -" call Decho("datediv<".datediv.">") - - " IMDY: {{{3 - if method == s:IMDY - let m = substitute(substitute(curline,pat,'\1',''),' ','','ge')+0 - let d = substitute(substitute(curline,pat,'\2',''),' ','','ge')+0 - let y = substitute(substitute(curline,pat,'\3',''),' ','','ge')+0 - let type = 2 -" call Decho("IMDY: y=".y." m=".m." d=".d." leftcol=".leftcol." rghtcol=".rghtcol) - - " IYMD: {{{3 - elseif method == s:IYMD - let y = substitute(substitute(curline,pat,'\1',''),' ','','ge')+0 - let m = substitute(substitute(curline,pat,'\2',''),' ','','ge')+0 - let d = substitute(substitute(curline,pat,'\3',''),' ','','ge')+0 - let type = 1 -" call Decho("IYMD: y=".y." m=".m." d=".d." leftcol=".leftcol." rghtcol=".rghtcol) - - " IDMY: {{{3 - elseif method == s:IDMY - let d = substitute(substitute(curline,pat,'\1',''),' ','','ge')+0 - let m = substitute(substitute(curline,pat,'\2',''),' ','','ge')+0 - let y = substitute(substitute(curline,pat,'\3',''),' ','','ge')+0 - let type = 3 -" call Decho("IDMY: y=".y." m=".m." d=".d." leftcol=".leftcol." rghtcol=".rghtcol) - else - echoerr "***error*** in script" -" call Dret("VisBlockIncr -- method#".method." not supported") - return - endif - - " Julian day/Calendar day calculations {{{3 - try - let julday= calutil#Cal2Jul(y,m,d) - catch /^Vim\%((\a\+)\)\=:E/ - echoerr "***error*** you need calutil.vim! (:help visincr-calutil)" -" call Dret("VisBlockIncr") - return - endtry - norm! `< - let l = y1 - while l <= y2 - if exists("restrict") && getline(".") !~ restrict - norm! j - let l= l + 1 - continue - endif - let doy = calutil#Jul2Cal(julday,type) - - " IYMD: {{{3 - if type == 1 - let doy = substitute(doy,'^\d/',leaddate.'&','e') - let doy = substitute(doy,'/\(\d/\)','/'.leaddate.'\1','e') - let doy = substitute(doy,'/\(\d\)$','/'.leaddate.'\1','e') - - " IMDY IDMY: {{{3 - else - let doy = substitute(doy,'^\d/',' &','e') - let doy = substitute(doy,'/\(\d/\)','/'.leaddate.'\1','e') - let doy = substitute(doy,'/\(\d\)$','/'.leaddate.'\1','e') - endif - - " use user's date divider - if datediv != '/' - let doy= substitute(doy,'/',datediv,'g') - else - let doy= escape(doy,'/') - endif -" call Decho("doy<".doy.">") - - if leaddate != ' ' - let doy= substitute(doy,' ',leaddate,'ge') - endif -" call Decho('exe s/\%'.leftcol.'v.*\%'.rghtcol.'v/'.doy.'/e') - exe 's/\%'.leftcol.'v.*\%'.rghtcol.'v/'.doy.'/e' - let l = l + 1 - let julday= julday + incr - if l <= y2 - norm! j - endif - endw - call s:RestoreUserOptions() -" call Dret("VisBlockIncr : IMDY IYMD IDMY ID IM") - return - endif " IMDY IYMD IDMY ID IM - - " I II IX IIX IO IIO IR IIR: {{{3 - " construct a line from the first line that only has the number in it - let rml = rghtcol - leftcol - let rmlp1 = rml + 1 - let lm1 = leftcol - 1 -" call Decho("rmlp1=[rghtcol=".rghtcol."]-[leftcol=".leftcol."]+1=".rmlp1) -" call Decho("lm1 =[leftcol=".leftcol."]-1=".lm1) - - if lm1 <= 0 - " region beginning at far left -" call Decho("handle visblock at far left") - let lm1 = 1 - let pat = '^\([0-9 \t]\{1,'.rmlp1.'}\).*$' - if method == s:IX || method == s:IIX - let pat = '^\([0-9a-fA-F \t]\{1,'.rmlp1.'}\).*$' - elseif method == s:IR || method == s:IIR - if getline(".") =~ '^\(.\{-}\)\%'.leftcol.'v\([0-9 \t]\{1,'.rmlp1.'}\).*$' - " need to convert arabic notation to roman numeral - let pat = '^\([0-9IVXCLM) \t]\{1,'.rmlp1.'}\).*$' - else - let pat = '^\([IVXCLM) \t]\{1,'.rmlp1.'}\).*$' - endif - else - let pat = '^\([0-9 \t]\{1,'.rmlp1.'}\).*$' - endif - let cnt = substitute(getline("'<"),pat,'\1',"") - - else - " region not beginning at far left -" call Decho("handle visblock not at far left") - if method == s:IX || method == s:IIX - let pat = '^\(.\{-}\)\%'.leftcol.'v\([0-9a-fA-F \t]\{1,'.rmlp1.'}\).*$' - elseif method == s:IO || method == s:IIO - let pat = '^\(.\{-}\)\%'.leftcol.'v\([0-7 \t]\{1,'.rmlp1.'}\).*$' - elseif method == s:IR || method == s:IIR -" call Decho('test: ^\(.\{-}\)\%'.leftcol.'v\([0-9 \t]\{1,'.rmlp1.'}\).*$') - if getline(".") =~ '^\(.\{-}\)\%'.leftcol.'v\([0-9 \t]\{1,'.rmlp1.'}\).*$' - " need to convert arabic notation to roman numeral - let pat = '^\(.\{-}\)\%'.leftcol.'v\([0-9IVXCLM \t]\{1,'.rmlp1.'}\).*$' - else - let pat = '^\(.\{-}\)\%'.leftcol.'v\([IVXCLM \t]\{1,'.rmlp1.'}\).*$' - endif - else - let pat = '^\(.\{-}\)\%'.leftcol.'v\([0-9 \t]\{1,'.rmlp1.'}\).*$' - endif -" call Decho("pat<".pat.">") - let cnt = substitute(getline("'<"),pat,'\2',"") - endif - - let cntlen = strlen(cnt) - let cnt = substitute(cnt,'\s','',"ge") - let ocnt = cnt -" call Decho("cntlen=".cntlen." cnt=".cnt." ocnt=".ocnt." (before I*[XOR] subs)") - - if method == s:IX || method == s:IIX - let cnt= substitute(cnt,'^0*\([1-9a-fA-F]\|0$\)','\1',"ge") - elseif method == s:IO || method == s:IIO - let cnt= substitute(cnt,'^0*\([1-7]\|0$\)','\1',"ge") - elseif method == s:IR || method == s:IIR - let cnt= substitute(cnt,'^\([IVXCLM]$\)','\1',"ge") - else - let cnt= substitute(cnt,'^0*\([1-9]\|0$\)','\1',"ge") - endif -" call Decho("cnt<".cnt."> pat<".pat.">") - - " left-method with zeros {{{3 - " IF top number is zero-mode - " AND we're justified right - " AND increment is positive - " AND user didn't specify a modeding character - if a:0 < 2 && ( method == s:II || method == s:IIX || method == s:IIO) && cnt != ocnt && incr > 0 - let zfill= '0' - endif - - " determine how much incrementing is needed {{{3 - if method == s:IX || method == s:IIX - let maxcnt= s:Dec2Hex(s:Hex2Dec(cnt) + incr*(y2 - y1)) - elseif method == s:IO || method == s:IIO - let maxcnt= s:Dec2Oct(s:Oct2Dec(cnt) + incr*(y2 - y1)) - elseif method == s:IR || method == s:IIR - if cnt =~ '^\d\+$' - let maxcnt= s:Dec2Rom(cnt + incr*(y2 - y1)) - else - let maxcnt= s:Dec2Rom(s:Rom2Dec(cnt) + incr*(y2 - y1)) - endif - else - let maxcnt= printf("%d",cnt + incr*(y2 - y1)) - endif - let maxcntlen= strlen(maxcnt) - if cntlen > maxcntlen - let maxcntlen= cntlen - endif - if method == s:IIR - let maxcntlen= maxcntlen + 2 - endif -" call Decho("maxcnt=".maxcnt." maxcntlen=".maxcntlen) - - " go through visual block incrementing numbers based {{{3 - " on first number (saved in cnt), taking care to - " avoid inadvertently issuing "0h" commands. - " l == current line number, over range [y1,y2] - norm! `< - let l = y1 - if (method == s:IR || method == s:IIR) && cnt =~ '^\d\+$' - let cnt= s:Dec2Rom(cnt) - endif - while l <= y2 -" call Decho("----- while [l=".l."] <= [y2=".y2."]: cnt=".cnt) - if exists("restrict") && getline(".") !~ restrict -" call Decho("skipping <".getline(".")."> (restrict)") - norm! j - let l= l + 1 - continue - endif - let cntlen= strlen(cnt) - - " Straighten out ragged-right visual-block selection {{{3 - " by appending spaces as needed - norm! $ - while virtcol("$") <= rghtcol - exe "norm! A \" - endwhile - norm! 0 - - " convert visual block line to all spaces {{{3 - if virtcol(".") != leftcol - exe 'norm! /\%'.leftcol."v\" - endif - exe "norm! " . rmlp1 . "r " - - " cnt has gotten bigger than the visually-selected {{{3 - " area allows. Will insert spaces to accommodate it. - if maxcntlen > 0 - let ins= maxcntlen - rmlp1 - else - let ins= strlen(cnt) - rmlp1 - endif - while ins > 0 - exe "norm! i \" - let ins= ins - 1 - endwhile - - " back up to left-of-block (plus optional left-hand-side modeling) {{{3 - norm! 0 - if method == s:I || method == s:IO || method == s:IX || method == s:IR - let bkup= leftcol -" call Decho("bkup= [leftcol=".leftcol."] (due to method)") - elseif maxcntlen > 0 - let bkup= leftcol + maxcntlen - cntlen -" call Decho("bkup= [leftcol=".leftcol."]+[maxcntlen=".maxcntlen."]-[cntlen=".cntlen."]=".bkup) - else - let bkup= leftcol -" call Decho("bkup= [leftcol=".leftcol."] ([maxcntlen=".maxcntlen."]<=0)") - endif - if virtcol(".") != bkup - if bkup == 0 - norm! 0 - else - exe 'norm! /\%'.bkup."v\" - endif - endif - - " replace with count {{{3 -" call Decho("exe norm! R" . cnt . "\") - exe "norm! R" . cnt . "\" - if cntlen > 1 - let cntlenm1= cntlen - 1 - exe "norm! " . cntlenm1 . "h" - endif - if zfill != " " - silent! exe 's/\%'.leftcol.'v\( \+\)/\=substitute(submatch(1)," ","'.zfill.'","ge")/e' - endif - - " set up for next line {{{3 - if l != y2 - norm! j - endif - if method == s:IX || method == s:IIX - let cnt= s:Dec2Hex(s:Hex2Dec(cnt) + incr) - elseif method == s:IO || method == s:IIO - let cnt= s:Dec2Oct(s:Oct2Dec(cnt) + incr) - elseif method == s:IR || method == s:IIR - let cnt= s:Dec2Rom(s:Rom2Dec(cnt) + incr) - else - let cnt= cnt + incr - endif - let l = l + 1 - endw - - " restore options: {{{3 - call s:RestoreUserOptions() -" call Dret("VisBlockIncr") -endfun - -" --------------------------------------------------------------------- -" Hex2Dec: convert hexadecimal to decimal {{{2 -fun! s:Hex2Dec(hex) -" call Dfunc("Hex2Dec(hex=".a:hex.")") - let hex= substitute(string(a:hex),"'","","ge") -" call Decho("hex<".hex.">") - if hex =~ '^-' - let n = strpart(hex,1) - let neg = 1 - else - let n = hex - let neg = 0 - endif -" call Decho("n<".n."> neg=".neg) - - let b10 = 0 - while n != "" - let hexdigit= strpart(n,0,1) - if hexdigit =~ '\d' - let hexdigit= char2nr(hexdigit) - char2nr('0') -" call Decho("0-9: hexdigit=".hexdigit) - elseif hexdigit =~ '[a-f]' - let hexdigit= char2nr(hexdigit) - char2nr('a') + 10 -" call Decho("a-f: hexdigit=".hexdigit) - else - let hexdigit= char2nr(hexdigit) - char2nr('A') + 10 -" call Decho("A-F: hexdigit=".hexdigit) - endif - let b10= 16*b10 + hexdigit - let n = strpart(n,1) - endwhile - - if neg - let b10= -b10 - endif -" call Dret("Hex2Dec ".b10) - return b10 -endfun - -" --------------------------------------------------------------------- -" Dec2Hex: convert decimal to hexadecimal {{{2 -fun! s:Dec2Hex(b10) -" call Dfunc("Dec2Hex(b10=".a:b10.")") - if a:b10 >= 0 - let b10 = a:b10 - let neg = 0 - else - let b10 = -a:b10 - let neg = 1 - endif -" call Decho('b10<'.b10.'> neg='.neg) - if v:version >= 700 - let hex= printf("%x",b10) - else - let hex = "" - while b10 - let hex = '0123456789abcdef'[b10 % 16] . hex - let b10 = b10 / 16 - endwhile - endif - if neg - let hex= "-".hex - endif -" call Dret("Dec2Hex ".hex) - return hex -endfun - -" --------------------------------------------------------------------- -" Oct2Dec: convert octal to decimal {{{2 -fun! s:Oct2Dec(oct) -" call Dfunc("Oct2Dec(oct=".a:oct.")") - if a:oct >= 0 - let n = a:oct - let neg= 0 - else - let n = strpart(a:oct,1) - let neg = 1 - endif - - let b10 = 0 - while n != "" - let octdigit= strpart(n,0,1) - if octdigit =~ '[0-7]' - let octdigit= char2nr(octdigit) - char2nr('0') -" call Decho("octdigit=".octdigit) - else - break - endif - let b10= 8*b10 + octdigit - let n = strpart(n,1) - endwhile - - if neg - let b10= -b10 - endif -" call Dret("Oct2Dec ".b10) - return b10 -endfun - -" --------------------------------------------------------------------- -" Dec2Oct: convert decimal to octal {{{2 -fun! s:Dec2Oct(b10) -" call Dfunc("Dec2Oct(b10=".a:b10.")") - if a:b10 >= 0 - let b10 = a:b10 - let neg = 0 - else - let b10 = -a:b10 - let neg = 1 - endif - - if v:version >= 700 - let oct= printf("%o",b10) - else - let oct = "" - while b10 - let oct = '01234567'[b10 % 8] . oct - let b10 = b10 / 8 - endwhile - endif - - if neg - let oct= "-".oct - endif -" call Dret("Dec2Oct ".oct) - return oct -endfun - -" ------------------------------------------------------------------------------ -" Roman Numeral Support: {{{2 -let s:d2r= [ [ 1000000 , 'M)' ],[900000 , 'CM)' ], [500000 , 'D)' ], [400000 , 'CD)' ], [100000 , 'C)' ], [90000 , 'XC)' ], [50000 , 'L)' ], [40000 , 'XL)' ], [10000 , 'X)' ], [9000 , 'IX)'], [5000 , 'V)'], [1000 , 'M' ], [900 , 'CM'], [500 , 'D'], [400 , 'CD'], [100 , 'C'], [90 , 'XC'], [50 , 'L'], [40 , 'XL'], [10 , 'X'], [9 , 'IX'], [5 , 'V'], [4 , 'IV'], [1 , 'I'] ] - -" --------------------------------------------------------------------- -" Rom2Dec: convert roman numerals to a decimal number {{{2 -fun! s:Rom2Dec(roman) -" call Dfunc("Rom2Dec(".a:roman.")") - let roman = substitute(a:roman,'.','\U&','ge') - let dec = 0 - - while roman != '' - for item in s:d2r - let pat= '^'.item[1] - if roman =~ pat - let dec= dec + item[0] - if strlen(item[1]) > 1 - let roman= strpart(roman,strlen(item[1])-1) - endif - break - endif - endfor - let roman= strpart(roman,1) - endwhile - -" call Dret("Rom2Dec ".dec) - return dec -endfun - -" --------------------------------------------------------------------- -" Dec2Rom: convert a decimal number to roman numerals {{{2 -" Note that since there is no zero or negative integers -" using Roman numerals, attempts to convert such will always -" result in "I". -fun! s:Dec2Rom(dec) -" call Dfunc("Dec2Rom(".a:dec.")") - if a:dec > 0 - let roman = "" - let dec = a:dec - let i = 0 - while dec > 0 - while dec >= s:d2r[i][0] - let dec = dec - s:d2r[i][0] - let roman = roman . s:d2r[i][1] - endwhile - let i= i + 1 - endwhile - else - let roman= "I" - endif -" call Dret("Dec2Rom ".roman) - return roman -endfun - -" --------------------------------------------------------------------- -" SaveUserOptions: {{{2 -fun! s:SaveUserOptions() -" call Dfunc("SaveUserOptions()") - let s:fokeep = &fo - let s:gdkeep = &gd - let s:ickeep = &ic - let s:magickeep = &magic - let s:reportkeep= &report - set fo=tcq magic report=9999 noic nogd -" call Dret("SaveUserOptions") -endfun - -" --------------------------------------------------------------------- -" RestoreUserOptions: {{{2 -fun! s:RestoreUserOptions() -" call Dfunc("RestoreUserOptions()") - let &fo = s:fokeep - let &gd = s:gdkeep - let &ic = s:ickeep - let &magic = s:magickeep - let &report= s:reportkeep -" call Dret("RestoreUserOptions") -endfun - -" --------------------------------------------------------------------- -" Restoration: {{{1 -let &cpo= s:keepcpo -unlet s:keepcpo -" ------------------------------------------------------------------------------ -" Modelines: {{{1 -" vim: ts=4 fdm=marker +" visincr.vim: Visual-block incremented lists +" Author: Charles E. Campbell, Jr. Ph.D. +" Date: Sep 19, 2006 +" Version: 17 +" +" Visincr assumes that a block of numbers selected by a +" ctrl-v (visual block) has been selected for incrementing. +" This function will transform that block of numbers into +" an incrementing column starting from that topmost number +" in the visual block. Also handles dates, daynames, and +" monthnames. +" +" Fancy Stuff: +" * If the visual block is ragged right (as can happen when "$" +" is used to select the right hand side), the block will have +" spaces appended to straighten it out +" * If the strlen of the count exceeds the visual-block +" allotment of spaces, then additional spaces will be inserted +" * Handles leading tabs by using virtual column calculations +" GetLatestVimScripts: 670 1 :AutoInstall: visincr.vim +" 1Cor 16:14 : Let all that you do be done in love. {{{1 + +" --------------------------------------------------------------------- +" Load Once: {{{1 +if &cp || exists("g:loaded_visincr") + finish +endif +let s:keepcpo = &cpo +let g:loaded_visincr = "v17" +set cpo&vim + +" --------------------------------------------------------------------- +" Methods: {{{1 +let s:I = 0 +let s:II = 1 +let s:IMDY = 2 +let s:IYMD = 3 +let s:IDMY = 4 +let s:ID = 5 +let s:IM = 6 +let s:IA = 7 +let s:IX = 8 +let s:IIX = 9 +let s:IO = 10 +let s:IIO = 11 +let s:IR = 12 +let s:IIR = 13 +let s:RI = 14 +let s:RII = 15 +let s:RIMDY = 16 +let s:RIYMD = 17 +let s:RIDMY = 18 +let s:RID = 19 +let s:RIM = 20 + +" ------------------------------------------------------------------------------ +" Options: {{{1 +if !exists("g:visincr_leaddate") + " choose between dates such as 11/ 5/04 and 11/05/04 + let g:visincr_leaddate = '0' +endif +if !exists("g:visincr_datedivset") + let g:visincr_datedivset= '[-./]' +endif + +" ============================================================================== +" Functions: {{{1 + +" ------------------------------------------------------------------------------ +" VisBlockIncr: {{{2 +fun! visincr#VisBlockIncr(method,...) +" call Dfunc("VisBlockIncr(method<".a:method.">) a:0=".a:0) + + " avoid problems with user options {{{3 + call s:SaveUserOptions() + + " visblockincr only uses visual-block! {{{3 +" call Decho("visualmode<".visualmode().">") + if visualmode() != "\" + echoerr "Please use visual-block mode (ctrl-v)!" + call s:RestoreUserOptions() +" call Dret("VisBlockIncr") + return + endif + + " save boundary line numbers and set up method {{{3 + let y1 = line("'<") + let y2 = line("'>") + let method = (a:method >= s:RI)? a:method - s:RI : a:method + let leaddate= g:visincr_leaddate + + " get increment (default=1) {{{3 + if a:0 > 0 + let incr= a:1 + if a:method == s:IX || a:method == s:IIX + let incr= s:Hex2Dec(incr) + elseif a:method == s:IO || a:method == s:IIO + let incr= s:Oct2Dec(incr) + endif + else + let incr= 1 + endif +" call Decho("incr=".incr) + + " set up restriction pattern {{{3 + let leftcol = virtcol("'<") + let rghtcol = virtcol("'>") + if leftcol > rghtcol + let leftcol = virtcol("'>") + let rghtcol = virtcol("'<") + endif + let width= rghtcol - leftcol + 1 +" call Decho("width= [rghtcol=".rghtcol."]-[leftcol=".leftcol."]+1=".width) + + if a:method == s:RI + let restrict= '\%'.col(".").'c\d' +" call Decho(":I restricted<".restrict.">") + + elseif a:method == s:RII + let restrict= '\%'.col(".").'c\s\{,'.width.'}\d' +" call Decho(":II restricted<".restrict.">") + + elseif a:method == s:RIMDY + let restrict= '\%'.col(".").'c\d\{1,2}'.g:visincr_datedivset.'\d\{1,2}'.g:visincr_datedivset.'\d\{2,4}' +" call Decho(":IMDY restricted<".restrict.">") + + elseif a:method == s:RIYMD + let restrict= '\%'.col(".").'c\d\{2,4}'.g:visincr_datedivset.'\d\{1,2}'.g:visincr_datedivset.'\d\{1,2}' +" call Decho(":IYMD restricted<".restrict.">") + + elseif a:method == s:RIDMY + let restrict= '\%'.col(".").'c\d\{1,2}'.g:visincr_datedivset.'\d\{1,2}'.g:visincr_datedivset.'\d\{2,4}' +" call Decho(":IDMY restricted<".restrict.">") + + elseif a:method == s:RID + if exists("g:visincr_dow") + let dowlist = substitute(g:visincr_dow,'\(\a\{1,3}\)[^,]*\%(,\|$\)','\1\\|','ge') + let dowlist = substitute(dowlist,'\\|$','','e') + let restrict= '\c\%'.col(".").'c\('.substitute(dowlist,',','\\|','ge').'\)' +" call Decho("restrict<".restrict.">") + else + let restrict= '\c\%'.col(".").'c\(mon\|tue\|wed\|thu\|fri\|sat\|sun\)' + endif +" call Decho(":ID restricted<".restrict.">") + + elseif a:method == s:RIM + if exists("g:visincr_month") + let monlist = substitute(g:visincr_month,'\(\a\{1,3}\)[^,]*\%(,\|$\)','\1\\|','ge') + let monlist = substitute(monlist,'\\|$','','e') + let restrict= '\c\%'.col(".").'c\('.substitute(monlist,',','\\|','ge').'\)' +" call Decho("restrict<".restrict.">") + else + let restrict= '\c\%'.col(".").'c\(jan\|feb\|mar\|apr\|may\|jun\|jul\|aug\|sep\|oct\|nov\|dec\)' + endif +" call Decho(":IM restricted<".restrict.">") + endif + + " determine zfill {{{3 +" call Decho("a:0=".a:0." method=".method) + if a:0 > 1 && ((s:IMDY <= method && method <= s:IDMY) || (s:RIMDY <= method && method <= s:RIDMY)) + let leaddate= a:2 +" call Decho("set leaddate<".leaddate.">") + elseif a:0 > 1 && method + let zfill= a:2 + if zfill == "''" || zfill == '""' + let zfill="" + endif +" call Decho("set zfill<".zfill.">") + else + " default zfill (a single space) + let zfill= ' ' +" call Decho("set default zfill<".zfill.">") + endif + + " IMDY IYMD IDMY ID IM IA: {{{3 + if s:IMDY <= method && method <= s:IA + let rghtcol = rghtcol + 1 + let curline = getline("'<") + + " ID: {{{3 + if method == s:ID + let pat = '^.*\%'.leftcol.'v\(\a\+\)\%'.rghtcol.'v.*$' + let dow = substitute(substitute(curline,pat,'\1','e'),' ','','ge') + let dowlen = strlen(dow) +" call Decho("pat<".pat."> dow<".dow."> dowlen=".dowlen) + + " set up long daynames + if exists("g:visincr_dow") + let dow_0= substitute(g:visincr_dow,'^\([^,]*\),.*$', '\1','') + let dow_1= substitute(g:visincr_dow,'^\%([^,]*,\)\{1}\([^,]*\),.*$','\1','') + let dow_2= substitute(g:visincr_dow,'^\%([^,]*,\)\{2}\([^,]*\),.*$','\1','') + let dow_3= substitute(g:visincr_dow,'^\%([^,]*,\)\{3}\([^,]*\),.*$','\1','') + let dow_4= substitute(g:visincr_dow,'^\%([^,]*,\)\{4}\([^,]*\),.*$','\1','') + let dow_5= substitute(g:visincr_dow,'^\%([^,]*,\)\{5}\([^,]*\),.*$','\1','') + let dow_6= substitute(g:visincr_dow,'^\%([^,]*,\)\{6}\([^,]*\)$', '\1','') + else + let dow_0= "Monday" + let dow_1= "Tuesday" + let dow_2= "Wednesday" + let dow_3= "Thursday" + let dow_4= "Friday" + let dow_5= "Saturday" + let dow_6= "Sunday" + endif + + " if the daynames under the cursor is <= 3, transform + " long daynames to short daynames + if strlen(dow) <= 3 +" call Decho("transform long daynames to short daynames") + let dow_0= strpart(dow_0,0,3) + let dow_1= strpart(dow_1,0,3) + let dow_2= strpart(dow_2,0,3) + let dow_3= strpart(dow_3,0,3) + let dow_4= strpart(dow_4,0,3) + let dow_5= strpart(dow_5,0,3) + let dow_6= strpart(dow_6,0,3) + endif + + " identify day-of-week under cursor + let idow= 0 + while idow < 7 +" call Decho("dow<".dow."> dow_".idow."<".dow_{idow}.">") + if dow =~ '\c\<'.strpart(dow_{idow},0,3) + break + endif + let idow= idow + 1 + endwhile + if idow >= 7 + echoerr "***error*** misspelled day-of-week <".dow.">" + call s:RestoreUserOptions() +" call Dret("VisBlockIncr : unable to identify day-of-week") + return + endif + + " generate incremented dayname list + norm! `< + norm! gUl + norm! `< + let l = y1 + while l < y2 + norm! j +" call Decho("while [l=".l."] < [y2=".y2."]: line=".line(".")." col[".leftcol.",".rghtcol."] width=".width) + if exists("restrict") && getline(".") !~ restrict + let l= l + 1 + continue + endif + let idow= (idow + incr)%7 + exe 's/\%'.leftcol.'v.\{'.width.'\}/'.dow_{idow}.'/e' + let l= l + 1 + endw + " return from ID + call s:RestoreUserOptions() +" call Dret("VisBlockIncr : ID") + return + endif + + " IM: {{{3 + if method == s:IM + let pat = '^.*\%'.leftcol.'v\(\a\+\)\%'.rghtcol.'v.*$' + let mon = substitute(substitute(curline,pat,'\1','e'),' ','','ge') + let monlen = strlen(mon) + if exists("g:visincr_month") + let mon_0 = substitute(g:visincr_month,'^\([^,]*\),.*$', '\1','') + let mon_1 = substitute(g:visincr_month,'^\%([^,]*,\)\{1}\([^,]*\),.*$', '\1','') + let mon_2 = substitute(g:visincr_month,'^\%([^,]*,\)\{2}\([^,]*\),.*$', '\1','') + let mon_3 = substitute(g:visincr_month,'^\%([^,]*,\)\{3}\([^,]*\),.*$', '\1','') + let mon_4 = substitute(g:visincr_month,'^\%([^,]*,\)\{4}\([^,]*\),.*$', '\1','') + let mon_5 = substitute(g:visincr_month,'^\%([^,]*,\)\{5}\([^,]*\),.*$', '\1','') + let mon_6 = substitute(g:visincr_month,'^\%([^,]*,\)\{6}\([^,]*\),.*$', '\1','') + let mon_7 = substitute(g:visincr_month,'^\%([^,]*,\)\{7}\([^,]*\),.*$', '\1','') + let mon_8 = substitute(g:visincr_month,'^\%([^,]*,\)\{8}\([^,]*\),.*$', '\1','') + let mon_9 = substitute(g:visincr_month,'^\%([^,]*,\)\{9}\([^,]*\),.*$', '\1','') + let mon_10= substitute(g:visincr_month,'^\%([^,]*,\)\{10}\([^,]*\),.*$','\1','') + let mon_11= substitute(g:visincr_month,'^\%([^,]*,\)\{11}\([^,]*\)$', '\1','') + else + let mon_0 = "January" + let mon_1 = "February" + let mon_2 = "March" + let mon_3 = "April" + let mon_4 = "May" + let mon_5 = "June" + let mon_6 = "July" + let mon_7 = "August" + let mon_8 = "September" + let mon_9 = "October" + let mon_10= "November" + let mon_11= "December" + endif + + " identify month under cursor + let imon= 0 + while imon < 12 + if mon =~ '\c\<'.strpart(mon_{imon},0,3) + break + endif + let imon= imon + 1 + endwhile + if imon >= 12 + echoerr "***error*** misspelled month <".mon.">" + call s:RestoreUserOptions() +" call Dret("VisBlockIncr") + return + endif + + " if monthname is three or fewer characters long, + " transform monthnames to three character versions + if strlen(mon) <= 3 +" call Decho("transform monthnames to short versions") + let jmon= 0 + while jmon < 12 + let mon_{jmon} = strpart(mon_{jmon},0,3) + let jmon = jmon + 1 + endwhile + endif + + " generate incremented monthname list + norm! `< + norm! gUl + norm! `< + let l = y1 + while l < y2 + norm! j + if exists("restrict") && getline(".") !~ restrict + let l= l + 1 + continue + endif + let imon= (imon + incr)%12 + exe 's/\%'.leftcol.'v.\{'.width.'\}/'.mon_{imon}.'/e' + let l= l + 1 + endw + " return from IM + call s:RestoreUserOptions() +" call Dret("VisBlockIncr : IM") + return + endif + + " IA: {{{3 + if method == s:IA + let pat = '^.*\%'.leftcol.'v\(\a\).*$' + let letter = substitute(curline,pat,'\1','e') + if letter !~ '\a' + let letter= 'A' + endif + if letter =~ '[a-z]' + let alphabet='abcdefghijklmnopqrstuvwxyz' + else + let alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZ' + endif + let ilet= stridx(alphabet,letter) + + norm! `< + let l = y1 + while l <= y2 +" call Decho("letter<".letter."> l=".l." ilet=".ilet) + exe 's/\%'.leftcol.'v.*\%'.rghtcol.'v/'.letter.'/e' + let ilet = (ilet + incr)%26 + let letter = strpart(alphabet,ilet,1) + if l < y2 + silent norm! j + endif + let l= l + 1 + endw + " return from IA + call s:RestoreUserOptions() +" call Dret("VisBlockIncr : IA") + return + endif + + let pat = '^.*\%'.leftcol.'v\( \=[0-9]\{1,4}\)'.g:visincr_datedivset.'\( \=[0-9]\{1,2}\)'.g:visincr_datedivset.'\( \=[0-9]\{1,4}\)\%'.rghtcol.'v.*$' + let datediv= substitute(curline,'^.*\%'.leftcol.'v\%( \=[0-9]\{1,4}\)\('.g:visincr_datedivset.'\).*$','\1','') +" call Decho("datediv<".datediv.">") + + " IMDY: {{{3 + if method == s:IMDY + let m = substitute(substitute(curline,pat,'\1',''),' ','','ge')+0 + let d = substitute(substitute(curline,pat,'\2',''),' ','','ge')+0 + let y = substitute(substitute(curline,pat,'\3',''),' ','','ge')+0 + let type = 2 +" call Decho("IMDY: y=".y." m=".m." d=".d." leftcol=".leftcol." rghtcol=".rghtcol) + + " IYMD: {{{3 + elseif method == s:IYMD + let y = substitute(substitute(curline,pat,'\1',''),' ','','ge')+0 + let m = substitute(substitute(curline,pat,'\2',''),' ','','ge')+0 + let d = substitute(substitute(curline,pat,'\3',''),' ','','ge')+0 + let type = 1 +" call Decho("IYMD: y=".y." m=".m." d=".d." leftcol=".leftcol." rghtcol=".rghtcol) + + " IDMY: {{{3 + elseif method == s:IDMY + let d = substitute(substitute(curline,pat,'\1',''),' ','','ge')+0 + let m = substitute(substitute(curline,pat,'\2',''),' ','','ge')+0 + let y = substitute(substitute(curline,pat,'\3',''),' ','','ge')+0 + let type = 3 +" call Decho("IDMY: y=".y." m=".m." d=".d." leftcol=".leftcol." rghtcol=".rghtcol) + else + echoerr "***error*** in script" +" call Dret("VisBlockIncr -- method#".method." not supported") + return + endif + + " Julian day/Calendar day calculations {{{3 + try + let julday= calutil#Cal2Jul(y,m,d) + catch /^Vim\%((\a\+)\)\=:E/ + echoerr "***error*** you need calutil.vim! (:help visincr-calutil)" +" call Dret("VisBlockIncr") + return + endtry + norm! `< + let l = y1 + while l <= y2 + if exists("restrict") && getline(".") !~ restrict + norm! j + let l= l + 1 + continue + endif + let doy = calutil#Jul2Cal(julday,type) + + " IYMD: {{{3 + if type == 1 + let doy = substitute(doy,'^\d/',leaddate.'&','e') + let doy = substitute(doy,'/\(\d/\)','/'.leaddate.'\1','e') + let doy = substitute(doy,'/\(\d\)$','/'.leaddate.'\1','e') + + " IMDY IDMY: {{{3 + else + let doy = substitute(doy,'^\d/',' &','e') + let doy = substitute(doy,'/\(\d/\)','/'.leaddate.'\1','e') + let doy = substitute(doy,'/\(\d\)$','/'.leaddate.'\1','e') + endif + + " use user's date divider + if datediv != '/' + let doy= substitute(doy,'/',datediv,'g') + else + let doy= escape(doy,'/') + endif +" call Decho("doy<".doy.">") + + if leaddate != ' ' + let doy= substitute(doy,' ',leaddate,'ge') + endif +" call Decho('exe s/\%'.leftcol.'v.*\%'.rghtcol.'v/'.doy.'/e') + exe 's/\%'.leftcol.'v.*\%'.rghtcol.'v/'.doy.'/e' + let l = l + 1 + let julday= julday + incr + if l <= y2 + norm! j + endif + endw + call s:RestoreUserOptions() +" call Dret("VisBlockIncr : IMDY IYMD IDMY ID IM") + return + endif " IMDY IYMD IDMY ID IM + + " I II IX IIX IO IIO IR IIR: {{{3 + " construct a line from the first line that only has the number in it + let rml = rghtcol - leftcol + let rmlp1 = rml + 1 + let lm1 = leftcol - 1 +" call Decho("rmlp1=[rghtcol=".rghtcol."]-[leftcol=".leftcol."]+1=".rmlp1) +" call Decho("lm1 =[leftcol=".leftcol."]-1=".lm1) + + if lm1 <= 0 + " region beginning at far left +" call Decho("handle visblock at far left") + let lm1 = 1 + let pat = '^\([0-9 \t]\{1,'.rmlp1.'}\).*$' + if method == s:IX || method == s:IIX + let pat = '^\([0-9a-fA-F \t]\{1,'.rmlp1.'}\).*$' + elseif method == s:IR || method == s:IIR + if getline(".") =~ '^\(.\{-}\)\%'.leftcol.'v\([0-9 \t]\{1,'.rmlp1.'}\).*$' + " need to convert arabic notation to roman numeral + let pat = '^\([0-9IVXCLM) \t]\{1,'.rmlp1.'}\).*$' + else + let pat = '^\([IVXCLM) \t]\{1,'.rmlp1.'}\).*$' + endif + else + let pat = '^\([0-9 \t]\{1,'.rmlp1.'}\).*$' + endif + let cnt = substitute(getline("'<"),pat,'\1',"") + + else + " region not beginning at far left +" call Decho("handle visblock not at far left") + if method == s:IX || method == s:IIX + let pat = '^\(.\{-}\)\%'.leftcol.'v\([0-9a-fA-F \t]\{1,'.rmlp1.'}\).*$' + elseif method == s:IO || method == s:IIO + let pat = '^\(.\{-}\)\%'.leftcol.'v\([0-7 \t]\{1,'.rmlp1.'}\).*$' + elseif method == s:IR || method == s:IIR +" call Decho('test: ^\(.\{-}\)\%'.leftcol.'v\([0-9 \t]\{1,'.rmlp1.'}\).*$') + if getline(".") =~ '^\(.\{-}\)\%'.leftcol.'v\([0-9 \t]\{1,'.rmlp1.'}\).*$' + " need to convert arabic notation to roman numeral + let pat = '^\(.\{-}\)\%'.leftcol.'v\([0-9IVXCLM \t]\{1,'.rmlp1.'}\).*$' + else + let pat = '^\(.\{-}\)\%'.leftcol.'v\([IVXCLM \t]\{1,'.rmlp1.'}\).*$' + endif + else + let pat = '^\(.\{-}\)\%'.leftcol.'v\([0-9 \t]\{1,'.rmlp1.'}\).*$' + endif +" call Decho("pat<".pat.">") + let cnt = substitute(getline("'<"),pat,'\2',"") + endif + + let cntlen = strlen(cnt) + let cnt = substitute(cnt,'\s','',"ge") + let ocnt = cnt +" call Decho("cntlen=".cntlen." cnt=".cnt." ocnt=".ocnt." (before I*[XOR] subs)") + + if method == s:IX || method == s:IIX + let cnt= substitute(cnt,'^0*\([1-9a-fA-F]\|0$\)','\1',"ge") + elseif method == s:IO || method == s:IIO + let cnt= substitute(cnt,'^0*\([1-7]\|0$\)','\1',"ge") + elseif method == s:IR || method == s:IIR + let cnt= substitute(cnt,'^\([IVXCLM]$\)','\1',"ge") + else + let cnt= substitute(cnt,'^0*\([1-9]\|0$\)','\1',"ge") + endif +" call Decho("cnt<".cnt."> pat<".pat.">") + + " left-method with zeros {{{3 + " IF top number is zero-mode + " AND we're justified right + " AND increment is positive + " AND user didn't specify a modeding character + if a:0 < 2 && ( method == s:II || method == s:IIX || method == s:IIO) && cnt != ocnt && incr > 0 + let zfill= '0' + endif + + " determine how much incrementing is needed {{{3 + if method == s:IX || method == s:IIX + let maxcnt= s:Dec2Hex(s:Hex2Dec(cnt) + incr*(y2 - y1)) + elseif method == s:IO || method == s:IIO + let maxcnt= s:Dec2Oct(s:Oct2Dec(cnt) + incr*(y2 - y1)) + elseif method == s:IR || method == s:IIR + if cnt =~ '^\d\+$' + let maxcnt= s:Dec2Rom(cnt + incr*(y2 - y1)) + else + let maxcnt= s:Dec2Rom(s:Rom2Dec(cnt) + incr*(y2 - y1)) + endif + else + let maxcnt= printf("%d",cnt + incr*(y2 - y1)) + endif + let maxcntlen= strlen(maxcnt) + if cntlen > maxcntlen + let maxcntlen= cntlen + endif + if method == s:IIR + let maxcntlen= maxcntlen + 2 + endif +" call Decho("maxcnt=".maxcnt." maxcntlen=".maxcntlen) + + " go through visual block incrementing numbers based {{{3 + " on first number (saved in cnt), taking care to + " avoid inadvertently issuing "0h" commands. + " l == current line number, over range [y1,y2] + norm! `< + let l = y1 + if (method == s:IR || method == s:IIR) && cnt =~ '^\d\+$' + let cnt= s:Dec2Rom(cnt) + endif + while l <= y2 +" call Decho("----- while [l=".l."] <= [y2=".y2."]: cnt=".cnt) + if exists("restrict") && getline(".") !~ restrict +" call Decho("skipping <".getline(".")."> (restrict)") + norm! j + let l= l + 1 + continue + endif + let cntlen= strlen(cnt) + + " Straighten out ragged-right visual-block selection {{{3 + " by appending spaces as needed + norm! $ + while virtcol("$") <= rghtcol + exe "norm! A \" + endwhile + norm! 0 + + " convert visual block line to all spaces {{{3 + if virtcol(".") != leftcol + exe 'norm! /\%'.leftcol."v\" + endif + exe "norm! " . rmlp1 . "r " + + " cnt has gotten bigger than the visually-selected {{{3 + " area allows. Will insert spaces to accommodate it. + if maxcntlen > 0 + let ins= maxcntlen - rmlp1 + else + let ins= strlen(cnt) - rmlp1 + endif + while ins > 0 + exe "norm! i \" + let ins= ins - 1 + endwhile + + " back up to left-of-block (plus optional left-hand-side modeling) {{{3 + norm! 0 + if method == s:I || method == s:IO || method == s:IX || method == s:IR + let bkup= leftcol +" call Decho("bkup= [leftcol=".leftcol."] (due to method)") + elseif maxcntlen > 0 + let bkup= leftcol + maxcntlen - cntlen +" call Decho("bkup= [leftcol=".leftcol."]+[maxcntlen=".maxcntlen."]-[cntlen=".cntlen."]=".bkup) + else + let bkup= leftcol +" call Decho("bkup= [leftcol=".leftcol."] ([maxcntlen=".maxcntlen."]<=0)") + endif + if virtcol(".") != bkup + if bkup == 0 + norm! 0 + else + exe 'norm! /\%'.bkup."v\" + endif + endif + + " replace with count {{{3 +" call Decho("exe norm! R" . cnt . "\") + exe "norm! R" . cnt . "\" + if cntlen > 1 + let cntlenm1= cntlen - 1 + exe "norm! " . cntlenm1 . "h" + endif + if zfill != " " + silent! exe 's/\%'.leftcol.'v\( \+\)/\=substitute(submatch(1)," ","'.zfill.'","ge")/e' + endif + + " set up for next line {{{3 + if l != y2 + norm! j + endif + if method == s:IX || method == s:IIX + let cnt= s:Dec2Hex(s:Hex2Dec(cnt) + incr) + elseif method == s:IO || method == s:IIO + let cnt= s:Dec2Oct(s:Oct2Dec(cnt) + incr) + elseif method == s:IR || method == s:IIR + let cnt= s:Dec2Rom(s:Rom2Dec(cnt) + incr) + else + let cnt= cnt + incr + endif + let l = l + 1 + endw + + " restore options: {{{3 + call s:RestoreUserOptions() +" call Dret("VisBlockIncr") +endfun + +" --------------------------------------------------------------------- +" Hex2Dec: convert hexadecimal to decimal {{{2 +fun! s:Hex2Dec(hex) +" call Dfunc("Hex2Dec(hex=".a:hex.")") + let hex= substitute(string(a:hex),"'","","ge") +" call Decho("hex<".hex.">") + if hex =~ '^-' + let n = strpart(hex,1) + let neg = 1 + else + let n = hex + let neg = 0 + endif +" call Decho("n<".n."> neg=".neg) + + let b10 = 0 + while n != "" + let hexdigit= strpart(n,0,1) + if hexdigit =~ '\d' + let hexdigit= char2nr(hexdigit) - char2nr('0') +" call Decho("0-9: hexdigit=".hexdigit) + elseif hexdigit =~ '[a-f]' + let hexdigit= char2nr(hexdigit) - char2nr('a') + 10 +" call Decho("a-f: hexdigit=".hexdigit) + else + let hexdigit= char2nr(hexdigit) - char2nr('A') + 10 +" call Decho("A-F: hexdigit=".hexdigit) + endif + let b10= 16*b10 + hexdigit + let n = strpart(n,1) + endwhile + + if neg + let b10= -b10 + endif +" call Dret("Hex2Dec ".b10) + return b10 +endfun + +" --------------------------------------------------------------------- +" Dec2Hex: convert decimal to hexadecimal {{{2 +fun! s:Dec2Hex(b10) +" call Dfunc("Dec2Hex(b10=".a:b10.")") + if a:b10 >= 0 + let b10 = a:b10 + let neg = 0 + else + let b10 = -a:b10 + let neg = 1 + endif +" call Decho('b10<'.b10.'> neg='.neg) + if v:version >= 700 + let hex= printf("%x",b10) + else + let hex = "" + while b10 + let hex = '0123456789abcdef'[b10 % 16] . hex + let b10 = b10 / 16 + endwhile + endif + if neg + let hex= "-".hex + endif +" call Dret("Dec2Hex ".hex) + return hex +endfun + +" --------------------------------------------------------------------- +" Oct2Dec: convert octal to decimal {{{2 +fun! s:Oct2Dec(oct) +" call Dfunc("Oct2Dec(oct=".a:oct.")") + if a:oct >= 0 + let n = a:oct + let neg= 0 + else + let n = strpart(a:oct,1) + let neg = 1 + endif + + let b10 = 0 + while n != "" + let octdigit= strpart(n,0,1) + if octdigit =~ '[0-7]' + let octdigit= char2nr(octdigit) - char2nr('0') +" call Decho("octdigit=".octdigit) + else + break + endif + let b10= 8*b10 + octdigit + let n = strpart(n,1) + endwhile + + if neg + let b10= -b10 + endif +" call Dret("Oct2Dec ".b10) + return b10 +endfun + +" --------------------------------------------------------------------- +" Dec2Oct: convert decimal to octal {{{2 +fun! s:Dec2Oct(b10) +" call Dfunc("Dec2Oct(b10=".a:b10.")") + if a:b10 >= 0 + let b10 = a:b10 + let neg = 0 + else + let b10 = -a:b10 + let neg = 1 + endif + + if v:version >= 700 + let oct= printf("%o",b10) + else + let oct = "" + while b10 + let oct = '01234567'[b10 % 8] . oct + let b10 = b10 / 8 + endwhile + endif + + if neg + let oct= "-".oct + endif +" call Dret("Dec2Oct ".oct) + return oct +endfun + +" ------------------------------------------------------------------------------ +" Roman Numeral Support: {{{2 +let s:d2r= [ [ 1000000 , 'M)' ],[900000 , 'CM)' ], [500000 , 'D)' ], [400000 , 'CD)' ], [100000 , 'C)' ], [90000 , 'XC)' ], [50000 , 'L)' ], [40000 , 'XL)' ], [10000 , 'X)' ], [9000 , 'IX)'], [5000 , 'V)'], [1000 , 'M' ], [900 , 'CM'], [500 , 'D'], [400 , 'CD'], [100 , 'C'], [90 , 'XC'], [50 , 'L'], [40 , 'XL'], [10 , 'X'], [9 , 'IX'], [5 , 'V'], [4 , 'IV'], [1 , 'I'] ] + +" --------------------------------------------------------------------- +" Rom2Dec: convert roman numerals to a decimal number {{{2 +fun! s:Rom2Dec(roman) +" call Dfunc("Rom2Dec(".a:roman.")") + let roman = substitute(a:roman,'.','\U&','ge') + let dec = 0 + + while roman != '' + for item in s:d2r + let pat= '^'.item[1] + if roman =~ pat + let dec= dec + item[0] + if strlen(item[1]) > 1 + let roman= strpart(roman,strlen(item[1])-1) + endif + break + endif + endfor + let roman= strpart(roman,1) + endwhile + +" call Dret("Rom2Dec ".dec) + return dec +endfun + +" --------------------------------------------------------------------- +" Dec2Rom: convert a decimal number to roman numerals {{{2 +" Note that since there is no zero or negative integers +" using Roman numerals, attempts to convert such will always +" result in "I". +fun! s:Dec2Rom(dec) +" call Dfunc("Dec2Rom(".a:dec.")") + if a:dec > 0 + let roman = "" + let dec = a:dec + let i = 0 + while dec > 0 + while dec >= s:d2r[i][0] + let dec = dec - s:d2r[i][0] + let roman = roman . s:d2r[i][1] + endwhile + let i= i + 1 + endwhile + else + let roman= "I" + endif +" call Dret("Dec2Rom ".roman) + return roman +endfun + +" --------------------------------------------------------------------- +" SaveUserOptions: {{{2 +fun! s:SaveUserOptions() +" call Dfunc("SaveUserOptions()") + let s:fokeep = &fo + let s:gdkeep = &gd + let s:ickeep = &ic + let s:magickeep = &magic + let s:reportkeep= &report + set fo=tcq magic report=9999 noic nogd +" call Dret("SaveUserOptions") +endfun + +" --------------------------------------------------------------------- +" RestoreUserOptions: {{{2 +fun! s:RestoreUserOptions() +" call Dfunc("RestoreUserOptions()") + let &fo = s:fokeep + let &gd = s:gdkeep + let &ic = s:ickeep + let &magic = s:magickeep + let &report= s:reportkeep +" call Dret("RestoreUserOptions") +endfun + +" --------------------------------------------------------------------- +" Restoration: {{{1 +let &cpo= s:keepcpo +unlet s:keepcpo +" ------------------------------------------------------------------------------ +" Modelines: {{{1 +" vim: ts=4 fdm=marker diff --git a/vimfiles/plugin/visincrPlugin.vim b/vimfiles/plugin/visincrPlugin.vim index 66c0918..d116940 100644 --- a/vimfiles/plugin/visincrPlugin.vim +++ b/vimfiles/plugin/visincrPlugin.vim @@ -1,73 +1,73 @@ -" visincrPlugin.vim: Visual-block incremented lists -" Author: Charles E. Campbell, Jr. Ph.D. -" Date: Jul 18, 2006 -" Public Interface Only -" -" (James 2:19,20 WEB) You believe that God is one. You do well! -" The demons also believe, and shudder. -" But do you want to know, vain man, that -" faith apart from works is dead? - -" --------------------------------------------------------------------- -" Load Once: {{{1 -if &cp || exists("g:loaded_visincrPlugin") - finish -endif -let g:loaded_visincrPlugin = 1 -let s:keepcpo = &cpo -set cpo&vim - -" --------------------------------------------------------------------- -" Methods: {{{1 -let s:I = 0 -let s:II = 1 -let s:IMDY = 2 -let s:IYMD = 3 -let s:IDMY = 4 -let s:ID = 5 -let s:IM = 6 -let s:IA = 7 -let s:IX = 8 -let s:IIX = 9 -let s:IO = 10 -let s:IIO = 11 -let s:IR = 12 -let s:IIR = 13 -let s:RI = 14 -let s:RII = 15 -let s:RIMDY = 16 -let s:RIYMD = 17 -let s:RIDMY = 18 -let s:RID = 19 -let s:RIM = 20 - -" ------------------------------------------------------------------------------ -" Public Interface: {{{1 -com! -ra -complete=expression -na=? I call visincr#VisBlockIncr(s:I , ) -com! -ra -complete=expression -na=* II call visincr#VisBlockIncr(s:II , ) -com! -ra -complete=expression -na=* IMDY call visincr#VisBlockIncr(s:IMDY , ) -com! -ra -complete=expression -na=* IYMD call visincr#VisBlockIncr(s:IYMD , ) -com! -ra -complete=expression -na=* IDMY call visincr#VisBlockIncr(s:IDMY , ) -com! -ra -complete=expression -na=? ID call visincr#VisBlockIncr(s:ID , ) -com! -ra -complete=expression -na=? IM call visincr#VisBlockIncr(s:IM , ) -com! -ra -complete=expression -na=? IA call visincr#VisBlockIncr(s:IA , ) -com! -ra -complete=expression -na=? IX call visincr#VisBlockIncr(s:IX , ) -com! -ra -complete=expression -na=? IIX call visincr#VisBlockIncr(s:IIX , ) -com! -ra -complete=expression -na=? IO call visincr#VisBlockIncr(s:IO , ) -com! -ra -complete=expression -na=? IIO call visincr#VisBlockIncr(s:IIO , ) -com! -ra -complete=expression -na=? IR call visincr#VisBlockIncr(s:IR , ) -com! -ra -complete=expression -na=? IIR call visincr#VisBlockIncr(s:IIR , ) - -com! -ra -complete=expression -na=? RI call visincr#VisBlockIncr(s:RI , ) -com! -ra -complete=expression -na=* RII call visincr#VisBlockIncr(s:RII , ) -com! -ra -complete=expression -na=* RIMDY call visincr#VisBlockIncr(s:RIMDY, ) -com! -ra -complete=expression -na=* RIYMD call visincr#VisBlockIncr(s:RIYMD, ) -com! -ra -complete=expression -na=* RIDMY call visincr#VisBlockIncr(s:RIDMY, ) -com! -ra -complete=expression -na=? RID call visincr#VisBlockIncr(s:RID , ) -com! -ra -complete=expression -na=? RIM call visincr#VisBlockIncr(s:RIM , ) - -" --------------------------------------------------------------------- -" Restoration And Modelines: {{{1 -" vim: ts=4 fdm=marker -let &cpo= s:keepcpo -unlet s:keepcpo +" visincrPlugin.vim: Visual-block incremented lists +" Author: Charles E. Campbell, Jr. Ph.D. +" Date: Jul 18, 2006 +" Public Interface Only +" +" (James 2:19,20 WEB) You believe that God is one. You do well! +" The demons also believe, and shudder. +" But do you want to know, vain man, that +" faith apart from works is dead? + +" --------------------------------------------------------------------- +" Load Once: {{{1 +if &cp || exists("g:loaded_visincrPlugin") + finish +endif +let g:loaded_visincrPlugin = 1 +let s:keepcpo = &cpo +set cpo&vim + +" --------------------------------------------------------------------- +" Methods: {{{1 +let s:I = 0 +let s:II = 1 +let s:IMDY = 2 +let s:IYMD = 3 +let s:IDMY = 4 +let s:ID = 5 +let s:IM = 6 +let s:IA = 7 +let s:IX = 8 +let s:IIX = 9 +let s:IO = 10 +let s:IIO = 11 +let s:IR = 12 +let s:IIR = 13 +let s:RI = 14 +let s:RII = 15 +let s:RIMDY = 16 +let s:RIYMD = 17 +let s:RIDMY = 18 +let s:RID = 19 +let s:RIM = 20 + +" ------------------------------------------------------------------------------ +" Public Interface: {{{1 +com! -ra -complete=expression -na=? I call visincr#VisBlockIncr(s:I , ) +com! -ra -complete=expression -na=* II call visincr#VisBlockIncr(s:II , ) +com! -ra -complete=expression -na=* IMDY call visincr#VisBlockIncr(s:IMDY , ) +com! -ra -complete=expression -na=* IYMD call visincr#VisBlockIncr(s:IYMD , ) +com! -ra -complete=expression -na=* IDMY call visincr#VisBlockIncr(s:IDMY , ) +com! -ra -complete=expression -na=? ID call visincr#VisBlockIncr(s:ID , ) +com! -ra -complete=expression -na=? IM call visincr#VisBlockIncr(s:IM , ) +com! -ra -complete=expression -na=? IA call visincr#VisBlockIncr(s:IA , ) +com! -ra -complete=expression -na=? IX call visincr#VisBlockIncr(s:IX , ) +com! -ra -complete=expression -na=? IIX call visincr#VisBlockIncr(s:IIX , ) +com! -ra -complete=expression -na=? IO call visincr#VisBlockIncr(s:IO , ) +com! -ra -complete=expression -na=? IIO call visincr#VisBlockIncr(s:IIO , ) +com! -ra -complete=expression -na=? IR call visincr#VisBlockIncr(s:IR , ) +com! -ra -complete=expression -na=? IIR call visincr#VisBlockIncr(s:IIR , ) + +com! -ra -complete=expression -na=? RI call visincr#VisBlockIncr(s:RI , ) +com! -ra -complete=expression -na=* RII call visincr#VisBlockIncr(s:RII , ) +com! -ra -complete=expression -na=* RIMDY call visincr#VisBlockIncr(s:RIMDY, ) +com! -ra -complete=expression -na=* RIYMD call visincr#VisBlockIncr(s:RIYMD, ) +com! -ra -complete=expression -na=* RIDMY call visincr#VisBlockIncr(s:RIDMY, ) +com! -ra -complete=expression -na=? RID call visincr#VisBlockIncr(s:RID , ) +com! -ra -complete=expression -na=? RIM call visincr#VisBlockIncr(s:RIM , ) + +" --------------------------------------------------------------------- +" Restoration And Modelines: {{{1 +" vim: ts=4 fdm=marker +let &cpo= s:keepcpo +unlet s:keepcpo