| version 1.3, 2002/08/11 17:14:45 |
version 1.4, 2003/02/16 21:54:32 |
|
|
| "============================================================================= |
"============================================================================= |
| " File: calendar.vim |
" File: calendar.vim |
| " Author: Yasuhiro Matsumoto <mattn_jp@hotmail.com> |
" Author: Yasuhiro Matsumoto <mattn_jp@hotmail.com> |
| " Last Change: Mon, 8 Apr 2002 |
" Last Change: Fri, 10 Jan 2003 |
| " Version: 1.3h |
" Version: 1.3r |
| " Thanks: |
" Thanks: |
| |
" Vikas Agnihotri : bug report |
| |
" Steve Hall : gave a hint for 1.3q |
| |
" James Devenish : bug fix |
| |
" Carl Mueller : gave a hint for 1.3o |
| |
" Klaus Fabritius : bug fix |
| |
" Stucki : gave a hint for 1.3m |
| |
" Rosta : bug report |
| |
" Richard Bair : bug report |
| |
" Yin Hao Liew : bug report |
| " Bill McCarthy : bug fix and gave a hint |
" Bill McCarthy : bug fix and gave a hint |
| " Srinath Avadhanula : bug fix |
" Srinath Avadhanula : bug fix |
| " Ronald Hoellwarth : few advices |
" Ronald Hoellwarth : few advices |
|
|
| " <Leader>ch |
" <Leader>ch |
| " show horizontal calendar ... |
" show horizontal calendar ... |
| " ChangeLog: |
" ChangeLog: |
| |
" 1.3r : bug fix |
| |
" if clicked navigator, cursor go to strange position. |
| |
" 1.3q : bug fix |
| |
" coundn't set calendar_navi |
| |
" in its horizontal direction |
| |
" 1.3p : bug fix |
| |
" coundn't edit diary when the calendar is |
| |
" in its horizontal direction |
| |
" 1.3o : add option calendar_mark, and delete calendar_rmark |
| |
" see Additional: |
| |
" add option calendar_navi |
| |
" see Additional: |
| |
" 1.3n : bug fix |
| |
" s:CalendarSign() should use filereadable(expand(sfile)). |
| |
" 1.3m : tuning |
| |
" using topleft or botright for opening Calendar. |
| |
" use filereadable for s:CalendarSign(). |
| |
" 1.3l : bug fix |
| |
" if set calendar_monday, it can see that Sep 1st is Sat |
| |
" as well as Aug 31st. |
| |
" 1.3k : bug fix |
| |
" it didn't escape the file name on calendar. |
| |
" 1.3j : support for fixed Gregorian |
| |
" added the part of Sep 1752. |
| |
" 1.3i : bug fix |
| |
" Calculation mistake for week number. |
| " 1.3h : add option for position of displaying '*' or '+'. |
" 1.3h : add option for position of displaying '*' or '+'. |
| " see Additional: |
" see Additional: |
| " 1.3g : centering header |
" 1.3g : centering header |
|
|
| " *if you want to place the mark('*' or '+') after the day, |
" *if you want to place the mark('*' or '+') after the day, |
| " add the following to your .vimrc: |
" add the following to your .vimrc: |
| " |
" |
| " let g:calendar_rmark = '' |
" let g:calendar_mark = 'right' |
| |
" |
| |
" NOTE:you can set 'left', 'left-fit', 'right' for this option. |
| |
" |
| |
" *if you want to use navigator, |
| |
" add the following to your .vimrc: |
| |
" |
| |
" let g:calendar_navi = '' |
| |
" |
| |
" NOTE:you can set 'top', 'bottom', 'both' for this option. |
| " |
" |
| " *if you want to replace calendar header, |
" *if you want to replace calendar header, |
| " add the following in your favorite language to your .vimrc: |
" add the following in your favorite language to your .vimrc: |
|
|
| " |
" |
| " :echo calendar_version |
" :echo calendar_version |
| |
|
| let g:calendar_version = "1.3h" |
let g:calendar_version = "1.3r" |
| if !exists("g:calendar_action") |
if !exists("g:calendar_action") |
| let g:calendar_action = "<SID>CalendarDiary" |
let g:calendar_action = "<SID>CalendarDiary" |
| endif |
endif |
|
|
| if !exists("g:calendar_sign") |
if !exists("g:calendar_sign") |
| let g:calendar_sign = "<SID>CalendarSign" |
let g:calendar_sign = "<SID>CalendarSign" |
| endif |
endif |
| |
if !exists("g:calendar_mark") |
| |
\|| (g:calendar_mark != 'left' |
| |
\&& g:calendar_mark != 'left-fit' |
| |
\&& g:calendar_mark != 'right') |
| |
let g:calendar_mark = 'left' |
| |
endif |
| |
if !exists("g:calendar_navi") |
| |
\|| (g:calendar_navi != 'top' |
| |
\&& g:calendar_navi != 'bottom' |
| |
\&& g:calendar_navi != 'both') |
| |
let g:calendar_navi = 'top' |
| |
endif |
| |
|
| "***************************************************************** |
"***************************************************************** |
| "* Calendar commands |
"* Calendar commands |
|
|
| :command! -nargs=* Calendar call Calendar(0,<f-args>) |
:command! -nargs=* Calendar call Calendar(0,<f-args>) |
| :command! -nargs=* CalendarH call Calendar(1,<f-args>) |
:command! -nargs=* CalendarH call Calendar(1,<f-args>) |
| |
|
| nmap <Leader>ca :cal Calendar(0)<CR> |
if !hasmapto("<Plug>Calendar") |
| nmap <Leader>ch :cal Calendar(1)<CR> |
nmap <unique> <Leader>ca <Plug>Calendar |
| |
endif |
| |
if !hasmapto("<Plug>CalendarH") |
| |
nmap <unique> <Leader>ch <Plug>CalendarH |
| |
endif |
| |
nmap <silent> <Plug>Calendar :cal Calendar(0)<CR> |
| |
nmap <silent> <Plug>CalendarH :cal Calendar(1)<CR> |
| |
|
| "***************************************************************** |
"***************************************************************** |
| "* GetToken : get token from source with count |
"* GetToken : get token from source with count |
| Line 220 function! s:CalendarDoAction() |
|
| Line 282 function! s:CalendarDoAction() |
|
| return |
return |
| endif |
endif |
| |
|
| |
" for navi |
| |
if exists('g:calendar_navi') |
| |
let navi = expand("<cword>") |
| |
let curl = line(".") |
| |
if navi == 'Prev' |
| |
exec substitute(maparg('<s-left>', 'n'), '<CR>', '', '') |
| |
elseif navi == 'Next' |
| |
exec substitute(maparg('<s-right>', 'n'), '<CR>', '', '') |
| |
elseif navi == 'Today' |
| |
call Calendar(b:CalendarDir) |
| |
else |
| |
let navi = '' |
| |
endif |
| |
if navi != '' |
| |
if curl < line('$')/2 |
| |
silent execute "normal! gg/".navi."\<cr>" |
| |
else |
| |
silent execute "normal! gg?".navi."\<cr>" |
| |
endif |
| |
return |
| |
endif |
| |
endif |
| |
|
| if b:CalendarDir |
if b:CalendarDir |
| let dir = 'H' |
let dir = 'H' |
| if !exists('g:calendar_monday') && exists('g:calendar_weeknm') |
if !exists('g:calendar_monday') && exists('g:calendar_weeknm') |
| Line 227 function! s:CalendarDoAction() |
|
| Line 312 function! s:CalendarDoAction() |
|
| else |
else |
| let cnr = col('.') - (col('.')%(24)) + 1 |
let cnr = col('.') - (col('.')%(24)) + 1 |
| endif |
endif |
| let lnr = line('.') |
|
| let hdr = 1 |
|
| let week = ((col(".") - cnr - 1 + cnr/49) / 3) |
let week = ((col(".") - cnr - 1 + cnr/49) / 3) |
| else |
else |
| let dir = 'V' |
let dir = 'V' |
| let cnr = 1 |
let cnr = 1 |
| let lnr = 1 |
|
| let hdr = 1 |
|
| while 1 |
|
| if lnr > line('.') |
|
| break |
|
| endif |
|
| let sline = getline(lnr) |
|
| if sline =~ '^\s*$' |
|
| let hdr = lnr + 1 |
|
| endif |
|
| let lnr = lnr + 1 |
|
| endwhile |
|
| let lnr = line('.') |
|
| let week = ((col(".")+1) / 3) - 1 |
let week = ((col(".")+1) / 3) - 1 |
| endif |
endif |
| |
let lnr = 1 |
| |
let hdr = 1 |
| |
while 1 |
| |
if lnr > line('.') |
| |
break |
| |
endif |
| |
let sline = getline(lnr) |
| |
if sline =~ '^\s*$' |
| |
let hdr = lnr + 1 |
| |
endif |
| |
let lnr = lnr + 1 |
| |
endwhile |
| |
let lnr = line('.') |
| if(exists('g:calendar_monday')) |
if(exists('g:calendar_monday')) |
| let week = week + 1 |
let week = week + 1 |
| elseif(week == 0) |
elseif(week == 0) |
| Line 419 function! Calendar(...) |
|
| Line 502 function! Calendar(...) |
|
| let vmdays = 29 |
let vmdays = 29 |
| endif |
endif |
| endif |
endif |
| |
|
| |
" fix Gregorian |
| |
if vyear <= 1752 |
| |
let vnweek = vnweek - 3 |
| |
endif |
| |
|
| let vnweek = vnweek % 7 |
let vnweek = vnweek % 7 |
| |
|
| if exists('g:calendar_monday') |
if exists('g:calendar_monday') |
| " if given g:calendar_monday, the week start with monday |
" if given g:calendar_monday, the week start with monday |
| if vnweek == 0 |
if vnweek == 0 |
| let vnweek = 6 |
let vnweek = 7 |
| endif |
endif |
| let vnweek = vnweek - 1 |
let vnweek = vnweek - 1 |
| elseif exists('g:calendar_weeknm') |
elseif exists('g:calendar_weeknm') |
| " if given g:calendar_weeknm, show week number(ref:ISO8601) |
" if given g:calendar_weeknm, show week number(ref:ISO8601) |
| let viweek = (vparam + 1) / 7 |
let viweek = (vparam + 1) / 7 |
| let vfweek = (vparam + 1) % 7 |
let vfweek = (vparam + 1) % 7 |
| if vnweek == 0 |
if vnweek == 0 |
| let vfweek = vfweek - 7 |
let vfweek = vfweek - 7 |
| |
let viweek = viweek + 1 |
| else |
else |
| let vfweek = vfweek - vnweek |
let vfweek = vfweek - vnweek |
| endif |
endif |
| Line 492 function! Calendar(...) |
|
| Line 582 function! Calendar(...) |
|
| let vwruler = strpart(vwruler,3).' '.strpart(vwruler,0,2) |
let vwruler = strpart(vwruler,3).' '.strpart(vwruler,0,2) |
| endif |
endif |
| let vdisplay2 = vdisplay2.' '.vwruler."\n" |
let vdisplay2 = vdisplay2.' '.vwruler."\n" |
| if exists("g:calendar_rmark") |
if g:calendar_mark == 'right' |
| let vdisplay2 = vdisplay2.' ' |
let vdisplay2 = vdisplay2.' ' |
| endif |
endif |
| |
|
| Line 507 function! Calendar(...) |
|
| Line 597 function! Calendar(...) |
|
| let vtarget = vyear.vmnth.vdaycur |
let vtarget = vyear.vmnth.vdaycur |
| if exists("g:calendar_sign") |
if exists("g:calendar_sign") |
| exe "let vsign = " . g:calendar_sign . "(vdaycur, vmnth, vyear)" |
exe "let vsign = " . g:calendar_sign . "(vdaycur, vmnth, vyear)" |
| |
if vsign != "" |
| |
let vsign = vsign[0] |
| |
if vsign !~ "[+!#$%&@?]" |
| |
let vsign = "+" |
| |
endif |
| |
endif |
| else |
else |
| let vsign = '' |
let vsign = '' |
| endif |
endif |
| if !exists("g:calendar_rmark") |
|
| if vtarget == vtoday |
" show mark |
| let vdisplay2=vdisplay2.'*' |
if g:calendar_mark == 'right' |
| elseif vsign != '' |
if vdaycur < 10 |
| let vdisplay2=vdisplay2.'+' |
|
| else |
|
| let vdisplay2=vdisplay2.' ' |
let vdisplay2=vdisplay2.' ' |
| endif |
endif |
| |
let vdisplay2=vdisplay2.vdaycur |
| |
endif |
| |
if g:calendar_mark == 'left-fit' |
| if vdaycur < 10 |
if vdaycur < 10 |
| let vdisplay2=vdisplay2.' ' |
let vdisplay2=vdisplay2.' ' |
| endif |
endif |
| let vdisplay2=vdisplay2.vdaycur |
endif |
| |
if vtarget == vtoday |
| |
let vdisplay2=vdisplay2.'*' |
| |
elseif vsign != '' |
| |
let vdisplay2=vdisplay2.vsign |
| else |
else |
| |
let vdisplay2=vdisplay2.' ' |
| |
endif |
| |
if g:calendar_mark == 'left' |
| if vdaycur < 10 |
if vdaycur < 10 |
| let vdisplay2=vdisplay2.' ' |
let vdisplay2=vdisplay2.' ' |
| endif |
endif |
| let vdisplay2=vdisplay2.vdaycur |
let vdisplay2=vdisplay2.vdaycur |
| if vtarget == vtoday |
endif |
| let vdisplay2=vdisplay2.'*' |
if g:calendar_mark == 'left-fit' |
| elseif vsign != '' |
let vdisplay2=vdisplay2.vdaycur |
| let vdisplay2=vdisplay2.'+' |
|
| else |
|
| let vdisplay2=vdisplay2.' ' |
|
| endif |
|
| endif |
endif |
| let vdaycur = vdaycur + 1 |
let vdaycur = vdaycur + 1 |
| |
|
| |
" fix Gregorian |
| |
if vyear == 1752 && vmnth == 9 && vdaycur == 3 |
| |
let vdaycur = 14 |
| |
endif |
| |
|
| let vinpcur = vinpcur + 1 |
let vinpcur = vinpcur + 1 |
| if vinpcur % 7 == 0 |
if vinpcur % 7 == 0 |
| if !exists('g:calendar_monday') && exists('g:calendar_weeknm') |
if !exists('g:calendar_monday') && exists('g:calendar_weeknm') |
| if !exists("g:calendar_rmark") |
if g:calendar_mark != 'right' |
| let vdisplay2=vdisplay2.' ' |
let vdisplay2=vdisplay2.' ' |
| endif |
endif |
| " if given g:calendar_weeknm, show week number |
" if given g:calendar_weeknm, show week number |
| Line 563 function! Calendar(...) |
|
| Line 669 function! Calendar(...) |
|
| let viweek = viweek + 1 |
let viweek = viweek + 1 |
| endif |
endif |
| let vdisplay2=vdisplay2."\n" |
let vdisplay2=vdisplay2."\n" |
| if exists("g:calendar_rmark") |
if g:calendar_mark == 'right' |
| let vdisplay2 = vdisplay2.' ' |
let vdisplay2 = vdisplay2.' ' |
| endif |
endif |
| endif |
endif |
| Line 576 function! Calendar(...) |
|
| Line 682 function! Calendar(...) |
|
| let vinpcur = vinpcur + 1 |
let vinpcur = vinpcur + 1 |
| endwhile |
endwhile |
| if !exists('g:calendar_monday') && exists('g:calendar_weeknm') |
if !exists('g:calendar_monday') && exists('g:calendar_weeknm') |
| if !exists("g:calendar_rmark") |
if g:calendar_mark != 'right' |
| let vdisplay2=vdisplay2.' ' |
let vdisplay2=vdisplay2.' ' |
| endif |
endif |
| if viweek < 10 |
if viweek < 10 |
| Line 701 function! Calendar(...) |
|
| Line 807 function! Calendar(...) |
|
| auto BufEnter *Calendar let &titlestring = strftime('%c') |
auto BufEnter *Calendar let &titlestring = strftime('%c') |
| auto BufLeave *Calendar let &titlestring = '' |
auto BufLeave *Calendar let &titlestring = '' |
| |
|
| |
if exists('g:calendar_navi') && dir |
| |
if g:calendar_navi == 'both' |
| |
let vheight = vheight + 4 |
| |
else |
| |
let vheight = vheight + 2 |
| |
endif |
| |
endif |
| |
|
| " or not |
" or not |
| if dir |
if dir |
| execute vheight.'split __Calendar' |
execute 'bo '.vheight.'split __Calendar' |
| else |
else |
| execute vcolumn.'vsplit __Calendar' |
execute 'to '.vcolumn.'vsplit __Calendar' |
| endif |
endif |
| setlocal noswapfile |
setlocal noswapfile |
| setlocal buftype=nowrite |
setlocal buftype=nowrite |
| Line 719 function! Calendar(...) |
|
| Line 833 function! Calendar(...) |
|
| " is this a vertical (0) or a horizontal (1) split? |
" is this a vertical (0) or a horizontal (1) split? |
| endif |
endif |
| let b:CalendarDir=dir |
let b:CalendarDir=dir |
| silent put! =vdisplay1 |
|
| "let save_f=@f |
" navi |
| "let @f=vdisplay1 |
if exists('g:calendar_navi') |
| "silent put! f |
if dir |
| "let @f=save_f |
let navcol = ((vcolumn/2)*3-8) |
| |
else |
| |
let navcol = ((vcolumn/2)-8) |
| |
endif |
| |
|
| |
if g:calendar_navi == 'top' |
| |
execute "normal gg".navcol."i " |
| |
silent exec "normal! i<Prev Today Next>\<cr>\<cr>" |
| |
silent put! =vdisplay1 |
| |
endif |
| |
if g:calendar_navi == 'bottom' |
| |
silent put! =vdisplay1 |
| |
silent exec "normal! Gi\<cr>" |
| |
execute "normal ".navcol."i " |
| |
silent exec "normal! i<Prev Today Next>" |
| |
endif |
| |
if g:calendar_navi == 'both' |
| |
execute "normal gg".navcol."i " |
| |
silent exec "normal! i<Prev Today Next>\<cr>\<cr>" |
| |
silent put! =vdisplay1 |
| |
silent exec "normal! Gi\<cr>" |
| |
execute "normal ".navcol."i " |
| |
silent exec "normal! i<Prev Today Next>" |
| |
endif |
| |
else |
| |
silent put! =vdisplay1 |
| |
endif |
| |
|
| setlocal nomodifiable |
setlocal nomodifiable |
| |
|
| Line 751 function! Calendar(...) |
|
| Line 891 function! Calendar(...) |
|
| execute 'nnoremap <silent> <buffer> q :close<cr>' |
execute 'nnoremap <silent> <buffer> q :close<cr>' |
| |
|
| execute 'nnoremap <silent> <buffer> <cr> :call <SID>CalendarDoAction()<cr>' |
execute 'nnoremap <silent> <buffer> <cr> :call <SID>CalendarDoAction()<cr>' |
| |
execute 'nnoremap <silent> <buffer> <2-LeftMouse> :call <SID>CalendarDoAction()<cr>' |
| "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| "+++ build highlight |
"+++ build highlight |
| "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| " today |
" today |
| syn clear |
syn clear |
| if !exists("g:calendar_rmark") |
if g:calendar_mark =~ 'left' |
| syn match Directory display "\*\s*\d*" |
syn match Directory display "\*\s*\d*" |
| syn match Identifier display "+\s*\d*" |
syn match Identifier display "[+!#$%&@?]\s*\d*" |
| else |
endif |
| |
if g:calendar_mark =~ 'left-fit' |
| |
syn match Directory display "\s*\*\d*" |
| |
syn match Identifier display "\s*[+!#$%&@?]\d*" |
| |
endif |
| |
if g:calendar_mark =~ 'right' |
| syn match Directory display "\d*\*\s*" |
syn match Directory display "\d*\*\s*" |
| syn match Identifier display "\d*+\s*" |
syn match Identifier display "\d*[+!#$%&@?]\s*" |
| endif |
endif |
| " header |
" header |
| syn match Special display "[^ ]*\d\+\/\d\+([^)]*)" |
syn match Special display "[^ ]*\d\+\/\d\+([^)]*)" |
| |
|
| |
" navi |
| |
if exists('g:calendar_navi') |
| |
syn match Search display "\(<Prev\|Next>\)" |
| |
syn match Search display "\sToday\s"hs=s+1,he=e-1 |
| |
endif |
| |
|
| " saturday, sunday |
" saturday, sunday |
| let dayorspace = '\(\*\|\s\)\(\s\|\d\)\(\s\|\d\)' |
let dayorspace = '\(\*\|\s\)\(\s\|\d\)\(\s\|\d\)' |
| if !exists('g:calendar_weeknm') || g:calendar_weeknm <= 2 |
if !exists('g:calendar_weeknm') || g:calendar_weeknm <= 2 |
| Line 863 function! s:CalendarDiary(day, month, ye |
|
| Line 1015 function! s:CalendarDiary(day, month, ye |
|
| |
|
| " load the file |
" load the file |
| exe "sp " . sfile |
exe "sp " . sfile |
| exe "auto BufLeave ".sfile." normal! ".vwinnum."\<c-w>\<c-w>" |
exe "auto BufLeave ".escape(sfile, ' \\')." normal! ".vwinnum."<c-w>w" |
| endfunc |
endfunc |
| |
|
| "***************************************************************** |
"***************************************************************** |
|
|
| "***************************************************************** |
"***************************************************************** |
| function! s:CalendarSign(day, month, year) |
function! s:CalendarSign(day, month, year) |
| let sfile = g:calendar_diary."/".a:year."/".a:month."/".a:day.".cal" |
let sfile = g:calendar_diary."/".a:year."/".a:month."/".a:day.".cal" |
| return expand(sfile) |
return filereadable(expand(sfile)) |
| endfunction |
endfunction |