├── .gitignore
├── Makefile
├── README.md
├── autoload
└── calendar.vim
├── calendar.vim.vimup
├── doc
└── calendar.txt
└── plugin
└── calendar.vim
/.gitignore:
--------------------------------------------------------------------------------
1 | .gitignore
2 | doc/tags
3 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | all : calendar-vim.zip
2 |
3 | remove-zip:
4 | -rm doc/tags
5 | -rm calendar-vim.zip
6 |
7 | calendar-vim.zip: remove-zip
8 | zip -r calendar-vim.zip autoload plugin doc
9 |
10 | release: calendar-vim.zip
11 | vimup update-script calendar.vim
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | calendar.vim
2 | ============
3 |
4 | `calendar.vim` creates a calendar window you can use within vim. It is useful
5 | in its own right as a calendar-inside-vim. It also provides hooks to customise
6 | its behaviour, making it a good basis for writing new plugins which require
7 | calendar functionality (see `:help calendar-hooks` for more information).
8 |
9 | Installation
10 | ------------
11 |
12 | You can install `calendar.vim` in the usual way, by copying the contents of the
13 | `plugin`, `autoload` and `doc` directories into the equivalent directories
14 | inside `.vim`.
15 |
16 | Alternatively, if you manage your plugins using [pathogen.vim][1], you can
17 | simply clone into the `bundle` directory:
18 |
19 | cd ~/.vim/bundle
20 | git clone git://github.com/mattn/calendar-vim
21 |
22 | Or, using submodules:
23 |
24 | cd ~/.vim
25 | git submodule add git://github.com/mattn/calendar-vim bundle/calendar-vim
26 |
27 | Usage
28 | -----
29 |
30 | Bring up a calendar based on today's date in a vertically split window:
31 |
32 | :Calendar
33 |
34 | Bring up a calendar showing November, 1991 (The month Vim was first released):
35 |
36 | :Calendar 1991 11
37 |
38 | The above calendars can alternatively be displayed in a horizontally split
39 | window:
40 |
41 | :CalendarH
42 |
43 | Bring up a full-screen:
44 |
45 | :CalendarT
46 |
47 | Fast mappings are provided:
48 |
49 | * <LocalLeader>cal: Vertically-split calendar
50 | * <LocalLeader>caL: Horizontally-split calendar
51 |
52 | For full documentation, install the plugin and run `:help calendar` from within
53 | Vim.
54 |
55 | [1]: https://github.com/tpope/vim-pathogen
56 |
--------------------------------------------------------------------------------
/autoload/calendar.vim:
--------------------------------------------------------------------------------
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 | "*****************************************************************
60 | "* Default Calendar key bindings
61 | "*****************************************************************
62 | let s:calendar_keys = {
63 | \ 'close' : 'q',
64 | \ 'do_action' : '',
65 | \ 'goto_today' : 't',
66 | \ 'show_help' : '?',
67 | \ 'redisplay' : 'r',
68 | \ 'goto_next_month' : '',
69 | \ 'goto_prev_month' : '',
70 | \ 'goto_next_year' : '',
71 | \ 'goto_prev_year' : '',
72 | \}
73 |
74 | if exists("g:calendar_keys") && type(g:calendar_keys) == 4
75 | let s:calendar_keys = extend(s:calendar_keys, g:calendar_keys)
76 | end
77 |
78 | "*****************************************************************
79 | "* CalendarClose : close the calendar
80 | "*----------------------------------------------------------------
81 | "*****************************************************************
82 | function! calendar#close(...)
83 | bw!
84 | endfunction
85 |
86 | "*****************************************************************
87 | "* CalendarDoAction : call the action handler function
88 | "*----------------------------------------------------------------
89 | "*****************************************************************
90 | function! calendar#action(...)
91 | " for switch calendar list.
92 | let text = getline(".")
93 | if text =~ "^( )"
94 | let list_idx = 0
95 | let curl = line(".") - 1
96 | while curl>1
97 | if getline(curl) =~ "^([\* ])"
98 | let list_idx += 1
99 | let curl -= 1
100 | else
101 | let g:calendar_diary_list_curr_idx = list_idx
102 | let g:calendar_diary = g:calendar_diary_list[list_idx].path
103 | let g:calendar_diary_extension = g:calendar_diary_list[list_idx].ext
104 | call calendar#show(b:CalendarDir, b:CalendarYear, b:CalendarMonth)
105 | return
106 | endif
107 | endwhile
108 | endif
109 |
110 | " for navi
111 | if exists('g:calendar_navi')
112 | let navi = (a:0 > 0)? a:1 : expand("")
113 | let curl = line(".")
114 | let curp = getpos(".")
115 | if navi == '<' . get(split(g:calendar_navi_label, ','), 0, '')
116 | if b:CalendarMonth > 1
117 | call calendar#show(b:CalendarDir, b:CalendarYear, b:CalendarMonth-1)
118 | else
119 | call calendar#show(b:CalendarDir, b:CalendarYear-1, 12)
120 | endif
121 | elseif navi == get(split(g:calendar_navi_label, ','), 2, '') . '>'
122 | if b:CalendarMonth < 12
123 | call calendar#show(b:CalendarDir, b:CalendarYear, b:CalendarMonth+1)
124 | else
125 | call calendar#show(b:CalendarDir, b:CalendarYear+1, 1)
126 | endif
127 | elseif navi == get(split(g:calendar_navi_label, ','), 1, '')
128 | call calendar#show(b:CalendarDir)
129 | if exists('g:calendar_today')
130 | exe "call " . g:calendar_today . "()"
131 | endif
132 | elseif navi == 'NextYear'
133 | call calendar#show(b:CalendarDir, b:CalendarYear + 1, b:CalendarMonth)
134 | call setpos('.', curp)
135 | return
136 | elseif navi == 'PrevYear'
137 | call calendar#show(b:CalendarDir, b:CalendarYear - 1, b:CalendarMonth)
138 | call setpos('.', curp)
139 | return
140 | else
141 | let navi = ''
142 | endif
143 | if navi != ''
144 | if g:calendar_focus_today == 1 && search("\*","w") > 0
145 | silent execute "normal! gg/\*\"
146 | return
147 | else
148 | if curl < line('$')/2
149 | silent execute "normal! gg0/".navi."\"
150 | else
151 | silent execute "normal! G$?".navi."\"
152 | endif
153 | return
154 | endif
155 | endif
156 | endif
157 |
158 | " if no action defined return
159 | if !exists("g:calendar_action") || g:calendar_action == ""
160 | return
161 | endif
162 |
163 | if b:CalendarDir == 0 || b:CalendarDir == 3
164 | let dir = 'V'
165 | let cnr = 1
166 | let week = ((col(".")+1) / 3) - 1
167 | elseif b:CalendarDir == 1
168 | let dir = 'H'
169 | if exists('g:calendar_weeknm')
170 | let cnr = col('.') - (col('.')%(24+5)) + 1
171 | else
172 | let cnr = col('.') - (col('.')%(24)) + 1
173 | endif
174 | let week = ((col(".") - cnr - 1 + cnr/49) / 3)
175 | elseif b:CalendarDir == 2
176 | let dir = 'T'
177 | let cnr = 1
178 | let week = ((col(".")+1) / 3) - 1
179 | endif
180 | let lnr = 1
181 | let hdr = 1
182 | while 1
183 | if lnr > line('.')
184 | break
185 | endif
186 | let sline = getline(lnr)
187 | if sline =~ '^\s*$'
188 | let hdr = lnr + 1
189 | endif
190 | let lnr = lnr + 1
191 | endwhile
192 | let lnr = line('.')
193 | if(exists('g:calendar_monday'))
194 | let week = week + 1
195 | elseif(week == 0)
196 | let week = 7
197 | endif
198 | if lnr-hdr < 2
199 | return
200 | endif
201 | let sline = substitute(strpart(getline(hdr),cnr,21),'\s*\(.*\)\s*','\1','')
202 | if b:CalendarDir != 2
203 | if (col(".")-cnr) > 21
204 | return
205 | endif
206 |
207 | " extract day
208 | if g:calendar_mark == 'right' && col('.') > 1
209 | normal! h
210 | let day = matchstr(expand(""), '[^0].*')
211 | normal! l
212 | else
213 | let day = matchstr(expand(""), '[^0].*')
214 | endif
215 | else
216 | let c = col('.')
217 | let day = ''
218 | let lnum = line('.')
219 | let cursorchar = getline(lnum)[col('.') - 1]
220 | while day == '' && lnum > 2 && cursorchar != '-' && cursorchar != '+'
221 | let day = matchstr(getline(lnum), '^.*|\zs[^|]\{-}\%'.c.'c[^|]\{-}\ze|.*$')
222 | let day = matchstr(day, '\d\+')
223 | let lnum = lnum - 1
224 | let cursorchar = getline(lnum)[col('.') - 1]
225 | endwhile
226 | endif
227 | if day == 0
228 | return
229 | endif
230 | " extract year and month
231 | if exists('g:calendar_erafmt') && g:calendar_erafmt !~ "^\s*$"
232 | let year = matchstr(substitute(sline, '/.*', '', ''), '\d\+')
233 | let month = matchstr(substitute(sline, '.*/\(\d\d\=\).*', '\1', ""), '[^0].*')
234 | if g:calendar_erafmt =~ '.*,[+-]*\d\+'
235 | let veranum = substitute(g:calendar_erafmt,'.*,\([+-]*\d\+\)','\1','')
236 | if year-veranum > 0
237 | let year = year-veranum
238 | endif
239 | endif
240 | else
241 | let year = matchstr(substitute(sline, '/.*', '', ''), '[^0].*')
242 | let month = matchstr(substitute(sline, '\d*/\(\d\d\=\).*', '\1', ""), '[^0].*')
243 | endif
244 | " call the action function
245 | exe "call " . g:calendar_action . "(day, month, year, week, dir)"
246 | endfunc
247 |
248 | "*****************************************************************
249 | "* Calendar : build calendar
250 | "*----------------------------------------------------------------
251 | "* a1 : direction
252 | "* a2 : month(if given a3, it's year)
253 | "* a3 : if given, it's month
254 | "*****************************************************************
255 | function! calendar#show(...)
256 |
257 | "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
258 | "+++ ready for build
259 | "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
260 | " remember today
261 | " divide strftime('%d') by 1 so as to get "1,2,3 .. 9" instead of "01, 02, 03 .. 09"
262 | let vtoday = strftime('%Y').strftime('%m').strftime('%d')
263 |
264 | " get arguments
265 | if a:0 == 0
266 | let dir = 0
267 | let vyear = strftime('%Y')
268 | let vmnth = matchstr(strftime('%m'), '[^0].*')
269 | elseif a:0 == 1
270 | let dir = a:1
271 | let vyear = strftime('%Y')
272 | let vmnth = matchstr(strftime('%m'), '[^0].*')
273 | elseif a:0 == 2
274 | let dir = a:1
275 | let vyear = strftime('%Y')
276 | let vmnth = matchstr(a:2, '^[^0].*')
277 | else
278 | let dir = a:1
279 | let vyear = a:2
280 | let vmnth = matchstr(a:3, '^[^0].*')
281 | endif
282 |
283 | " remember constant
284 | let vmnth_org = vmnth
285 | let vyear_org = vyear
286 |
287 | if dir != 2
288 | " start with last month
289 | let vmnth = vmnth - 1
290 | if vmnth < 1
291 | let vmnth = 12
292 | let vyear = vyear - 1
293 | endif
294 | endif
295 |
296 | " reset display variables
297 | let vdisplay1 = ''
298 | let vheight = 1
299 | let vmcnt = 0
300 |
301 | "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
302 | "+++ build display
303 | "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
304 | if exists("g:calendar_begin")
305 | exe "call " . g:calendar_begin . "()"
306 | endif
307 | if dir == 2
308 | let vmcntmax = 1
309 | let whitehrz = ''
310 | if !exists('b:CalendarDir') && !(bufname('%') == '' && &l:modified == 0)
311 | let width = &columns
312 | let height = &lines - 2
313 | else
314 | let width = winwidth(0)
315 | let height = winheight(0)
316 | endif
317 | let hrz = width / 8 - 5
318 | if hrz < 0
319 | let hrz = 0
320 | endif
321 | let h = 0
322 | while h < hrz
323 | let whitehrz = whitehrz.' '
324 | let h = h + 1
325 | endwhile
326 | let whitehrz = whitehrz.'|'
327 | let navifix = (exists('g:calendar_navi') && g:calendar_navi == 'both') * 2
328 | let vrt = (height - &cmdheight - 3 - navifix) / 6 - 2
329 | if vrt < 0
330 | let vrt = 0
331 | endif
332 | if whitehrz == '|'
333 | let whitevrta = whitehrz
334 | else
335 | let whitevrta = whitehrz[1:]
336 | endif
337 | let h = 0
338 | let leftmargin = (width - (strlen(whitehrz) + 3) * 7 - 1) / 2
339 | let whiteleft = ''
340 | while h < leftmargin
341 | let whiteleft = whiteleft.' '
342 | let h = h + 1
343 | endwhile
344 | let h = 0
345 | let whitevrt = ''
346 | while h < vrt
347 | let whitevrt = whitevrt."\n".whiteleft.'|'
348 | let i = 0
349 | while i < 7
350 | let whitevrt = whitevrt.' '.whitehrz
351 | let i = i + 1
352 | endwhile
353 | let h = h + 1
354 | endwhile
355 | let whitevrt = whitevrt."\n"
356 | let whitevrt2 = whiteleft.'+'
357 | let h = 0
358 | let borderhrz = '---'.substitute(substitute(whitehrz, ' ', '-', 'g'), '|', '+', '')
359 | while h < 7
360 | let whitevrt2 = whitevrt2.borderhrz
361 | let h = h + 1
362 | endwhile
363 | let whitevrtweeknm = whitevrt.whitevrt2."\n"
364 | let whitevrt = whitevrta.whitevrt.whitevrt2."\n"
365 | let fridaycol = (strlen(whitehrz) + 3) * 5 + strlen(whiteleft) + 1
366 | let saturdaycol = (strlen(whitehrz) + 3) * 6 + strlen(whiteleft) + 1
367 | else
368 | let vmcntmax = get(g:, 'calendar_number_of_months', 3)
369 | endif
370 | while vmcnt < vmcntmax
371 | let vcolumn = 22
372 | let vnweek = -1
373 | "--------------------------------------------------------------
374 | "--- calculating
375 | "--------------------------------------------------------------
376 | " set boundary of the month
377 | if vmnth == 1
378 | let vmdays = 31
379 | let vparam = 1
380 | let vsmnth = 'Jan'
381 | elseif vmnth == 2
382 | let vmdays = 28
383 | let vparam = 32
384 | let vsmnth = 'Feb'
385 | elseif vmnth == 3
386 | let vmdays = 31
387 | let vparam = 60
388 | let vsmnth = 'Mar'
389 | elseif vmnth == 4
390 | let vmdays = 30
391 | let vparam = 91
392 | let vsmnth = 'Apr'
393 | elseif vmnth == 5
394 | let vmdays = 31
395 | let vparam = 121
396 | let vsmnth = 'May'
397 | elseif vmnth == 6
398 | let vmdays = 30
399 | let vparam = 152
400 | let vsmnth = 'Jun'
401 | elseif vmnth == 7
402 | let vmdays = 31
403 | let vparam = 182
404 | let vsmnth = 'Jul'
405 | elseif vmnth == 8
406 | let vmdays = 31
407 | let vparam = 213
408 | let vsmnth = 'Aug'
409 | elseif vmnth == 9
410 | let vmdays = 30
411 | let vparam = 244
412 | let vsmnth = 'Sep'
413 | elseif vmnth == 10
414 | let vmdays = 31
415 | let vparam = 274
416 | let vsmnth = 'Oct'
417 | elseif vmnth == 11
418 | let vmdays = 30
419 | let vparam = 305
420 | let vsmnth = 'Nov'
421 | elseif vmnth == 12
422 | let vmdays = 31
423 | let vparam = 335
424 | let vsmnth = 'Dec'
425 | else
426 | echo 'Invalid Year or Month'
427 | return
428 | endif
429 | let vleap = 0
430 | if vyear % 400 == 0
431 | let vleap = 1
432 | if vmnth == 2
433 | let vmdays = 29
434 | elseif vmnth >= 3
435 | let vparam = vparam + 1
436 | endif
437 | elseif vyear % 100 == 0
438 | if vmnth == 2
439 | let vmdays = 28
440 | endif
441 | elseif vyear % 4 == 0
442 | let vleap = 1
443 | if vmnth == 2
444 | let vmdays = 29
445 | elseif vmnth >= 3
446 | let vparam = vparam + 1
447 | endif
448 | endif
449 |
450 | " calc vnweek of the day
451 | if vnweek == -1
452 | let vnweek = ( vyear * 365 ) + vparam
453 | let vnweek = vnweek + ( vyear/4 ) - ( vyear/100 ) + ( vyear/400 )
454 | if vleap
455 | let vnweek = vnweek - 1
456 | endif
457 | let vnweek = vnweek - 1
458 | endif
459 |
460 | " fix Gregorian
461 | if vyear <= 1752
462 | let vnweek = vnweek - 3
463 | endif
464 |
465 | let vnweek = vnweek % 7
466 |
467 | if exists('g:calendar_monday')
468 | " if given g:calendar_monday, the week start with monday
469 | if vnweek == 0
470 | let vnweek = 7
471 | endif
472 | let vnweek = vnweek - 1
473 | endif
474 |
475 | if exists('g:calendar_weeknm')
476 | " if given g:calendar_weeknm, show week number(ref:ISO8601)
477 |
478 | "vparam <= 1. day of month
479 | "vnweek <= 1. weekday of month (0-6)
480 | "viweek <= number of week
481 | "vfweek <= 1. day of year
482 |
483 | " Mon Tue Wed Thu Fri Sat Sun
484 | " 6 5 4 3 2 1 0 vfweek
485 | " 0 1 2 3 4 5 6 vnweek
486 |
487 | let vfweek =((vparam % 7) -vnweek+ 14-2) % 7
488 | let viweek = (vparam - vfweek-2+7 ) / 7 +1
489 |
490 | if vfweek < 3
491 | let viweek = viweek - 1
492 | endif
493 |
494 | "vfweekl <=year length
495 | let vfweekl = 52
496 | if vfweek == 3 || (vfweek == 4 && vleap)
497 | let vfweekl = 53
498 | endif
499 |
500 | if viweek == 0
501 | "belongs to last week number of previous year
502 | let viweek = 52
503 | let vleap = ((vyear-1) % 4 == 0 &&
504 | \ ((vyear-1) % 100 != 0 || (vyear-1) % 400 == 0))
505 | if vfweek == 2 || (vfweek == 1 && vleap)
506 | let viweek = 53
507 | endif
508 | endif
509 |
510 | let vcolumn = vcolumn + 5
511 | if g:calendar_weeknm == 5
512 | let vcolumn = vcolumn - 2
513 | endif
514 | endif
515 |
516 | "--------------------------------------------------------------
517 | "--- displaying
518 | "--------------------------------------------------------------
519 | " build header
520 | if exists('g:calendar_erafmt') && g:calendar_erafmt !~ "^\s*$"
521 | if g:calendar_erafmt =~ '.*,[+-]*\d\+'
522 | let veranum = substitute(g:calendar_erafmt,'.*,\([+-]*\d\+\)','\1','')
523 | if vyear+veranum > 0
524 | let vdisplay2 = substitute(g:calendar_erafmt,'\(.*\),.*','\1','')
525 | let vdisplay2 = vdisplay2.(vyear+veranum).'/'.vmnth.'('
526 | else
527 | let vdisplay2 = vyear.'/'.vmnth.'('
528 | endif
529 | else
530 | let vdisplay2 = vyear.'/'.vmnth.'('
531 | endif
532 | let vdisplay2 = strpart(" ",
533 | \ 1,(vcolumn-strlen(vdisplay2))/2-2).vdisplay2
534 | else
535 | let vdisplay2 = vyear.'/'.vmnth.'('
536 | let vdisplay2 = strpart(" ",
537 | \ 1,(vcolumn-strlen(vdisplay2))/2-2).vdisplay2
538 | endif
539 | if exists('g:calendar_mruler') && g:calendar_mruler !~ "^\s*$"
540 | let vdisplay2 = vdisplay2 . get(split(g:calendar_mruler, ','), vmnth-1, '').')'."\n"
541 | else
542 | let vdisplay2 = vdisplay2 . vsmnth.')'."\n"
543 | endif
544 | let vwruler = "Su Mo Tu We Th Fr Sa"
545 | if exists('g:calendar_wruler') && g:calendar_wruler !~ "^\s*$"
546 | let vwruler = g:calendar_wruler
547 | endif
548 | if exists('g:calendar_monday')
549 | let vwruler = strpart(vwruler,stridx(vwruler, ' ') + 1).' '.strpart(vwruler,0,stridx(vwruler, ' '))
550 | endif
551 | if dir == 2
552 | let whiteruler = substitute(substitute(whitehrz, ' ', '_', 'g'), '__', ' ', '')
553 | let vwruler = '| '.substitute(vwruler, ' ', whiteruler.' ', 'g').whiteruler
554 | let vdisplay2 = vdisplay2.whiteleft.vwruler."\n"
555 | else
556 | let vdisplay2 = vdisplay2.' '.vwruler."\n"
557 | endif
558 | if g:calendar_mark == 'right' && dir != 2
559 | let vdisplay2 = vdisplay2.' '
560 | endif
561 |
562 | " build calendar
563 | let vinpcur = 0
564 | while (vinpcur < vnweek)
565 | if dir == 2
566 | if vinpcur % 7
567 | let vdisplay2 = vdisplay2.whitehrz
568 | else
569 | let vdisplay2 = vdisplay2.whiteleft.'|'
570 | endif
571 | endif
572 | let vdisplay2 = vdisplay2.' '
573 | let vinpcur = vinpcur + 1
574 | endwhile
575 | let vdaycur = 1
576 | while (vdaycur <= vmdays)
577 | if dir == 2
578 | if vinpcur % 7
579 | let vdisplay2 = vdisplay2.whitehrz
580 | else
581 | let vdisplay2 = vdisplay2.whiteleft.'|'
582 | endif
583 | endif
584 | if vmnth < 10
585 | let vtarget = vyear."0".vmnth
586 | else
587 | let vtarget = vyear.vmnth
588 | endif
589 | if vdaycur < 10
590 | let vtarget = vtarget."0".vdaycur
591 | else
592 | let vtarget = vtarget.vdaycur
593 | endif
594 | if exists("g:calendar_sign") && g:calendar_sign != ""
595 | exe "let vsign = " . g:calendar_sign . "(vdaycur, vmnth, vyear)"
596 | if vsign != ""
597 | let vsign = vsign[0]
598 | if vsign !~ "[+!#$%&@?]"
599 | let vsign = "+"
600 | endif
601 | endif
602 | else
603 | let vsign = ''
604 | endif
605 |
606 | " show mark
607 | if g:calendar_mark == 'right'
608 | if vdaycur < 10
609 | let vdisplay2 = vdisplay2.' '
610 | endif
611 | let vdisplay2 = vdisplay2.vdaycur
612 | elseif g:calendar_mark == 'left-fit'
613 | if vdaycur < 10
614 | let vdisplay2 = vdisplay2.' '
615 | endif
616 | endif
617 | if vtarget == vtoday
618 | let vdisplay2 = vdisplay2.'*'
619 | elseif vsign != ''
620 | let vdisplay2 = vdisplay2.vsign
621 | else
622 | let vdisplay2 = vdisplay2.' '
623 | endif
624 | if g:calendar_mark == 'left'
625 | if vdaycur < 10
626 | let vdisplay2 = vdisplay2.' '
627 | endif
628 | let vdisplay2 = vdisplay2.vdaycur
629 | endif
630 | if g:calendar_mark == 'left-fit'
631 | let vdisplay2 = vdisplay2.vdaycur
632 | endif
633 | let vdaycur = vdaycur + 1
634 |
635 | " fix Gregorian
636 | if vyear == 1752 && vmnth == 9 && vdaycur == 3
637 | let vdaycur = 14
638 | endif
639 |
640 | let vinpcur = vinpcur + 1
641 | if vinpcur % 7 == 0
642 | if exists('g:calendar_weeknm')
643 | if dir == 2
644 | let vdisplay2 = vdisplay2.whitehrz
645 | endif
646 | if g:calendar_mark != 'right'
647 | let vdisplay2 = vdisplay2.' '
648 | endif
649 | " if given g:calendar_weeknm, show week number
650 | if viweek < 10
651 | if g:calendar_weeknm == 1
652 | let vdisplay2 = vdisplay2.'WK0'.viweek
653 | elseif g:calendar_weeknm == 2
654 | let vdisplay2 = vdisplay2.'WK '.viweek
655 | elseif g:calendar_weeknm == 3
656 | let vdisplay2 = vdisplay2.'KW0'.viweek
657 | elseif g:calendar_weeknm == 4
658 | let vdisplay2 = vdisplay2.'KW '.viweek
659 | elseif g:calendar_weeknm == 5
660 | let vdisplay2 = vdisplay2.' '.viweek
661 | endif
662 | else
663 | if g:calendar_weeknm <= 2
664 | let vdisplay2 = vdisplay2.'WK'.viweek
665 | elseif g:calendar_weeknm == 3 || g:calendar_weeknm == 4
666 | let vdisplay2 = vdisplay2.'KW'.viweek
667 | elseif g:calendar_weeknm == 5
668 | let vdisplay2 = vdisplay2.viweek
669 | endif
670 | endif
671 | let viweek = viweek + 1
672 |
673 | if viweek > vfweekl
674 | let viweek = 1
675 | endif
676 |
677 | endif
678 | let vdisplay2 = vdisplay2."\n"
679 | if g:calendar_mark == 'right' && dir != 2
680 | let vdisplay2 = vdisplay2.' '
681 | endif
682 | endif
683 | endwhile
684 |
685 | " if it is needed, fill with space
686 | if vinpcur % 7
687 | while (vinpcur % 7 != 0)
688 | if dir == 2
689 | let vdisplay2 = vdisplay2.whitehrz
690 | endif
691 | let vdisplay2 = vdisplay2.' '
692 | let vinpcur = vinpcur + 1
693 | endwhile
694 | if exists('g:calendar_weeknm')
695 | if dir == 2
696 | let vdisplay2 = vdisplay2.whitehrz
697 | endif
698 | if g:calendar_mark != 'right'
699 | let vdisplay2 = vdisplay2.' '
700 | endif
701 | if viweek < 10
702 | if g:calendar_weeknm == 1
703 | let vdisplay2 = vdisplay2.'WK0'.viweek
704 | elseif g:calendar_weeknm == 2
705 | let vdisplay2 = vdisplay2.'WK '.viweek
706 | elseif g:calendar_weeknm == 3
707 | let vdisplay2 = vdisplay2.'KW0'.viweek
708 | elseif g:calendar_weeknm == 4
709 | let vdisplay2 = vdisplay2.'KW '.viweek
710 | elseif g:calendar_weeknm == 5
711 | let vdisplay2 = vdisplay2.' '.viweek
712 | endif
713 | else
714 | if g:calendar_weeknm <= 2
715 | let vdisplay2 = vdisplay2.'WK'.viweek
716 | elseif g:calendar_weeknm == 3 || g:calendar_weeknm == 4
717 | let vdisplay2 = vdisplay2.'KW'.viweek
718 | elseif g:calendar_weeknm == 5
719 | let vdisplay2 = vdisplay2.viweek
720 | endif
721 | endif
722 | endif
723 | endif
724 |
725 | " build display
726 | let vstrline = ''
727 | if dir == 1
728 | " for horizontal
729 | "--------------------------------------------------------------
730 | " +---+ +---+ +------+
731 | " | | | | | |
732 | " | 1 | + | 2 | = | 1' |
733 | " | | | | | |
734 | " +---+ +---+ +------+
735 | "--------------------------------------------------------------
736 | let vtokline = 1
737 | while 1
738 | let vtoken1 = get(split(vdisplay1, "\n"), vtokline-1, '')
739 | let vtoken2 = get(split(vdisplay2, "\n"), vtokline-1, '')
740 | if vtoken1 == '' && vtoken2 == ''
741 | break
742 | endif
743 | while strlen(vtoken1) < (vcolumn+1)*vmcnt
744 | if strlen(vtoken1) % (vcolumn+1) == 0
745 | let vtoken1 = vtoken1.'|'
746 | else
747 | let vtoken1 = vtoken1.' '
748 | endif
749 | endwhile
750 | let vstrline = vstrline.vtoken1.'|'.vtoken2.' '."\n"
751 | let vtokline = vtokline + 1
752 | endwhile
753 | let vdisplay1 = vstrline
754 | let vheight = vtokline-1
755 | elseif (dir == 0 || dir == 3)
756 | " for vertical
757 | "--------------------------------------------------------------
758 | " +---+ +---+ +---+
759 | " | 1 | + | 2 | = | |
760 | " +---+ +---+ | 1'|
761 | " | |
762 | " +---+
763 | "--------------------------------------------------------------
764 | let vtokline = 1
765 | while 1
766 | let vtoken1 = get(split(vdisplay1, "\n"), vtokline-1, '')
767 | if vtoken1 == ''
768 | break
769 | endif
770 | let vstrline = vstrline.vtoken1."\n"
771 | let vtokline = vtokline + 1
772 | let vheight = vheight + 1
773 | endwhile
774 | if vstrline != ''
775 | let vstrline = vstrline.' '."\n"
776 | let vheight = vheight + 1
777 | endif
778 | let vtokline = 1
779 | while 1
780 | let vtoken2 = get(split(vdisplay2, "\n"), vtokline-1, '')
781 | if vtoken2 == ''
782 | break
783 | endif
784 | while strlen(vtoken2) < vcolumn
785 | let vtoken2 = vtoken2.' '
786 | endwhile
787 | let vstrline = vstrline.vtoken2."\n"
788 | let vtokline = vtokline + 1
789 | let vheight = vtokline + 1
790 | endwhile
791 | let vdisplay1 = vstrline
792 | else
793 | let vtokline = 1
794 | while 1
795 | let vtoken1 = get(split(vdisplay1, "\n"), vtokline-1, '')
796 | let vtoken2 = get(split(vdisplay2, "\n"), vtokline-1, '')
797 | if vtoken1 == '' && vtoken2 == ''
798 | break
799 | endif
800 | while strlen(vtoken1) < (vcolumn+1)*vmcnt
801 | if strlen(vtoken1) % (vcolumn+1) == 0
802 | let vtoken1 = vtoken1.'|'
803 | else
804 | let vtoken1 = vtoken1.' '
805 | endif
806 | endwhile
807 | if vtokline > 2
808 | if exists('g:calendar_weeknm')
809 | let vright = whitevrtweeknm
810 | elseif whitehrz == '|'
811 | let vright = whitevrt
812 | else
813 | let vright = ' '.whitevrt
814 | endif
815 | else
816 | let vright = "\n"
817 | endif
818 | let vstrline = vstrline.vtoken1.vtoken2.vright
819 | let vtokline = vtokline + 1
820 | endwhile
821 | let vdisplay1 = vstrline
822 | let vheight = vtokline-1
823 | endif
824 | let vmnth = vmnth + 1
825 | let vmcnt = vmcnt + 1
826 | if vmnth > 12
827 | let vmnth = 1
828 | let vyear = vyear + 1
829 | endif
830 | endwhile
831 | if exists("g:calendar_end")
832 | exe "call " . g:calendar_end . "()"
833 | endif
834 | if a:0 == 0
835 | return vdisplay1
836 | endif
837 |
838 | if exists("g:calendar_diary_list") && len(g:calendar_diary_list) > 0
839 | let vdisplay1 = vdisplay1 . "\nCalendars:\n" . repeat("-", vcolumn)
840 | let diary_index = 0
841 | for diary in g:calendar_diary_list
842 | if diary_index == g:calendar_diary_list_curr_idx
843 | let diary_list = "(*) " . diary["name"]
844 | let diary_list = "\n" . diary_list . repeat(" ", vcolumn-len(diary_list))
845 | else
846 | let diary_list = "( ) " . diary["name"]
847 | let diary_list = "\n" . diary_list . repeat(" ", vcolumn-len(diary_list))
848 | endif
849 | let vdisplay1 = vdisplay1 . diary_list
850 | let diary_index = diary_index + 1
851 | endfor
852 | endif
853 |
854 | "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
855 | "+++ build window
856 | "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
857 | " make window
858 | let vwinnum = bufnr('__Calendar')
859 | if getbufvar(vwinnum, 'Calendar') == 'Calendar'
860 | let vwinnum = bufwinnr(vwinnum)
861 | else
862 | let vwinnum = -1
863 | endif
864 |
865 | if vwinnum >= 0
866 | " if already exist
867 | if vwinnum != bufwinnr('%')
868 | exe vwinnum . 'wincmd w'
869 | endif
870 | setlocal modifiable
871 | silent %d _
872 | else
873 | " make title
874 | if g:calendar_datetime == "title" && (!exists('s:bufautocommandsset'))
875 | auto BufEnter *Calendar let b:sav_titlestring = &titlestring | let &titlestring = '%{strftime("%c")}'
876 | auto BufLeave *Calendar if exists('b:sav_titlestring') | let &titlestring = b:sav_titlestring | endif
877 | let s:bufautocommandsset = 1
878 | endif
879 |
880 | if exists('g:calendar_navi') && dir
881 | if g:calendar_navi == 'both'
882 | let vheight = vheight + 4
883 | else
884 | let vheight = vheight + 2
885 | endif
886 | endif
887 |
888 | " or not
889 | if dir == 1
890 | silent execute 'bo '.vheight.'split __Calendar'
891 | setlocal winfixheight
892 | elseif dir == 0
893 | silent execute 'to '.vcolumn.'vsplit __Calendar'
894 | setlocal winfixwidth
895 | elseif dir == 3
896 | silent execute 'bo '.vcolumn.'vsplit __Calendar'
897 | setlocal winfixwidth
898 | elseif bufname('%') == '' && &l:modified == 0
899 | silent execute 'edit __Calendar'
900 | else
901 | silent execute 'tabnew __Calendar'
902 | endif
903 | call s:CalendarBuildKeymap(dir, vyear, vmnth)
904 | setlocal noswapfile
905 | setlocal buftype=nofile
906 | setlocal bufhidden=delete
907 | silent! exe "setlocal " . g:calendar_options
908 | let nontext_columns = &foldcolumn + &nu * &numberwidth
909 | if has("+relativenumber") || exists("+relativenumber")
910 | let nontext_columns += &rnu * &numberwidth
911 | endif
912 | " Without this, the 'sidescrolloff' setting may cause the left side of the
913 | " calendar to disappear if the last inserted element is near the right
914 | " window border.
915 | setlocal nowrap
916 | setlocal norightleft
917 | setlocal modifiable
918 | setlocal nolist
919 | let b:Calendar = 'Calendar'
920 | setlocal filetype=calendar
921 | " is this a vertical (0) or a horizontal (1) split?
922 | if dir != 2
923 | exe vcolumn + nontext_columns . "wincmd |"
924 | endif
925 | endif
926 | if g:calendar_datetime == "statusline"
927 | setlocal statusline=%{strftime('%c')}
928 | endif
929 | let b:CalendarDir = dir
930 | let b:CalendarYear = vyear_org
931 | let b:CalendarMonth = vmnth_org
932 |
933 | " navi
934 | if exists('g:calendar_navi')
935 | let navi_label = '<'
936 | \.get(split(g:calendar_navi_label, ','), 0, '').' '
937 | \.get(split(g:calendar_navi_label, ','), 1, '').' '
938 | \.get(split(g:calendar_navi_label, ','), 2, '').'>'
939 | if dir == 1
940 | let navcol = vcolumn + (vcolumn-strlen(navi_label)+2)/2
941 | elseif (dir == 0 ||dir == 3)
942 | let navcol = (vcolumn-strlen(navi_label)+2)/2
943 | else
944 | let navcol = (width - strlen(navi_label)) / 2
945 | endif
946 | if navcol < 3
947 | let navcol = 3
948 | endif
949 |
950 | if g:calendar_navi == 'top'
951 | execute "normal gg".navcol."i "
952 | silent exec "normal! a".navi_label."\\"
953 | silent put! =vdisplay1
954 | endif
955 | if g:calendar_navi == 'bottom'
956 | silent put! =vdisplay1
957 | silent exec "normal! Gi\"
958 | execute "normal ".navcol."i "
959 | silent exec "normal! a".navi_label
960 | endif
961 | if g:calendar_navi == 'both'
962 | execute "normal gg".navcol."i "
963 | silent exec "normal! a".navi_label."\\"
964 | silent put! =vdisplay1
965 | silent exec "normal! Gi\"
966 | execute "normal ".navcol."i "
967 | silent exec "normal! a".navi_label
968 | endif
969 | else
970 | silent put! =vdisplay1
971 | endif
972 |
973 | setlocal nomodifiable
974 | " In case we've gotten here from insert mode (via :Calendar)...
975 | stopinsert
976 |
977 | let vyear = vyear_org
978 | let vmnth = vmnth_org
979 |
980 | "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
981 | "+++ build highlight
982 | "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
983 | " today
984 | syn clear
985 | if g:calendar_mark =~ 'left-fit'
986 | syn match CalToday display "\s*\*\d*"
987 | syn match CalMemo display "\s*[+!#$%&@?]\d*"
988 | elseif g:calendar_mark =~ 'right'
989 | syn match CalToday display "\d*\*\s*"
990 | syn match CalMemo display "\d*[+!#$%&@?]\s*"
991 | else
992 | syn match CalToday display "\*\s*\d*"
993 | syn match CalMemo display "[+!#$%&@?]\s*\d*"
994 | endif
995 | " header
996 | syn match CalHeader display "[^ ]*\d\+\/\d\+([^)]*)"
997 |
998 | " navi
999 | if exists('g:calendar_navi')
1000 | exec "silent! syn match CalNavi display \"\\(<"
1001 | \.get(split(g:calendar_navi_label, ','), 0, '')."\\|"
1002 | \.get(split(g:calendar_navi_label, ','), 2, '').">\\)\""
1003 | exec "silent! syn match CalNavi display \"\\s"
1004 | \.get(split(g:calendar_navi_label, ','), 1, '')."\\s\"hs=s+1,he=e-1"
1005 | endif
1006 |
1007 | " saturday, sunday
1008 |
1009 | if exists('g:calendar_monday')
1010 | if dir == 1
1011 | syn match CalSaturday display /|.\{15}\s\([0-9\ ]\d\)/hs=e-1 contains=ALL
1012 | syn match CalSunday display /|.\{18}\s\([0-9\ ]\d\)/hs=e-1 contains=ALL
1013 | elseif (dir == 0|| dir == 3)
1014 | syn match CalSaturday display /^.\{15}\s\([0-9\ ]\d\)/hs=e-1 contains=ALL
1015 | syn match CalSunday display /^.\{18}\s\([0-9\ ]\d\)/hs=e-1 contains=ALL
1016 | else
1017 | exec printf('syn match CalSaturday display /^.\{%d}\s\?\([0-9\ ]\d\)/hs=e-1 contains=ALL', fridaycol)
1018 | exec printf('syn match CalSunday display /^.\{%d}\s\?\([0-9\ ]\d\)/hs=e-1 contains=ALL', saturdaycol)
1019 | endif
1020 | else
1021 | if dir == 1
1022 | syn match CalSaturday display /|.\{18}\s\([0-9\ ]\d\)/hs=e-1 contains=ALL
1023 | syn match CalSunday display /|\s\([0-9\ ]\d\)/hs=e-1 contains=ALL
1024 | elseif (dir == 0 || dir == 3)
1025 | syn match CalSaturday display /^.\{18}\s\([0-9\ ]\d\)/hs=e-1 contains=ALL
1026 | syn match CalSunday display /^\s\([0-9\ ]\d\)/hs=e-1 contains=ALL
1027 | else
1028 | exec printf('syn match CalSaturday display /^.\{%d}\s\?\([0-9\ ]\d\)/hs=e-1 contains=ALL', saturdaycol)
1029 | syn match CalSunday display /^\s*|\s*\([0-9\ ]\d\)/hs=e-1 contains=ALL
1030 | endif
1031 | endif
1032 |
1033 | syn match CalCurrList display "^(\*).*$"
1034 |
1035 | " week number
1036 | if !exists('g:calendar_weeknm') || g:calendar_weeknm <= 2
1037 | syn match CalWeeknm display "WK[0-9\ ]\d"
1038 | else
1039 | syn match CalWeeknm display "KW[0-9\ ]\d"
1040 | endif
1041 |
1042 | " ruler
1043 | execute 'syn match CalRuler "'.vwruler.'"'
1044 |
1045 | if search("\*","w") > 0
1046 | silent execute "normal! gg/\*\"
1047 | endif
1048 |
1049 | " --+--
1050 | if dir == 2
1051 | exec "syn match CalNormal display " string(borderhrz)
1052 | exec "syn match CalNormal display " string('^'.whiteleft.'+')
1053 | endif
1054 |
1055 | return ''
1056 | endfunction
1057 |
1058 | "*****************************************************************
1059 | "* make_dir : make directory
1060 | "*----------------------------------------------------------------
1061 | "* dir : directory
1062 | "*****************************************************************
1063 | function! s:make_dir(dir)
1064 | if(has("unix"))
1065 | call system("mkdir " . a:dir)
1066 | let rc = v:shell_error
1067 | elseif(has("win16") || has("win32") || has("win95") ||
1068 | \has("dos16") || has("dos32") || has("os2"))
1069 | call system("mkdir \"" . a:dir . "\"")
1070 | let rc = v:shell_error
1071 | else
1072 | let rc = 1
1073 | endif
1074 | if rc != 0
1075 | call confirm("can't create directory : " . a:dir, "&OK")
1076 | endif
1077 | return rc
1078 | endfunc
1079 |
1080 | "*****************************************************************
1081 | "* diary : calendar hook function
1082 | "*----------------------------------------------------------------
1083 | "* day : day you actioned
1084 | "* month : month you actioned
1085 | "* year : year you actioned
1086 | "*****************************************************************
1087 | function! calendar#diary(day, month, year, week, dir)
1088 | " build the file name and create directories as needed
1089 | if !isdirectory(expand(g:calendar_diary))
1090 | call confirm("please create diary directory : ".g:calendar_diary, 'OK')
1091 | return
1092 | endif
1093 | let sfile = expand(g:calendar_diary) . "/" . printf("%04d", a:year)
1094 | if isdirectory(sfile) == 0
1095 | if s:make_dir(sfile) != 0
1096 | return
1097 | endif
1098 | endif
1099 | let sfile = sfile . "/" . printf("%02d", a:month)
1100 | if isdirectory(sfile) == 0
1101 | if s:make_dir(sfile) != 0
1102 | return
1103 | endif
1104 | endif
1105 | let sfile = expand(sfile) . "/" . printf("%02d", a:day) . g:calendar_diary_extension
1106 | let sfile = substitute(sfile, ' ', '\\ ', 'g')
1107 | let vbufnr = bufnr('__Calendar')
1108 |
1109 | " load the file
1110 | exe "wincmd w"
1111 | exe "edit " . sfile
1112 | exe "setfiletype " . g:calendar_filetype
1113 | let dir = getbufvar(vbufnr, "CalendarDir")
1114 | let vyear = getbufvar(vbufnr, "CalendarYear")
1115 | let vmnth = getbufvar(vbufnr, "CalendarMonth")
1116 | exe "auto BufDelete ".escape(sfile, ' \\')." call calendar#show(" . dir . "," . vyear . "," . vmnth . ")"
1117 | endfunc
1118 |
1119 | "*****************************************************************
1120 | "* sign : calendar sign function
1121 | "*----------------------------------------------------------------
1122 | "* day : day of sign
1123 | "* month : month of sign
1124 | "* year : year of sign
1125 | "*****************************************************************
1126 | function! calendar#sign(day, month, year)
1127 | let sfile = g:calendar_diary."/".printf("%04d", a:year)."/".printf("%02d", a:month)."/".printf("%02d", a:day).g:calendar_diary_extension
1128 | return filereadable(expand(sfile))
1129 | endfunction
1130 |
1131 | "*****************************************************************
1132 | "* CalendarVar : get variable
1133 | "*----------------------------------------------------------------
1134 | "*****************************************************************
1135 | function! s:CalendarVar(var)
1136 | if !exists(a:var)
1137 | return ''
1138 | endif
1139 | exec 'return ' . a:var
1140 | endfunction
1141 |
1142 | "*****************************************************************
1143 | "* CalendarBuildKeymap : build keymap
1144 | "*----------------------------------------------------------------
1145 | "*****************************************************************
1146 | function! s:CalendarBuildKeymap(dir, vyear, vmnth)
1147 | " make keymap
1148 | nnoremap CalendarClose :call calendar#close()
1149 | nnoremap CalendarDoAction :call calendar#action()
1150 | nnoremap CalendarDoAction :call calendar#action()
1151 | nnoremap CalendarGotoToday :call calendar#show(b:CalendarDir)
1152 | nnoremap CalendarShowHelp :call CalendarHelp()
1153 | execute 'nnoremap CalendarReDisplay :call calendar#show(' . a:dir . ',' . a:vyear . ',' . a:vmnth . ')'
1154 | let pnav = get(split(g:calendar_navi_label, ','), 0, '')
1155 | let nnav = get(split(g:calendar_navi_label, ','), 2, '')
1156 | execute 'nnoremap CalendarGotoPrevMonth :call calendar#action("<' . pnav . '")'
1157 | execute 'nnoremap CalendarGotoNextMonth :call calendar#action("' . nnav . '>")'
1158 | execute 'nnoremap CalendarGotoPrevYear :call calendar#action("PrevYear")'
1159 | execute 'nnoremap CalendarGotoNextYear :call calendar#action("NextYear")'
1160 |
1161 | nmap <2-LeftMouse> CalendarDoAction
1162 |
1163 | execute 'nmap ' . s:calendar_keys['close'] . ' CalendarClose'
1164 | execute 'nmap ' . s:calendar_keys['do_action'] . ' CalendarDoAction'
1165 | execute 'nmap ' . s:calendar_keys['goto_today'] . ' CalendarGotoToday'
1166 | execute 'nmap ' . s:calendar_keys['show_help'] . ' CalendarShowHelp'
1167 | execute 'nmap ' . s:calendar_keys['redisplay'] . ' CalendarRedisplay'
1168 |
1169 | execute 'nmap ' . s:calendar_keys['goto_next_month'] . ' CalendarGotoNextMonth'
1170 | execute 'nmap ' . s:calendar_keys['goto_prev_month'] . ' CalendarGotoPrevMonth'
1171 | execute 'nmap ' . s:calendar_keys['goto_next_year'] . ' CalendarGotoNextYear'
1172 | execute 'nmap ' . s:calendar_keys['goto_prev_year'] . ' CalendarGotoPrevYear'
1173 | endfunction
1174 |
1175 | "*****************************************************************
1176 | "* CalendarHelp : show help for Calendar
1177 | "*----------------------------------------------------------------
1178 | "*****************************************************************
1179 | function! s:CalendarHelp()
1180 | let ck = s:calendar_keys
1181 | let max_width = max(map(values(ck), 'len(v:val)'))
1182 | let offsets = map(copy(ck), '1 + max_width - len(v:val)')
1183 |
1184 | echohl SpecialKey
1185 | echo ck['goto_prev_month'] . repeat(' ', offsets['goto_prev_month']) . ': goto prev month'
1186 | echo ck['goto_next_month'] . repeat(' ', offsets['goto_next_month']) . ': goto next month'
1187 | echo ck['goto_prev_year'] . repeat(' ', offsets['goto_prev_year']) . ': goto prev year'
1188 | echo ck['goto_next_year'] . repeat(' ', offsets['goto_next_year']) . ': goto next year'
1189 | echo ck['goto_today'] . repeat(' ', offsets['goto_today']) . ': goto today'
1190 | echo ck['close'] . repeat(' ', offsets['close']) . ': close window'
1191 | echo ck['redisplay'] . repeat(' ', offsets['redisplay']) . ': re-display window'
1192 | echo ck['show_help'] . repeat(' ', offsets['show_help']) . ': show this help'
1193 | if g:calendar_action == "calendar#diary"
1194 | echo ck['do_action'] . repeat(' ', offsets['do_action']) . ': show diary'
1195 | endif
1196 | echo ''
1197 | echohl Question
1198 |
1199 | let vk = [
1200 | \ 'calendar_erafmt',
1201 | \ 'calendar_mruler',
1202 | \ 'calendar_wruler',
1203 | \ 'calendar_weeknm',
1204 | \ 'calendar_navi_label',
1205 | \ 'calendar_diary',
1206 | \ 'calendar_mark',
1207 | \ 'calendar_navi',
1208 | \]
1209 | let max_width = max(map(copy(vk), 'len(v:val)'))
1210 |
1211 | for _ in vk
1212 | let v = get(g:, _, '')
1213 | echo _ . repeat(' ', max_width - len(_)) . ' = ' . v
1214 | endfor
1215 | echohl MoreMsg
1216 | echo "[Hit any key]"
1217 | echohl None
1218 | call getchar()
1219 | redraw!
1220 | endfunction
1221 |
1222 | function! calendar#search(keyword)
1223 | if g:calendar_search_grepprg == "internal"
1224 | exe "vimgrep /" . a:keyword."/" . escape(g:calendar_diary," ") . "/**/*" . g:calendar_diary_extension . "|cw"
1225 | else
1226 | silent execute g:calendar_search_grepprg . " '" . a:keyword . "' " . escape(g:calendar_diary," ") . "/**/*" . g:calendar_diary_extension
1227 | silent execute "cw"
1228 | endif
1229 | endfunction
1230 |
1231 | hi def link CalNavi Search
1232 | hi def link CalSaturday Statement
1233 | hi def link CalSunday Type
1234 | hi def link CalRuler StatusLine
1235 | hi def link CalWeeknm Comment
1236 | hi def link CalToday Directory
1237 | hi def link CalHeader Special
1238 | hi def link CalMemo Identifier
1239 | hi def link CalNormal Normal
1240 | hi def link CalCurrList Error
1241 |
--------------------------------------------------------------------------------
/calendar.vim.vimup:
--------------------------------------------------------------------------------
1 | script_name: calendar.vim
2 | script_id: '52'
3 | script_type: utility
4 | script_package: calendar-vim.zip
5 | script_version: '2.9'
6 | required_vim_version: '7.2'
7 | summary: Calendar
8 |
9 | detailed_description: |
10 | This script create calender window.
11 | This don't use the external program(cal).
12 |
13 | install_details: |
14 | Copy calendar.vim to your plugin directory.
15 |
16 | versions:
17 | - '2.9': |
18 | [fix] missing file
19 | - '2.8': |
20 | [fix] fix keymap
21 | - '2.7': |
22 | vim7ish, customizable key bindings
23 | - '2.6': |
24 | new weeknumber format
25 | - '2.5': |
26 | [fix] 7.2 don't have relativenumber.
27 | - '2.4': |
28 | Applied patch from SethMilliken: added g:calendar_options . default is 'fdc=0 nonu nornu' . you can overwrite default behavior of calendar window.
29 | - '2.3': |
30 | Applied patch from bw1: fixed weeknum function.
31 | - '2.2': |
32 | Applied patch:
33 | http://gist.github.com/355513#file_customizable_keymap.diff
34 | http://gist.github.com/355513#file_winfixwidth.diff
35 | - '2.1': |
36 | Applied patch from thinca. Thanks.
37 | - '2.0': |
38 | Applied patch from Ingo Karkat. Thanks.
39 |
40 | - ENH: Added a config setting g:calendar_datetime. This allows to remove the
41 | display of the current date/time in the title (I don't like it), and offers the
42 | window's statusline as an alternative.
43 |
44 | - BUG: The checks for g:calendar_action and g:calendar_sign should also check
45 | for an existing, but empty variable. Otherwise, it is not possible to disable it
46 | in a .vimrc, because the sourcing of calendar.vim would initialize the variables.
47 |
48 | - BUG: In s:CalendarDoAction(), the check for g:calendar_action must come after
49 | the "navi" handling; otherwise "navi" breaks if g:calendar_action is disabled
50 | (see above).
51 |
52 | - ENH: The :set wrapscan is ugly, because it is a global setting. The search()
53 | commands already pass the 'w' flag, so the only remaining issue were the
54 | searches via /. I modified the 'G0/...' search to 'G$?' (i.e. backward from end
55 | of buffer), so that 'wrapscan' isn't required any more. (Even better would be to
56 | use search() for these jumps, too.) With this, I can also completely get rid of
57 | the autocmds in case one does not want the date/time in the title, neither (see
58 | above).
59 |
60 | - Using :setlocal buftype=nofile instead of =nowrite; this is more suitable for
61 | this kind of scratch buffer, and avoids that the path may be shown in the title
62 | / statusline (depending on the customization).
63 |
64 | - BUG: Replaced :setlocal nowrap with 'wrap'. Without this, the 'sidescrolloff'
65 | setting may cause the left side of the calendar to disappear if the last
66 | inserted element is near the right window border. 'wrap' shouldn't matter,
67 | anyway, and 'sidescrolloff' is a global setting, unfortunately.
68 | Try :set sidescrolloff=3 in combination with :let g:calendar_navi = 'bottom' to
69 | reproduce.
70 |
71 | - BUG: The :normal i... for the navi rendering causes a trailing space after the
72 | "Next>" button. This way, I cannot quickly type "G$" to activate the next
73 | button. Now using :normal a... to append. This causes the entire navi to shift
74 | one character to the right, but you could fix this by decreasing the column
75 | counter.
76 |
77 | - ENH: Use :stopinsert in case we've gotten here from insert mode (via
78 | :Calendar)...
79 |
80 | - Using :wincmd w instead of :normal ; it's simpler. (And you should always
81 | use :normal! (with a bang) to avoid interference with user remappings!)
82 |
83 | - ENH: I noticed that and do the same thing, but in different
84 | ways (one uses the navi and the latter is called by the former). I dropped the
85 | unintuitive shift mappings and instead do the jumps consistently in the navi,
86 | using the b:Calendar... variables instead of that ugly maparg() stuff.
87 |
88 | - ENH: I noticed that and do the same thing. I changed /
89 | to move an entire year, so one can quickly let the years pass...
90 |
91 | - ENH: the 'q' mapping now returns to the previous window, not the first one.
92 | - '1.9': |
93 | This is an upgrade for calendar.vim. use nnoremap.
94 | - '1.8': |
95 | This is an upgrade for calendar.vim. fixed E382 while closing diary.
96 |
--------------------------------------------------------------------------------
/doc/calendar.txt:
--------------------------------------------------------------------------------
1 | *calendar.txt* Calendar utility for vim
2 |
3 | Author: Yasuhiro Matsumoto
4 |
5 | INTRODUCTION *calendar*
6 |
7 | This script creates a calendar window in vim. It does not rely on any
8 | external program, such as cal, etc.
9 |
10 | COMMANDS *calendar-commands*
11 |
12 | calendar.vim makes the following commands available:
13 |
14 | *calendar-:Calendar*
15 | :Calendar [[year] month] Show calendar at this year and this month in a
16 | vertical split. When [year] is omitted, the
17 | calendar will show the given month in the current
18 | year. When both [year] and [month] are omitted, the
19 | calendar will show the current month.
20 |
21 | *calendar-:CalendarH*
22 | :CalendarH [[year] month] Show calendar at this year and this month in a
23 | horizontal split. When [year] is omitted, the
24 | calendar will show the given month in the current
25 | year. When both [year] and [month] are omitted, the
26 | calendar will show the current month.
27 |
28 | *calendar-:CalendarT*
29 | :CalendarT [[year] month] Show calendar at this year and this month in a
30 | full-screen window. When [year] is omitted, the
31 | calendar will show the given month in the current
32 | year. When both [year] and [month] are omitted, the
33 | calendar will show the current month.
34 |
35 | *calendar-:CalendarVR*
36 | :CalendarVR [[year] month] Show calendar at this year and this month in a
37 | vertical split at the right site. When [year] is
38 | omitted, the calendar will show the given month in
39 | the current year. When both [year] and [month] are
40 | omitted, the calendar will show the current month.
41 |
42 | *calendar-:CalendarSearch*
43 | :CalendarSearch [keyword] Search something in current calendar diary book.
44 |
45 |
46 | MAPPINGS *calendar-mappings*
47 |
48 | calendar.vim makes the following normal mode mappings available:
49 |
50 | *calendar-cal*
51 | cal Brings up the calendar in a vertical split.
52 | Equivalent to calling |:Calendar|.
53 |
54 | *calendar-caL*
55 | caL Brings up the calendar in a horizontal split.
56 | Equivalent to calling |:CalendarH|.
57 |
58 | SETTINGS *calendar-settings*
59 |
60 | calendar.vim can be configured using the following settings:
61 |
62 | *g:calendar_no_mappings*
63 | Disable standard mappings:
64 | let g:calendar_no_mappings=0
65 |
66 | *g:calendar_focus_today*
67 | Keeps focus when moving to next or previous calendar: >
68 | let g:calendar_focus_today = 1
69 | <
70 |
71 | *g:calendar_keys*
72 | To change the key bindings in the calendar window, add entries to this
73 | dictionary. Possible keys, the action bound to the keycode given in the
74 | respective value for this key and the default binding are listed below.
75 | 'close' Closes calendar window. 'q'
76 | 'do_action' Executes |calendar_action|. ''
77 | 'goto_today' Executes |calendar_today|. 't'
78 | 'show_help' Displays a short help message. '?'
79 | 'redisplay' Redraws calendar window. 'r'
80 | 'goto_next_month' Jumps to the next month. ''
81 | 'goto_prev_month' Jumps to the previous month. ''
82 | 'goto_next_year' Jumps to the next year. ''
83 | 'goto_prev_year' Jumps to the previous year. ''
84 | An example in your .vimrc might look like this: >
85 | let g:calendar_keys = { 'goto_next_month': '', 'goto_prev_month': ''}
86 | <
87 |
88 | *g:calendar_mark*
89 | Place a '*' or '+' mark after the day. Acceptable values are 'left',
90 | 'left-fit', and 'right': >
91 | let g:calendar_mark = 'right'
92 | <
93 |
94 | *g:calendar_diary*
95 | Specify the directory for the diary files. The default value is $HOME/diary. >
96 | let g:calendar_diary=$HOME.'/.vim/diary'
97 | <
98 |
99 | *g:calendar_diary_list*
100 | Specify multiple diary configurations. >
101 | let g:calendar_diary_list = [
102 | \ {'name': 'Note', 'path': $HOME.'/note', 'ext': '.md'},
103 | \ {'name': 'Diary', 'path': $HOME.'/diary', 'ext': '.diary.md'},
104 | \ ]
105 | <
106 |
107 | *g:calendar_diary_list_curr_idx*
108 | Specify multiple diary default configuration. The default value is 0. >
109 | let g:calendar_diary_list_curr_idx = 1
110 | <
111 |
112 |
113 | *g:calendar_navi*
114 | To control the calendar navigator, set this variable. Acceptable values are
115 | 'top', 'bottom', or 'both'. >
116 | let g:calendar_navi = ''
117 | <
118 |
119 | *g:calendar_navi_label*
120 | To set the labels for the calendar navigator, for example to change the
121 | language, use this variable. Entries should be comma separated. >
122 | let g:calendar_navi_label = 'Prev,Today,Next'
123 | <
124 |
125 | *g:calendar_erafmt*
126 | To change the dating system, set the following variable. Include the name of
127 | the dating system and its offset from the Georgian calendar (A.D.). For
128 | example, to use the current Japanese era (Heisei), you would set: >
129 | let g:calendar_erafmt = 'Heisei,-1988'
130 | <
131 |
132 | *g:calendar_mruler*
133 | To change the month names for the calendar headings, set this variable. The
134 | value is expected to be a comma-separated list of twelve values, starting with
135 | January: >
136 | let g:calendar_mruler = 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'
137 | <
138 |
139 | *g:calendar_wruler*
140 | To change the week names for the calendar headings, set this variable. The
141 | value is expected to be a space-separated list of seven values, starting with
142 | Sunday: >
143 | let g:calendar_wruler = 'Su Mo Tu We Th Fr Sa'
144 | <
145 |
146 | *g:calendar_monday*
147 | To make the week start on Monday rather than Sunday, set this variable. Note
148 | that the value of |g:calendar_wruler| is not affected by this; it should
149 | always begin with Sunday: >
150 | let g:calendar_monday = 1
151 | <
152 |
153 | *g:calendar_weeknm*
154 | To show the week number, set this variable. There are four valid settings: >
155 | let g:calendar_weeknm = 1 " WK01
156 | let g:calendar_weeknm = 2 " WK 1
157 | let g:calendar_weeknm = 3 " KW01
158 | let g:calendar_weeknm = 4 " KW 1
159 | let g:calendar_weeknm = 5 " 1
160 | <
161 |
162 | *g:calendar_datetime*
163 | To control display of the current date and time, set this variable.
164 | Acceptable values are 'title', 'statusline', and '': >
165 | let g:calendar_datetime = 'title'
166 | <
167 | *g:calendar_filetype*
168 | To control the filetype of calendar entries, set this variable. It defaults to
169 | 'markdown'. Acceptable values are values that are acceptable for |filetype|
170 | like e.g. 'markdown' or 'pandoc':
171 | let g:calendar_filetype = 'pandoc'
172 |
173 | *g:calendar_number_of_months*
174 | To control the number of months per view, set this variable. The default value
175 | is 3. >
176 | let g:calendar_number_of_months = 5
177 | <
178 |
179 | *g:calendar_search_grepprg*
180 | To set the command |:CalendarSearch| grepprg config. default value is 'grep',
181 | using system default grep program. If you want use Vim internal grep command
182 | |:vimgrep|, set value to 'internal'. >
183 | let g:calendar_search_grepprg = 'internal'
184 | <
185 |
186 | HOOKS *calendar-hooks*
187 |
188 | calendar.vim provides a number of hooks which allow you to run custom code on
189 | certain events. These are documented below.
190 |
191 | *calendar_action*
192 | The function declared in the calendar_action variable is run when the user
193 | presses enter on a date. Implement and set your function as follows: >
194 | function MyCalAction(day,month,year,week,dir)
195 | " day : day you actioned
196 | " month : month you actioned
197 | " year : year you actioned
198 | " week : day of week (Mo=1 ... Su=7)
199 | " dir : direction of calendar
200 | endfunction
201 | let calendar_action = 'MyCalAction'
202 | <
203 |
204 | *calendar_begin*
205 | The function declared in the calendar_begin variable is run just before the
206 | calendar is displayed. Implement and set your function as follows: >
207 | function MyCalActionBegin()
208 | endfunction
209 | let calendar_begin = 'MyCalActionBegin'
210 | <
211 |
212 | *calendar_end*
213 | The function declared in the calendar_end variable is run just after the
214 | calendar is displayed. Implement and set your function as follows: >
215 | function MyCalActionEnd()
216 | endfunction
217 | let calendar_end = 'MyCalActionEnd'
218 | <
219 |
220 | *calendar_sign*
221 | The function declared in the calendar_sign variable can be used to set a mark
222 | next to certain dates. Implement and set your function as follows: >
223 | function MyCalSign(day,month,year)
224 | " day : day you actioned
225 | " month : month you actioned
226 | " year : year you actioned
227 | if a:day == 1 && a:month == 1
228 | return 1 " happy new year
229 | else
230 | return 0 " or not
231 | endif
232 | endfunction
233 | let calendar_sign = 'MyCalSign'
234 | <
235 |
236 | *calendar_today*
237 | The function declared in the calendar_today variable is run when the user
238 | presses 'today'. Implement and set your function as follows: >
239 | function MyCalToday()
240 | endfunction
241 | let calendar_today = 'MyCalToday'
242 | <
243 |
244 | ABOUT *calendar-about*
245 |
246 | calendar.vim is available on GitHub:
247 |
248 | http://github.com/mattn/calendar-vim
249 |
250 | and also on VimScripts:
251 |
252 | http://www.vim.org/scripts/script.php?script_id=52
253 |
254 | vim:tw=78:et:ft=help:norl:
255 |
--------------------------------------------------------------------------------
/plugin/calendar.vim:
--------------------------------------------------------------------------------
1 | "=============================================================================
2 | " What Is This: Calendar
3 | " File: calendar.vim
4 | " Author: Yasuhiro Matsumoto
5 | " Last Change: 2013 Okt 27
6 | " Version: 2.9
7 | " Thanks:
8 | " Tobias Columbus : customizable key bindings
9 | " Daniel P. Wright : doc/calendar.txt
10 | " SethMilliken : gave a hint for 2.4
11 | " bw1 : bug fix, new weeknm format
12 | " Ingo Karkat : bug fix
13 | " Thinca : bug report, bug fix
14 | " Yu Pei : bug report
15 | " Per Winkvist : bug fix
16 | " Serge (gentoosiast) Koksharov : bug fix
17 | " Vitor Antunes : bug fix
18 | " Olivier Mengue : bug fix
19 | " Noel Henson : today action
20 | " Per Winkvist : bug report
21 | " Peter Findeisen : bug fix
22 | " Chip Campbell : gave a hint for 1.3z
23 | " PAN Shizhu : gave a hint for 1.3y
24 | " Eric Wald : bug fix
25 | " Sascha Wuestemann : advise
26 | " Linas Vasiliauskas : bug report
27 | " Per Winkvist : bug report
28 | " Ronald Hoelwarth : gave a hint for 1.3s
29 | " Vikas Agnihotri : bug report
30 | " Steve Hall : gave a hint for 1.3q
31 | " James Devenish : bug fix
32 | " Carl Mueller : gave a hint for 1.3o
33 | " Klaus Fabritius : bug fix
34 | " Stucki : gave a hint for 1.3m
35 | " Rosta : bug report
36 | " Richard Bair : bug report
37 | " Yin Hao Liew : bug report
38 | " Bill McCarthy : bug fix and gave a hint
39 | " Srinath Avadhanula : bug fix
40 | " Ronald Hoellwarth : few advices
41 | " Juan Orlandini : added higlighting of days with data
42 | " Ray : bug fix
43 | " Ralf.Schandl : gave a hint for 1.3
44 | " Bhaskar Karambelkar : bug fix
45 | " Suresh Govindachar : gave a hint for 1.2, bug fix
46 | " Michael Geddes : bug fix
47 | " Leif Wickland : bug fix
48 | " ChangeLog:
49 | " 2.8 : bug fix
50 | " 2.7 : vim7ish, customizable key bindings
51 | " 2.6 : new week number format
52 | " 2.5 : bug fix, 7.2 don't have relativenumber.
53 | " 2.4 : added g:calendar_options.
54 | " 2.3 : week number like ISO8601
55 | " g:calendar_monday and g:calendar_weeknm work together
56 | " 2.2 : http://gist.github.com/355513#file_customizable_keymap.diff
57 | " http://gist.github.com/355513#file_winfixwidth.diff
58 | " 2.1 : bug fix, set filetype 'calendar'.
59 | " 2.0 : bug fix, many bug fix and enhancements.
60 | " 1.9 : bug fix, use nnoremap.
61 | " 1.8 : bug fix, E382 when close diary.
62 | " 1.7 : bug fix, week number was broken on 2008.
63 | " 1.6 : added calendar_begin action.
64 | " added calendar_end action.
65 | " 1.5 : bug fix, fixed ruler formating with strpart.
66 | " bug fix, using winfixheight.
67 | " 1.4a : bug fix, week number was broken on 2005.
68 | " added calendar_today action.
69 | " bug fix, about wrapscan.
70 | " bug fix, about today mark.
71 | " bug fix, about today navigation.
72 | " 1.4 : bug fix, and one improvement.
73 | " bug 1:
74 | " when marking the current date, there is not distinguished e.g. between
75 | " 20041103 and 20040113, both dates are marked as today
76 | " bug 2:
77 | " the navigation mark "today" doesn't work
78 | " improvement:
79 | " the mapping t worked only when today was displayed, now it works always
80 | " and redisplays the cuurent month and today
81 | " 1.3z : few changes
82 | " asign , for navigation.
83 | " set ws for search navigation.
84 | " add tag for GetLatestVimScripts(AutoInstall)
85 | " 1.3y : bug fix, few changes
86 | " changed color syntax name. (ex. CalNavi, see bottom of this)
87 | " changed a map CalendarV for cal
88 | " changed a map CalendarH for caL
89 | " (competitive map for cvscommand.vim)
90 | " the date on the right-hand side didn't work correctoly.
91 | " make a map to rebuild Calendar window(r).
92 | " 1.3x : bug fix
93 | " viweek can't refer when not set calendar_weeknm.
94 | " 1.3w : bug fix
95 | " on leap year, week number decreases.
96 | " 1.3v : bug fix
97 | " add nowrapscan
98 | " use s:bufautocommandsset for making title
99 | " don't focus to navi when doubleclick bottom next>.
100 | " 1.3u : bug fix
101 | " when enter diary first time,
102 | " it don't warn that you don't have diary directory.
103 | " 1.3t : bug fix
104 | " make sure the variables for help
105 | " 1.3s : bug fix
106 | " make a map CalendarV for ca
107 | " add option calendar_navi_label
108 | " see Additional:
109 | " add option calendar_focus_today
110 | " see Additional:
111 | " add map ? for help
112 | " 1.3r : bug fix
113 | " if clicked navigator, cursor go to strange position.
114 | " 1.3q : bug fix
115 | " coundn't set calendar_navi
116 | " in its horizontal direction
117 | " 1.3p : bug fix
118 | " coundn't edit diary when the calendar is
119 | " in its horizontal direction
120 | " 1.3o : add option calendar_mark, and delete calendar_rmark
121 | " see Additional:
122 | " add option calendar_navi
123 | " see Additional:
124 | " 1.3n : bug fix
125 | " s:CalendarSign() should use filereadable(expand(sfile)).
126 | " 1.3m : tuning
127 | " using topleft or botright for opening Calendar.
128 | " use filereadable for s:CalendarSign().
129 | " 1.3l : bug fix
130 | " if set calendar_monday, it can see that Sep 1st is Sat
131 | " as well as Aug 31st.
132 | " 1.3k : bug fix
133 | " it didn't escape the file name on calendar.
134 | " 1.3j : support for fixed Gregorian
135 | " added the part of Sep 1752.
136 | " 1.3i : bug fix
137 | " Calculation mistake for week number.
138 | " 1.3h : add option for position of displaying '*' or '+'.
139 | " see Additional:
140 | " 1.3g : centering header
141 | " add option for show name of era.
142 | " see Additional:
143 | " bug fix
144 | " ca didn't show current month.
145 | " 1.3f : bug fix
146 | " there was yet another bug of today's sign.
147 | " 1.3e : added usage for
148 | " support handler for sign.
149 | " see Additional:
150 | " 1.3d : added higlighting of days that have calendar data associated
151 | " with it.
152 | " bug fix for calculates date.
153 | " 1.3c : bug fix for MakeDir()
154 | " if CalendarMakeDir(sfile) != 0
155 | " v
156 | " if s:CalendarMakeDir(sfile) != 0
157 | " 1.3b : bug fix for calendar_monday.
158 | " it didn't work g:calendar_monday correctly.
159 | " add g:calendar_version.
160 | " add argument on action handler.
161 | " see Additional:
162 | " 1.3a : bug fix for MakeDir().
163 | " it was not able to make directory.
164 | " 1.3 : support handler for action.
165 | " see Additional:
166 | " 1.2g : bug fix for today's sign.
167 | " it could not display today's sign correctly.
168 | " 1.2f : bug fix for current Date.
169 | " vtoday variable calculates date as 'YYYYMMDD'
170 | " while the loop calculates date as 'YYYYMMD' i.e just 1 digit
171 | " for date if < 10 so if current date is < 10 , the if condiction
172 | " to check for current date fails and current date is not
173 | " highlighted.
174 | " simple solution changed vtoday calculation line divide the
175 | " current-date by 1 so as to get 1 digit date.
176 | " 1.2e : change the way for setting title.
177 | " auto configuration for g:calendar_wruler with g:calendar_monday
178 | " 1.2d : add option for show week number.
179 | " let g:calendar_weeknm = 1
180 | " add separator if horizontal.
181 | " change all option's name
182 | " g:calendar_mnth -> g:calendar_mruler
183 | " g:calendar_week -> g:calendar_wruler
184 | " g:calendar_smnd -> g:calendar_monday
185 | " 1.2c : add option for that the week starts with monday.
186 | " let g:calendar_smnd = 1
187 | " 1.2b : bug fix for modifiable.
188 | " setlocal nomodifiable (was set)
189 | " 1.2a : add default options.
190 | " nonumber,foldcolumn=0,nowrap... as making gap
191 | " 1.2 : support wide display.
192 | " add a command CalendarH
193 | " add map
194 | " 1.1c : extra.
195 | " add a titlestring for today.
196 | " 1.1b : bug fix by Michael Geddes.
197 | " it happend when do ':Calender' twice
198 | " 1.1a : fix misspell.
199 | " Calender -> Calendar
200 | " 1.1 : bug fix.
201 | " it"s about strftime("%m")
202 | " 1.0a : bug fix by Leif Wickland.
203 | " it"s about strftime("%w")
204 | " 1.0 : first release.
205 | " TODO:
206 | " add the option for diary which is separate or single file.
207 | " GetLatestVimScripts: 52 1 :AutoInstall: calendar.vim
208 |
209 | if &compatible
210 | finish
211 | endif
212 | "*****************************************************************
213 | "* Calendar commands
214 | "*****************************************************************
215 | command! -nargs=* Calendar call calendar#show(0,)
216 | command! -nargs=* CalendarVR call calendar#show(3,)
217 | command! -nargs=* CalendarH call calendar#show(1,)
218 | command! -nargs=* CalendarT call calendar#show(2,)
219 |
220 | command! -nargs=* CalendarSearch call calendar#search("")
221 |
222 | if !get(g:, 'calendar_no_mappings', 0)
223 | if !hasmapto('CalendarV')
224 | nmap cal CalendarV
225 | endif
226 | if !hasmapto('CalendarH')
227 | nmap caL CalendarH
228 | endif
229 | endif
230 | nnoremap CalendarV :cal calendar#show(0)
231 | nnoremap CalendarH :cal calendar#show(1)
232 | nnoremap CalendarT :cal calendar#show(2)
233 |
234 | " vi: et sw=2 ts=2
235 |
--------------------------------------------------------------------------------