calendar.vim 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. if !exists("g:calendar_action")
  2. let g:calendar_action = "calendar#diary"
  3. endif
  4. if !exists("g:calendar_sign")
  5. let g:calendar_sign = "calendar#sign"
  6. endif
  7. if !exists("g:calendar_mark")
  8. \|| (g:calendar_mark != 'left'
  9. \&& g:calendar_mark != 'left-fit'
  10. \&& g:calendar_mark != 'right')
  11. let g:calendar_mark = 'left'
  12. endif
  13. if !exists("g:calendar_navi")
  14. \|| (g:calendar_navi != 'top'
  15. \&& g:calendar_navi != 'bottom'
  16. \&& g:calendar_navi != 'both'
  17. \&& g:calendar_navi != '')
  18. let g:calendar_navi = 'top'
  19. endif
  20. if !exists("g:calendar_navi_label")
  21. let g:calendar_navi_label = "Prev,Today,Next"
  22. endif
  23. if !exists("g:calendar_diary_list_curr_idx")
  24. let g:calendar_diary_list_curr_idx = 0
  25. endif
  26. if !exists("g:calendar_diary")
  27. if exists("g:calendar_diary_list") && len(g:calendar_diary_list) > 0 && g:calendar_diary_list_curr_idx >= 0 && g:calendar_diary_list_curr_idx < len(g:calendar_diary_list)
  28. let g:calendar_diary = g:calendar_diary_list[g:calendar_diary_list_curr_idx].path
  29. let g:calendar_diary_extension = g:calendar_diary_list[g:calendar_diary_list_curr_idx].ext
  30. else
  31. let g:calendar_diary = "~/diary"
  32. endif
  33. endif
  34. if !exists("g:calendar_focus_today")
  35. let g:calendar_focus_today = 0
  36. endif
  37. if !exists("g:calendar_datetime")
  38. \|| (g:calendar_datetime != ''
  39. \&& g:calendar_datetime != 'title'
  40. \&& g:calendar_datetime != 'statusline')
  41. let g:calendar_datetime = 'title'
  42. endif
  43. if !exists("g:calendar_options")
  44. let g:calendar_options = "fdc=0 nonu"
  45. if has("+relativenumber") || exists("+relativenumber")
  46. let g:calendar_options .= " nornu"
  47. endif
  48. endif
  49. if !exists("g:calendar_filetype")
  50. let g:calendar_filetype = "markdown"
  51. endif
  52. if !exists("g:calendar_diary_extension")
  53. let g:calendar_diary_extension = ".md"
  54. endif
  55. if !exists("g:calendar_search_grepprg")
  56. let g:calendar_search_grepprg = "grep"
  57. endif
  58. "*****************************************************************
  59. "* Default Calendar key bindings
  60. "*****************************************************************
  61. let s:calendar_keys = {
  62. \ 'close' : 'q',
  63. \ 'do_action' : '<CR>',
  64. \ 'goto_today' : 't',
  65. \ 'show_help' : '?',
  66. \ 'redisplay' : 'r',
  67. \ 'goto_next_month' : '<RIGHT>',
  68. \ 'goto_prev_month' : '<LEFT>',
  69. \ 'goto_next_year' : '<UP>',
  70. \ 'goto_prev_year' : '<DOWN>',
  71. \}
  72. if exists("g:calendar_keys") && type(g:calendar_keys) == 4
  73. let s:calendar_keys = extend(s:calendar_keys, g:calendar_keys)
  74. end
  75. "*****************************************************************
  76. "* CalendarClose : close the calendar
  77. "*----------------------------------------------------------------
  78. "*****************************************************************
  79. function! calendar#close(...)
  80. bw!
  81. endfunction
  82. "*****************************************************************
  83. "* CalendarDoAction : call the action handler function
  84. "*----------------------------------------------------------------
  85. "*****************************************************************
  86. function! calendar#action(...)
  87. " for switch calendar list.
  88. let text = getline(".")
  89. if text =~ "^( )"
  90. let list_idx = 0
  91. let curl = line(".") - 1
  92. while curl>1
  93. if getline(curl) =~ "^([\* ])"
  94. let list_idx += 1
  95. let curl -= 1
  96. else
  97. let g:calendar_diary_list_curr_idx = list_idx
  98. let g:calendar_diary = g:calendar_diary_list[list_idx].path
  99. let g:calendar_diary_extension = g:calendar_diary_list[list_idx].ext
  100. call calendar#show(b:CalendarDir, b:CalendarYear, b:CalendarMonth)
  101. return
  102. endif
  103. endwhile
  104. endif
  105. " for navi
  106. if exists('g:calendar_navi')
  107. let navi = (a:0 > 0)? a:1 : expand("<cWORD>")
  108. let curl = line(".")
  109. let curp = getpos(".")
  110. if navi == '<' . get(split(g:calendar_navi_label, ','), 0, '')
  111. if b:CalendarMonth > 1
  112. call calendar#show(b:CalendarDir, b:CalendarYear, b:CalendarMonth-1)
  113. else
  114. call calendar#show(b:CalendarDir, b:CalendarYear-1, 12)
  115. endif
  116. elseif navi == get(split(g:calendar_navi_label, ','), 2, '') . '>'
  117. if b:CalendarMonth < 12
  118. call calendar#show(b:CalendarDir, b:CalendarYear, b:CalendarMonth+1)
  119. else
  120. call calendar#show(b:CalendarDir, b:CalendarYear+1, 1)
  121. endif
  122. elseif navi == get(split(g:calendar_navi_label, ','), 1, '')
  123. call calendar#show(b:CalendarDir)
  124. if exists('g:calendar_today')
  125. exe "call " . g:calendar_today . "()"
  126. endif
  127. elseif navi == 'NextYear'
  128. call calendar#show(b:CalendarDir, b:CalendarYear + 1, b:CalendarMonth)
  129. call setpos('.', curp)
  130. return
  131. elseif navi == 'PrevYear'
  132. call calendar#show(b:CalendarDir, b:CalendarYear - 1, b:CalendarMonth)
  133. call setpos('.', curp)
  134. return
  135. else
  136. let navi = ''
  137. endif
  138. if navi != ''
  139. if g:calendar_focus_today == 1 && search("\*","w") > 0
  140. silent execute "normal! gg/\*\<cr>"
  141. return
  142. else
  143. if curl < line('$')/2
  144. silent execute "normal! gg0/".navi."\<cr>"
  145. else
  146. silent execute "normal! G$?".navi."\<cr>"
  147. endif
  148. return
  149. endif
  150. endif
  151. endif
  152. " if no action defined return
  153. if !exists("g:calendar_action") || g:calendar_action == ""
  154. return
  155. endif
  156. if b:CalendarDir == 0 || b:CalendarDir == 3
  157. let dir = 'V'
  158. let cnr = 1
  159. let week = ((col(".")+1) / 3) - 1
  160. elseif b:CalendarDir == 1
  161. let dir = 'H'
  162. if exists('g:calendar_weeknm')
  163. let cnr = col('.') - (col('.')%(24+5)) + 1
  164. else
  165. let cnr = col('.') - (col('.')%(24)) + 1
  166. endif
  167. let week = ((col(".") - cnr - 1 + cnr/49) / 3)
  168. elseif b:CalendarDir == 2
  169. let dir = 'T'
  170. let cnr = 1
  171. let week = ((col(".")+1) / 3) - 1
  172. endif
  173. let lnr = 1
  174. let hdr = 1
  175. while 1
  176. if lnr > line('.')
  177. break
  178. endif
  179. let sline = getline(lnr)
  180. if sline =~ '^\s*$'
  181. let hdr = lnr + 1
  182. endif
  183. let lnr = lnr + 1
  184. endwhile
  185. let lnr = line('.')
  186. if(exists('g:calendar_monday'))
  187. let week = week + 1
  188. elseif(week == 0)
  189. let week = 7
  190. endif
  191. if lnr-hdr < 2
  192. return
  193. endif
  194. let sline = substitute(strpart(getline(hdr),cnr,21),'\s*\(.*\)\s*','\1','')
  195. if b:CalendarDir != 2
  196. if (col(".")-cnr) > 21
  197. return
  198. endif
  199. " extract day
  200. if g:calendar_mark == 'right' && col('.') > 1
  201. normal! h
  202. let day = matchstr(expand("<cword>"), '[^0].*')
  203. normal! l
  204. else
  205. let day = matchstr(expand("<cword>"), '[^0].*')
  206. endif
  207. else
  208. let c = col('.')
  209. let day = ''
  210. let lnum = line('.')
  211. let cursorchar = getline(lnum)[col('.') - 1]
  212. while day == '' && lnum > 2 && cursorchar != '-' && cursorchar != '+'
  213. let day = matchstr(getline(lnum), '^.*|\zs[^|]\{-}\%'.c.'c[^|]\{-}\ze|.*$')
  214. let day = matchstr(day, '\d\+')
  215. let lnum = lnum - 1
  216. let cursorchar = getline(lnum)[col('.') - 1]
  217. endwhile
  218. endif
  219. if day == 0
  220. return
  221. endif
  222. " extract year and month
  223. if exists('g:calendar_erafmt') && g:calendar_erafmt !~ "^\s*$"
  224. let year = matchstr(substitute(sline, '/.*', '', ''), '\d\+')
  225. let month = matchstr(substitute(sline, '.*/\(\d\d\=\).*', '\1', ""), '[^0].*')
  226. if g:calendar_erafmt =~ '.*,[+-]*\d\+'
  227. let veranum = substitute(g:calendar_erafmt,'.*,\([+-]*\d\+\)','\1','')
  228. if year-veranum > 0
  229. let year = year-veranum
  230. endif
  231. endif
  232. else
  233. let year = matchstr(substitute(sline, '/.*', '', ''), '[^0].*')
  234. let month = matchstr(substitute(sline, '\d*/\(\d\d\=\).*', '\1', ""), '[^0].*')
  235. endif
  236. " call the action function
  237. exe "call " . g:calendar_action . "(day, month, year, week, dir)"
  238. endfunc
  239. "*****************************************************************
  240. "* Calendar : build calendar
  241. "*----------------------------------------------------------------
  242. "* a1 : direction
  243. "* a2 : month(if given a3, it's year)
  244. "* a3 : if given, it's month
  245. "*****************************************************************
  246. function! calendar#show(...)
  247. "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  248. "+++ ready for build
  249. "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  250. " remember today
  251. " divide strftime('%d') by 1 so as to get "1,2,3 .. 9" instead of "01, 02, 03 .. 09"
  252. let vtoday = strftime('%Y').strftime('%m').strftime('%d')
  253. " get arguments
  254. if a:0 == 0
  255. let dir = 0
  256. let vyear = strftime('%Y')
  257. let vmnth = matchstr(strftime('%m'), '[^0].*')
  258. elseif a:0 == 1
  259. let dir = a:1
  260. let vyear = strftime('%Y')
  261. let vmnth = matchstr(strftime('%m'), '[^0].*')
  262. elseif a:0 == 2
  263. let dir = a:1
  264. let vyear = strftime('%Y')
  265. let vmnth = matchstr(a:2, '^[^0].*')
  266. else
  267. let dir = a:1
  268. let vyear = a:2
  269. let vmnth = matchstr(a:3, '^[^0].*')
  270. endif
  271. " remember constant
  272. let vmnth_org = vmnth
  273. let vyear_org = vyear
  274. if dir != 2
  275. " start with last month
  276. let vmnth = vmnth - 1
  277. if vmnth < 1
  278. let vmnth = 12
  279. let vyear = vyear - 1
  280. endif
  281. endif
  282. " reset display variables
  283. let vdisplay1 = ''
  284. let vheight = 1
  285. let vmcnt = 0
  286. "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  287. "+++ build display
  288. "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  289. if exists("g:calendar_begin")
  290. exe "call " . g:calendar_begin . "()"
  291. endif
  292. if dir == 2
  293. let vmcntmax = 1
  294. let whitehrz = ''
  295. if !exists('b:CalendarDir') && !(bufname('%') == '' && &l:modified == 0)
  296. let width = &columns
  297. let height = &lines - 2
  298. else
  299. let width = winwidth(0)
  300. let height = winheight(0)
  301. endif
  302. let hrz = width / 8 - 5
  303. if hrz < 0
  304. let hrz = 0
  305. endif
  306. let h = 0
  307. while h < hrz
  308. let whitehrz = whitehrz.' '
  309. let h = h + 1
  310. endwhile
  311. let whitehrz = whitehrz.'|'
  312. let navifix = (exists('g:calendar_navi') && g:calendar_navi == 'both') * 2
  313. let vrt = (height - &cmdheight - 3 - navifix) / 6 - 2
  314. if vrt < 0
  315. let vrt = 0
  316. endif
  317. if whitehrz == '|'
  318. let whitevrta = whitehrz
  319. else
  320. let whitevrta = whitehrz[1:]
  321. endif
  322. let h = 0
  323. let leftmargin = (width - (strlen(whitehrz) + 3) * 7 - 1) / 2
  324. let whiteleft = ''
  325. while h < leftmargin
  326. let whiteleft = whiteleft.' '
  327. let h = h + 1
  328. endwhile
  329. let h = 0
  330. let whitevrt = ''
  331. while h < vrt
  332. let whitevrt = whitevrt."\n".whiteleft.'|'
  333. let i = 0
  334. while i < 7
  335. let whitevrt = whitevrt.' '.whitehrz
  336. let i = i + 1
  337. endwhile
  338. let h = h + 1
  339. endwhile
  340. let whitevrt = whitevrt."\n"
  341. let whitevrt2 = whiteleft.'+'
  342. let h = 0
  343. let borderhrz = '---'.substitute(substitute(whitehrz, ' ', '-', 'g'), '|', '+', '')
  344. while h < 7
  345. let whitevrt2 = whitevrt2.borderhrz
  346. let h = h + 1
  347. endwhile
  348. let whitevrtweeknm = whitevrt.whitevrt2."\n"
  349. let whitevrt = whitevrta.whitevrt.whitevrt2."\n"
  350. let fridaycol = (strlen(whitehrz) + 3) * 5 + strlen(whiteleft) + 1
  351. let saturdaycol = (strlen(whitehrz) + 3) * 6 + strlen(whiteleft) + 1
  352. else
  353. let vmcntmax = get(g:, 'calendar_number_of_months', 3)
  354. endif
  355. while vmcnt < vmcntmax
  356. let vcolumn = 22
  357. let vnweek = -1
  358. "--------------------------------------------------------------
  359. "--- calculating
  360. "--------------------------------------------------------------
  361. " set boundary of the month
  362. if vmnth == 1
  363. let vmdays = 31
  364. let vparam = 1
  365. let vsmnth = 'Jan'
  366. elseif vmnth == 2
  367. let vmdays = 28
  368. let vparam = 32
  369. let vsmnth = 'Feb'
  370. elseif vmnth == 3
  371. let vmdays = 31
  372. let vparam = 60
  373. let vsmnth = 'Mar'
  374. elseif vmnth == 4
  375. let vmdays = 30
  376. let vparam = 91
  377. let vsmnth = 'Apr'
  378. elseif vmnth == 5
  379. let vmdays = 31
  380. let vparam = 121
  381. let vsmnth = 'May'
  382. elseif vmnth == 6
  383. let vmdays = 30
  384. let vparam = 152
  385. let vsmnth = 'Jun'
  386. elseif vmnth == 7
  387. let vmdays = 31
  388. let vparam = 182
  389. let vsmnth = 'Jul'
  390. elseif vmnth == 8
  391. let vmdays = 31
  392. let vparam = 213
  393. let vsmnth = 'Aug'
  394. elseif vmnth == 9
  395. let vmdays = 30
  396. let vparam = 244
  397. let vsmnth = 'Sep'
  398. elseif vmnth == 10
  399. let vmdays = 31
  400. let vparam = 274
  401. let vsmnth = 'Oct'
  402. elseif vmnth == 11
  403. let vmdays = 30
  404. let vparam = 305
  405. let vsmnth = 'Nov'
  406. elseif vmnth == 12
  407. let vmdays = 31
  408. let vparam = 335
  409. let vsmnth = 'Dec'
  410. else
  411. echo 'Invalid Year or Month'
  412. return
  413. endif
  414. let vleap = 0
  415. if vyear % 400 == 0
  416. let vleap = 1
  417. if vmnth == 2
  418. let vmdays = 29
  419. elseif vmnth >= 3
  420. let vparam = vparam + 1
  421. endif
  422. elseif vyear % 100 == 0
  423. if vmnth == 2
  424. let vmdays = 28
  425. endif
  426. elseif vyear % 4 == 0
  427. let vleap = 1
  428. if vmnth == 2
  429. let vmdays = 29
  430. elseif vmnth >= 3
  431. let vparam = vparam + 1
  432. endif
  433. endif
  434. " calc vnweek of the day
  435. if vnweek == -1
  436. let vnweek = ( vyear * 365 ) + vparam
  437. let vnweek = vnweek + ( vyear/4 ) - ( vyear/100 ) + ( vyear/400 )
  438. if vleap
  439. let vnweek = vnweek - 1
  440. endif
  441. let vnweek = vnweek - 1
  442. endif
  443. " fix Gregorian
  444. if vyear <= 1752
  445. let vnweek = vnweek - 3
  446. endif
  447. let vnweek = vnweek % 7
  448. if exists('g:calendar_monday')
  449. " if given g:calendar_monday, the week start with monday
  450. if vnweek == 0
  451. let vnweek = 7
  452. endif
  453. let vnweek = vnweek - 1
  454. endif
  455. if exists('g:calendar_weeknm')
  456. " if given g:calendar_weeknm, show week number(ref:ISO8601)
  457. "vparam <= 1. day of month
  458. "vnweek <= 1. weekday of month (0-6)
  459. "viweek <= number of week
  460. "vfweek <= 1. day of year
  461. " Mon Tue Wed Thu Fri Sat Sun
  462. " 6 5 4 3 2 1 0 vfweek
  463. " 0 1 2 3 4 5 6 vnweek
  464. let vfweek =((vparam % 7) -vnweek+ 14-2) % 7
  465. let viweek = (vparam - vfweek-2+7 ) / 7 +1
  466. if vfweek < 3
  467. let viweek = viweek - 1
  468. endif
  469. "vfweekl <=year length
  470. let vfweekl = 52
  471. if vfweek == 3 || (vfweek == 4 && vleap)
  472. let vfweekl = 53
  473. endif
  474. if viweek == 0
  475. "belongs to last week number of previous year
  476. let viweek = 52
  477. let vleap = ((vyear-1) % 4 == 0 &&
  478. \ ((vyear-1) % 100 != 0 || (vyear-1) % 400 == 0))
  479. if vfweek == 2 || (vfweek == 1 && vleap)
  480. let viweek = 53
  481. endif
  482. endif
  483. let vcolumn = vcolumn + 5
  484. if g:calendar_weeknm == 5
  485. let vcolumn = vcolumn - 2
  486. endif
  487. endif
  488. "--------------------------------------------------------------
  489. "--- displaying
  490. "--------------------------------------------------------------
  491. " build header
  492. if exists('g:calendar_erafmt') && g:calendar_erafmt !~ "^\s*$"
  493. if g:calendar_erafmt =~ '.*,[+-]*\d\+'
  494. let veranum = substitute(g:calendar_erafmt,'.*,\([+-]*\d\+\)','\1','')
  495. if vyear+veranum > 0
  496. let vdisplay2 = substitute(g:calendar_erafmt,'\(.*\),.*','\1','')
  497. let vdisplay2 = vdisplay2.(vyear+veranum).'/'.vmnth.'('
  498. else
  499. let vdisplay2 = vyear.'/'.vmnth.'('
  500. endif
  501. else
  502. let vdisplay2 = vyear.'/'.vmnth.'('
  503. endif
  504. let vdisplay2 = strpart(" ",
  505. \ 1,(vcolumn-strlen(vdisplay2))/2-2).vdisplay2
  506. else
  507. let vdisplay2 = vyear.'/'.vmnth.'('
  508. let vdisplay2 = strpart(" ",
  509. \ 1,(vcolumn-strlen(vdisplay2))/2-2).vdisplay2
  510. endif
  511. if exists('g:calendar_mruler') && g:calendar_mruler !~ "^\s*$"
  512. let vdisplay2 = vdisplay2 . get(split(g:calendar_mruler, ','), vmnth-1, '').')'."\n"
  513. else
  514. let vdisplay2 = vdisplay2 . vsmnth.')'."\n"
  515. endif
  516. let vwruler = "Su Mo Tu We Th Fr Sa"
  517. if exists('g:calendar_wruler') && g:calendar_wruler !~ "^\s*$"
  518. let vwruler = g:calendar_wruler
  519. endif
  520. if exists('g:calendar_monday')
  521. let vwruler = strpart(vwruler,stridx(vwruler, ' ') + 1).' '.strpart(vwruler,0,stridx(vwruler, ' '))
  522. endif
  523. if dir == 2
  524. let whiteruler = substitute(substitute(whitehrz, ' ', '_', 'g'), '__', ' ', '')
  525. let vwruler = '| '.substitute(vwruler, ' ', whiteruler.' ', 'g').whiteruler
  526. let vdisplay2 = vdisplay2.whiteleft.vwruler."\n"
  527. else
  528. let vdisplay2 = vdisplay2.' '.vwruler."\n"
  529. endif
  530. if g:calendar_mark == 'right' && dir != 2
  531. let vdisplay2 = vdisplay2.' '
  532. endif
  533. " build calendar
  534. let vinpcur = 0
  535. while (vinpcur < vnweek)
  536. if dir == 2
  537. if vinpcur % 7
  538. let vdisplay2 = vdisplay2.whitehrz
  539. else
  540. let vdisplay2 = vdisplay2.whiteleft.'|'
  541. endif
  542. endif
  543. let vdisplay2 = vdisplay2.' '
  544. let vinpcur = vinpcur + 1
  545. endwhile
  546. let vdaycur = 1
  547. while (vdaycur <= vmdays)
  548. if dir == 2
  549. if vinpcur % 7
  550. let vdisplay2 = vdisplay2.whitehrz
  551. else
  552. let vdisplay2 = vdisplay2.whiteleft.'|'
  553. endif
  554. endif
  555. if vmnth < 10
  556. let vtarget = vyear."0".vmnth
  557. else
  558. let vtarget = vyear.vmnth
  559. endif
  560. if vdaycur < 10
  561. let vtarget = vtarget."0".vdaycur
  562. else
  563. let vtarget = vtarget.vdaycur
  564. endif
  565. if exists("g:calendar_sign") && g:calendar_sign != ""
  566. exe "let vsign = " . g:calendar_sign . "(vdaycur, vmnth, vyear)"
  567. if vsign != ""
  568. let vsign = vsign[0]
  569. if vsign !~ "[+!#$%&@?]"
  570. let vsign = "+"
  571. endif
  572. endif
  573. else
  574. let vsign = ''
  575. endif
  576. " show mark
  577. if g:calendar_mark == 'right'
  578. if vdaycur < 10
  579. let vdisplay2 = vdisplay2.' '
  580. endif
  581. let vdisplay2 = vdisplay2.vdaycur
  582. elseif g:calendar_mark == 'left-fit'
  583. if vdaycur < 10
  584. let vdisplay2 = vdisplay2.' '
  585. endif
  586. endif
  587. if vtarget == vtoday
  588. let vdisplay2 = vdisplay2.'*'
  589. elseif vsign != ''
  590. let vdisplay2 = vdisplay2.vsign
  591. else
  592. let vdisplay2 = vdisplay2.' '
  593. endif
  594. if g:calendar_mark == 'left'
  595. if vdaycur < 10
  596. let vdisplay2 = vdisplay2.' '
  597. endif
  598. let vdisplay2 = vdisplay2.vdaycur
  599. endif
  600. if g:calendar_mark == 'left-fit'
  601. let vdisplay2 = vdisplay2.vdaycur
  602. endif
  603. let vdaycur = vdaycur + 1
  604. " fix Gregorian
  605. if vyear == 1752 && vmnth == 9 && vdaycur == 3
  606. let vdaycur = 14
  607. endif
  608. let vinpcur = vinpcur + 1
  609. if vinpcur % 7 == 0
  610. if exists('g:calendar_weeknm')
  611. if dir == 2
  612. let vdisplay2 = vdisplay2.whitehrz
  613. endif
  614. if g:calendar_mark != 'right'
  615. let vdisplay2 = vdisplay2.' '
  616. endif
  617. " if given g:calendar_weeknm, show week number
  618. if viweek < 10
  619. if g:calendar_weeknm == 1
  620. let vdisplay2 = vdisplay2.'WK0'.viweek
  621. elseif g:calendar_weeknm == 2
  622. let vdisplay2 = vdisplay2.'WK '.viweek
  623. elseif g:calendar_weeknm == 3
  624. let vdisplay2 = vdisplay2.'KW0'.viweek
  625. elseif g:calendar_weeknm == 4
  626. let vdisplay2 = vdisplay2.'KW '.viweek
  627. elseif g:calendar_weeknm == 5
  628. let vdisplay2 = vdisplay2.' '.viweek
  629. endif
  630. else
  631. if g:calendar_weeknm <= 2
  632. let vdisplay2 = vdisplay2.'WK'.viweek
  633. elseif g:calendar_weeknm == 3 || g:calendar_weeknm == 4
  634. let vdisplay2 = vdisplay2.'KW'.viweek
  635. elseif g:calendar_weeknm == 5
  636. let vdisplay2 = vdisplay2.viweek
  637. endif
  638. endif
  639. let viweek = viweek + 1
  640. if viweek > vfweekl
  641. let viweek = 1
  642. endif
  643. endif
  644. let vdisplay2 = vdisplay2."\n"
  645. if g:calendar_mark == 'right' && dir != 2
  646. let vdisplay2 = vdisplay2.' '
  647. endif
  648. endif
  649. endwhile
  650. " if it is needed, fill with space
  651. if vinpcur % 7
  652. while (vinpcur % 7 != 0)
  653. if dir == 2
  654. let vdisplay2 = vdisplay2.whitehrz
  655. endif
  656. let vdisplay2 = vdisplay2.' '
  657. let vinpcur = vinpcur + 1
  658. endwhile
  659. if exists('g:calendar_weeknm')
  660. if dir == 2
  661. let vdisplay2 = vdisplay2.whitehrz
  662. endif
  663. if g:calendar_mark != 'right'
  664. let vdisplay2 = vdisplay2.' '
  665. endif
  666. if viweek < 10
  667. if g:calendar_weeknm == 1
  668. let vdisplay2 = vdisplay2.'WK0'.viweek
  669. elseif g:calendar_weeknm == 2
  670. let vdisplay2 = vdisplay2.'WK '.viweek
  671. elseif g:calendar_weeknm == 3
  672. let vdisplay2 = vdisplay2.'KW0'.viweek
  673. elseif g:calendar_weeknm == 4
  674. let vdisplay2 = vdisplay2.'KW '.viweek
  675. elseif g:calendar_weeknm == 5
  676. let vdisplay2 = vdisplay2.' '.viweek
  677. endif
  678. else
  679. if g:calendar_weeknm <= 2
  680. let vdisplay2 = vdisplay2.'WK'.viweek
  681. elseif g:calendar_weeknm == 3 || g:calendar_weeknm == 4
  682. let vdisplay2 = vdisplay2.'KW'.viweek
  683. elseif g:calendar_weeknm == 5
  684. let vdisplay2 = vdisplay2.viweek
  685. endif
  686. endif
  687. endif
  688. endif
  689. " build display
  690. let vstrline = ''
  691. if dir == 1
  692. " for horizontal
  693. "--------------------------------------------------------------
  694. " +---+ +---+ +------+
  695. " | | | | | |
  696. " | 1 | + | 2 | = | 1' |
  697. " | | | | | |
  698. " +---+ +---+ +------+
  699. "--------------------------------------------------------------
  700. let vtokline = 1
  701. while 1
  702. let vtoken1 = get(split(vdisplay1, "\n"), vtokline-1, '')
  703. let vtoken2 = get(split(vdisplay2, "\n"), vtokline-1, '')
  704. if vtoken1 == '' && vtoken2 == ''
  705. break
  706. endif
  707. while strlen(vtoken1) < (vcolumn+1)*vmcnt
  708. if strlen(vtoken1) % (vcolumn+1) == 0
  709. let vtoken1 = vtoken1.'|'
  710. else
  711. let vtoken1 = vtoken1.' '
  712. endif
  713. endwhile
  714. let vstrline = vstrline.vtoken1.'|'.vtoken2.' '."\n"
  715. let vtokline = vtokline + 1
  716. endwhile
  717. let vdisplay1 = vstrline
  718. let vheight = vtokline-1
  719. elseif (dir == 0 || dir == 3)
  720. " for vertical
  721. "--------------------------------------------------------------
  722. " +---+ +---+ +---+
  723. " | 1 | + | 2 | = | |
  724. " +---+ +---+ | 1'|
  725. " | |
  726. " +---+
  727. "--------------------------------------------------------------
  728. let vtokline = 1
  729. while 1
  730. let vtoken1 = get(split(vdisplay1, "\n"), vtokline-1, '')
  731. if vtoken1 == ''
  732. break
  733. endif
  734. let vstrline = vstrline.vtoken1."\n"
  735. let vtokline = vtokline + 1
  736. let vheight = vheight + 1
  737. endwhile
  738. if vstrline != ''
  739. let vstrline = vstrline.' '."\n"
  740. let vheight = vheight + 1
  741. endif
  742. let vtokline = 1
  743. while 1
  744. let vtoken2 = get(split(vdisplay2, "\n"), vtokline-1, '')
  745. if vtoken2 == ''
  746. break
  747. endif
  748. while strlen(vtoken2) < vcolumn
  749. let vtoken2 = vtoken2.' '
  750. endwhile
  751. let vstrline = vstrline.vtoken2."\n"
  752. let vtokline = vtokline + 1
  753. let vheight = vtokline + 1
  754. endwhile
  755. let vdisplay1 = vstrline
  756. else
  757. let vtokline = 1
  758. while 1
  759. let vtoken1 = get(split(vdisplay1, "\n"), vtokline-1, '')
  760. let vtoken2 = get(split(vdisplay2, "\n"), vtokline-1, '')
  761. if vtoken1 == '' && vtoken2 == ''
  762. break
  763. endif
  764. while strlen(vtoken1) < (vcolumn+1)*vmcnt
  765. if strlen(vtoken1) % (vcolumn+1) == 0
  766. let vtoken1 = vtoken1.'|'
  767. else
  768. let vtoken1 = vtoken1.' '
  769. endif
  770. endwhile
  771. if vtokline > 2
  772. if exists('g:calendar_weeknm')
  773. let vright = whitevrtweeknm
  774. elseif whitehrz == '|'
  775. let vright = whitevrt
  776. else
  777. let vright = ' '.whitevrt
  778. endif
  779. else
  780. let vright = "\n"
  781. endif
  782. let vstrline = vstrline.vtoken1.vtoken2.vright
  783. let vtokline = vtokline + 1
  784. endwhile
  785. let vdisplay1 = vstrline
  786. let vheight = vtokline-1
  787. endif
  788. let vmnth = vmnth + 1
  789. let vmcnt = vmcnt + 1
  790. if vmnth > 12
  791. let vmnth = 1
  792. let vyear = vyear + 1
  793. endif
  794. endwhile
  795. if exists("g:calendar_end")
  796. exe "call " . g:calendar_end . "()"
  797. endif
  798. if a:0 == 0
  799. return vdisplay1
  800. endif
  801. if exists("g:calendar_diary_list") && len(g:calendar_diary_list) > 0
  802. let vdisplay1 = vdisplay1 . "\nCalendars:\n" . repeat("-", vcolumn)
  803. let diary_index = 0
  804. for diary in g:calendar_diary_list
  805. if diary_index == g:calendar_diary_list_curr_idx
  806. let diary_list = "(*) " . diary["name"]
  807. let diary_list = "\n" . diary_list . repeat(" ", vcolumn-len(diary_list))
  808. else
  809. let diary_list = "( ) " . diary["name"]
  810. let diary_list = "\n" . diary_list . repeat(" ", vcolumn-len(diary_list))
  811. endif
  812. let vdisplay1 = vdisplay1 . diary_list
  813. let diary_index = diary_index + 1
  814. endfor
  815. endif
  816. "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  817. "+++ build window
  818. "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  819. " make window
  820. let vwinnum = bufnr('__Calendar')
  821. if getbufvar(vwinnum, 'Calendar') == 'Calendar'
  822. let vwinnum = bufwinnr(vwinnum)
  823. else
  824. let vwinnum = -1
  825. endif
  826. if vwinnum >= 0
  827. " if already exist
  828. if vwinnum != bufwinnr('%')
  829. exe vwinnum . 'wincmd w'
  830. endif
  831. setlocal modifiable
  832. silent %d _
  833. else
  834. " make title
  835. if g:calendar_datetime == "title" && (!exists('s:bufautocommandsset'))
  836. auto BufEnter *Calendar let b:sav_titlestring = &titlestring | let &titlestring = '%{strftime("%c")}'
  837. auto BufLeave *Calendar if exists('b:sav_titlestring') | let &titlestring = b:sav_titlestring | endif
  838. let s:bufautocommandsset = 1
  839. endif
  840. if exists('g:calendar_navi') && dir
  841. if g:calendar_navi == 'both'
  842. let vheight = vheight + 4
  843. else
  844. let vheight = vheight + 2
  845. endif
  846. endif
  847. " or not
  848. if dir == 1
  849. silent execute 'bo '.vheight.'split __Calendar'
  850. setlocal winfixheight
  851. elseif dir == 0
  852. silent execute 'to '.vcolumn.'vsplit __Calendar'
  853. setlocal winfixwidth
  854. elseif dir == 3
  855. silent execute 'bo '.vcolumn.'vsplit __Calendar'
  856. setlocal winfixwidth
  857. elseif bufname('%') == '' && &l:modified == 0
  858. silent execute 'edit __Calendar'
  859. else
  860. silent execute 'tabnew __Calendar'
  861. endif
  862. call s:CalendarBuildKeymap(dir, vyear, vmnth)
  863. setlocal noswapfile
  864. setlocal buftype=nofile
  865. setlocal bufhidden=delete
  866. silent! exe "setlocal " . g:calendar_options
  867. let nontext_columns = &foldcolumn + &nu * &numberwidth
  868. if has("+relativenumber") || exists("+relativenumber")
  869. let nontext_columns += &rnu * &numberwidth
  870. endif
  871. " Without this, the 'sidescrolloff' setting may cause the left side of the
  872. " calendar to disappear if the last inserted element is near the right
  873. " window border.
  874. setlocal nowrap
  875. setlocal norightleft
  876. setlocal modifiable
  877. setlocal nolist
  878. let b:Calendar = 'Calendar'
  879. setlocal filetype=calendar
  880. " is this a vertical (0) or a horizontal (1) split?
  881. if dir != 2
  882. exe vcolumn + nontext_columns . "wincmd |"
  883. endif
  884. endif
  885. if g:calendar_datetime == "statusline"
  886. setlocal statusline=%{strftime('%c')}
  887. endif
  888. let b:CalendarDir = dir
  889. let b:CalendarYear = vyear_org
  890. let b:CalendarMonth = vmnth_org
  891. " navi
  892. if exists('g:calendar_navi')
  893. let navi_label = '<'
  894. \.get(split(g:calendar_navi_label, ','), 0, '').' '
  895. \.get(split(g:calendar_navi_label, ','), 1, '').' '
  896. \.get(split(g:calendar_navi_label, ','), 2, '').'>'
  897. if dir == 1
  898. let navcol = vcolumn + (vcolumn-strlen(navi_label)+2)/2
  899. elseif (dir == 0 ||dir == 3)
  900. let navcol = (vcolumn-strlen(navi_label)+2)/2
  901. else
  902. let navcol = (width - strlen(navi_label)) / 2
  903. endif
  904. if navcol < 3
  905. let navcol = 3
  906. endif
  907. if g:calendar_navi == 'top'
  908. execute "normal gg".navcol."i "
  909. silent exec "normal! a".navi_label."\<cr>\<cr>"
  910. silent put! =vdisplay1
  911. endif
  912. if g:calendar_navi == 'bottom'
  913. silent put! =vdisplay1
  914. silent exec "normal! Gi\<cr>"
  915. execute "normal ".navcol."i "
  916. silent exec "normal! a".navi_label
  917. endif
  918. if g:calendar_navi == 'both'
  919. execute "normal gg".navcol."i "
  920. silent exec "normal! a".navi_label."\<cr>\<cr>"
  921. silent put! =vdisplay1
  922. silent exec "normal! Gi\<cr>"
  923. execute "normal ".navcol."i "
  924. silent exec "normal! a".navi_label
  925. endif
  926. else
  927. silent put! =vdisplay1
  928. endif
  929. setlocal nomodifiable
  930. " In case we've gotten here from insert mode (via <C-O>:Calendar<CR>)...
  931. stopinsert
  932. let vyear = vyear_org
  933. let vmnth = vmnth_org
  934. "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  935. "+++ build highlight
  936. "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  937. " today
  938. syn clear
  939. if g:calendar_mark =~ 'left-fit'
  940. syn match CalToday display "\s*\*\d*"
  941. syn match CalMemo display "\s*[+!#$%&@?]\d*"
  942. elseif g:calendar_mark =~ 'right'
  943. syn match CalToday display "\d*\*\s*"
  944. syn match CalMemo display "\d*[+!#$%&@?]\s*"
  945. else
  946. syn match CalToday display "\*\s*\d*"
  947. syn match CalMemo display "[+!#$%&@?]\s*\d*"
  948. endif
  949. " header
  950. syn match CalHeader display "[^ ]*\d\+\/\d\+([^)]*)"
  951. " navi
  952. if exists('g:calendar_navi')
  953. exec "silent! syn match CalNavi display \"\\(<"
  954. \.get(split(g:calendar_navi_label, ','), 0, '')."\\|"
  955. \.get(split(g:calendar_navi_label, ','), 2, '').">\\)\""
  956. exec "silent! syn match CalNavi display \"\\s"
  957. \.get(split(g:calendar_navi_label, ','), 1, '')."\\s\"hs=s+1,he=e-1"
  958. endif
  959. " saturday, sunday
  960. if exists('g:calendar_monday')
  961. if dir == 1
  962. syn match CalSaturday display /|.\{15}\s\([0-9\ ]\d\)/hs=e-1 contains=ALL
  963. syn match CalSunday display /|.\{18}\s\([0-9\ ]\d\)/hs=e-1 contains=ALL
  964. elseif (dir == 0|| dir == 3)
  965. syn match CalSaturday display /^.\{15}\s\([0-9\ ]\d\)/hs=e-1 contains=ALL
  966. syn match CalSunday display /^.\{18}\s\([0-9\ ]\d\)/hs=e-1 contains=ALL
  967. else
  968. exec printf('syn match CalSaturday display /^.\{%d}\s\?\([0-9\ ]\d\)/hs=e-1 contains=ALL', fridaycol)
  969. exec printf('syn match CalSunday display /^.\{%d}\s\?\([0-9\ ]\d\)/hs=e-1 contains=ALL', saturdaycol)
  970. endif
  971. else
  972. if dir == 1
  973. syn match CalSaturday display /|.\{18}\s\([0-9\ ]\d\)/hs=e-1 contains=ALL
  974. syn match CalSunday display /|\s\([0-9\ ]\d\)/hs=e-1 contains=ALL
  975. elseif (dir == 0 || dir == 3)
  976. syn match CalSaturday display /^.\{18}\s\([0-9\ ]\d\)/hs=e-1 contains=ALL
  977. syn match CalSunday display /^\s\([0-9\ ]\d\)/hs=e-1 contains=ALL
  978. else
  979. exec printf('syn match CalSaturday display /^.\{%d}\s\?\([0-9\ ]\d\)/hs=e-1 contains=ALL', saturdaycol)
  980. syn match CalSunday display /^\s*|\s*\([0-9\ ]\d\)/hs=e-1 contains=ALL
  981. endif
  982. endif
  983. syn match CalCurrList display "^(\*).*$"
  984. " week number
  985. if !exists('g:calendar_weeknm') || g:calendar_weeknm <= 2
  986. syn match CalWeeknm display "WK[0-9\ ]\d"
  987. else
  988. syn match CalWeeknm display "KW[0-9\ ]\d"
  989. endif
  990. " ruler
  991. execute 'syn match CalRuler "'.vwruler.'"'
  992. if search("\*","w") > 0
  993. silent execute "normal! gg/\*\<cr>"
  994. endif
  995. " --+--
  996. if dir == 2
  997. exec "syn match CalNormal display " string(borderhrz)
  998. exec "syn match CalNormal display " string('^'.whiteleft.'+')
  999. endif
  1000. return ''
  1001. endfunction
  1002. "*****************************************************************
  1003. "* make_dir : make directory
  1004. "*----------------------------------------------------------------
  1005. "* dir : directory
  1006. "*****************************************************************
  1007. function! s:make_dir(dir)
  1008. if(has("unix"))
  1009. call system("mkdir " . a:dir)
  1010. let rc = v:shell_error
  1011. elseif(has("win16") || has("win32") || has("win95") ||
  1012. \has("dos16") || has("dos32") || has("os2"))
  1013. call system("mkdir \"" . a:dir . "\"")
  1014. let rc = v:shell_error
  1015. else
  1016. let rc = 1
  1017. endif
  1018. if rc != 0
  1019. call confirm("can't create directory : " . a:dir, "&OK")
  1020. endif
  1021. return rc
  1022. endfunc
  1023. "*****************************************************************
  1024. "* diary : calendar hook function
  1025. "*----------------------------------------------------------------
  1026. "* day : day you actioned
  1027. "* month : month you actioned
  1028. "* year : year you actioned
  1029. "*****************************************************************
  1030. function! calendar#diary(day, month, year, week, dir)
  1031. " build the file name and create directories as needed
  1032. if !isdirectory(expand(g:calendar_diary))
  1033. call confirm("please create diary directory : ".g:calendar_diary, 'OK')
  1034. return
  1035. endif
  1036. let sfile = expand(g:calendar_diary) . "/" . printf("%04d", a:year)
  1037. if isdirectory(sfile) == 0
  1038. if s:make_dir(sfile) != 0
  1039. return
  1040. endif
  1041. endif
  1042. let sfile = sfile . "/" . printf("%02d", a:month)
  1043. if isdirectory(sfile) == 0
  1044. if s:make_dir(sfile) != 0
  1045. return
  1046. endif
  1047. endif
  1048. let sfile = expand(sfile) . "/" . printf("%02d", a:day) . g:calendar_diary_extension
  1049. let sfile = substitute(sfile, ' ', '\\ ', 'g')
  1050. let vbufnr = bufnr('__Calendar')
  1051. " load the file
  1052. exe "wincmd w"
  1053. exe "edit " . sfile
  1054. exe "setfiletype " . g:calendar_filetype
  1055. let dir = getbufvar(vbufnr, "CalendarDir")
  1056. let vyear = getbufvar(vbufnr, "CalendarYear")
  1057. let vmnth = getbufvar(vbufnr, "CalendarMonth")
  1058. exe "auto BufDelete ".escape(sfile, ' \\')." call calendar#show(" . dir . "," . vyear . "," . vmnth . ")"
  1059. endfunc
  1060. "*****************************************************************
  1061. "* sign : calendar sign function
  1062. "*----------------------------------------------------------------
  1063. "* day : day of sign
  1064. "* month : month of sign
  1065. "* year : year of sign
  1066. "*****************************************************************
  1067. function! calendar#sign(day, month, year)
  1068. let sfile = g:calendar_diary."/".printf("%04d", a:year)."/".printf("%02d", a:month)."/".printf("%02d", a:day).g:calendar_diary_extension
  1069. return filereadable(expand(sfile))
  1070. endfunction
  1071. "*****************************************************************
  1072. "* CalendarVar : get variable
  1073. "*----------------------------------------------------------------
  1074. "*****************************************************************
  1075. function! s:CalendarVar(var)
  1076. if !exists(a:var)
  1077. return ''
  1078. endif
  1079. exec 'return ' . a:var
  1080. endfunction
  1081. "*****************************************************************
  1082. "* CalendarBuildKeymap : build keymap
  1083. "*----------------------------------------------------------------
  1084. "*****************************************************************
  1085. function! s:CalendarBuildKeymap(dir, vyear, vmnth)
  1086. " make keymap
  1087. nnoremap <silent> <buffer> <Plug>CalendarClose :call calendar#close()<cr>
  1088. nnoremap <silent> <buffer> <Plug>CalendarDoAction :call calendar#action()<cr>
  1089. nnoremap <silent> <buffer> <Plug>CalendarDoAction :call calendar#action()<cr>
  1090. nnoremap <silent> <buffer> <Plug>CalendarGotoToday :call calendar#show(b:CalendarDir)<cr>
  1091. nnoremap <silent> <buffer> <Plug>CalendarShowHelp :call <SID>CalendarHelp()<cr>
  1092. execute 'nnoremap <silent> <buffer> <Plug>CalendarReDisplay :call calendar#show(' . a:dir . ',' . a:vyear . ',' . a:vmnth . ')<cr>'
  1093. let pnav = get(split(g:calendar_navi_label, ','), 0, '')
  1094. let nnav = get(split(g:calendar_navi_label, ','), 2, '')
  1095. execute 'nnoremap <silent> <buffer> <Plug>CalendarGotoPrevMonth :call calendar#action("<' . pnav . '")<cr>'
  1096. execute 'nnoremap <silent> <buffer> <Plug>CalendarGotoNextMonth :call calendar#action("' . nnav . '>")<cr>'
  1097. execute 'nnoremap <silent> <buffer> <Plug>CalendarGotoPrevYear :call calendar#action("PrevYear")<cr>'
  1098. execute 'nnoremap <silent> <buffer> <Plug>CalendarGotoNextYear :call calendar#action("NextYear")<cr>'
  1099. nmap <buffer> <2-LeftMouse> <Plug>CalendarDoAction
  1100. execute 'nmap <buffer> ' . s:calendar_keys['close'] . ' <Plug>CalendarClose'
  1101. execute 'nmap <buffer> ' . s:calendar_keys['do_action'] . ' <Plug>CalendarDoAction'
  1102. execute 'nmap <buffer> ' . s:calendar_keys['goto_today'] . ' <Plug>CalendarGotoToday'
  1103. execute 'nmap <buffer> ' . s:calendar_keys['show_help'] . ' <Plug>CalendarShowHelp'
  1104. execute 'nmap <buffer> ' . s:calendar_keys['redisplay'] . ' <Plug>CalendarRedisplay'
  1105. execute 'nmap <buffer> ' . s:calendar_keys['goto_next_month'] . ' <Plug>CalendarGotoNextMonth'
  1106. execute 'nmap <buffer> ' . s:calendar_keys['goto_prev_month'] . ' <Plug>CalendarGotoPrevMonth'
  1107. execute 'nmap <buffer> ' . s:calendar_keys['goto_next_year'] . ' <Plug>CalendarGotoNextYear'
  1108. execute 'nmap <buffer> ' . s:calendar_keys['goto_prev_year'] . ' <Plug>CalendarGotoPrevYear'
  1109. endfunction
  1110. "*****************************************************************
  1111. "* CalendarHelp : show help for Calendar
  1112. "*----------------------------------------------------------------
  1113. "*****************************************************************
  1114. function! s:CalendarHelp()
  1115. let ck = s:calendar_keys
  1116. let max_width = max(map(values(ck), 'len(v:val)'))
  1117. let offsets = map(copy(ck), '1 + max_width - len(v:val)')
  1118. echohl SpecialKey
  1119. echo ck['goto_prev_month'] . repeat(' ', offsets['goto_prev_month']) . ': goto prev month'
  1120. echo ck['goto_next_month'] . repeat(' ', offsets['goto_next_month']) . ': goto next month'
  1121. echo ck['goto_prev_year'] . repeat(' ', offsets['goto_prev_year']) . ': goto prev year'
  1122. echo ck['goto_next_year'] . repeat(' ', offsets['goto_next_year']) . ': goto next year'
  1123. echo ck['goto_today'] . repeat(' ', offsets['goto_today']) . ': goto today'
  1124. echo ck['close'] . repeat(' ', offsets['close']) . ': close window'
  1125. echo ck['redisplay'] . repeat(' ', offsets['redisplay']) . ': re-display window'
  1126. echo ck['show_help'] . repeat(' ', offsets['show_help']) . ': show this help'
  1127. if g:calendar_action == "calendar#diary"
  1128. echo ck['do_action'] . repeat(' ', offsets['do_action']) . ': show diary'
  1129. endif
  1130. echo ''
  1131. echohl Question
  1132. let vk = [
  1133. \ 'calendar_erafmt',
  1134. \ 'calendar_mruler',
  1135. \ 'calendar_wruler',
  1136. \ 'calendar_weeknm',
  1137. \ 'calendar_navi_label',
  1138. \ 'calendar_diary',
  1139. \ 'calendar_mark',
  1140. \ 'calendar_navi',
  1141. \]
  1142. let max_width = max(map(copy(vk), 'len(v:val)'))
  1143. for _ in vk
  1144. let v = get(g:, _, '')
  1145. echo _ . repeat(' ', max_width - len(_)) . ' = ' . v
  1146. endfor
  1147. echohl MoreMsg
  1148. echo "[Hit any key]"
  1149. echohl None
  1150. call getchar()
  1151. redraw!
  1152. endfunction
  1153. function! calendar#search(keyword)
  1154. if g:calendar_search_grepprg == "internal"
  1155. exe "vimgrep /" . a:keyword."/" . escape(g:calendar_diary," ") . "/**/*" . g:calendar_diary_extension . "|cw"
  1156. else
  1157. silent execute g:calendar_search_grepprg . " '" . a:keyword . "' " . escape(g:calendar_diary," ") . "/**/*" . g:calendar_diary_extension
  1158. silent execute "cw"
  1159. endif
  1160. endfunction
  1161. hi def link CalNavi Search
  1162. hi def link CalSaturday Statement
  1163. hi def link CalSunday Type
  1164. hi def link CalRuler StatusLine
  1165. hi def link CalWeeknm Comment
  1166. hi def link CalToday Directory
  1167. hi def link CalHeader Special
  1168. hi def link CalMemo Identifier
  1169. hi def link CalNormal Normal
  1170. hi def link CalCurrList Error