diff -ur --binary howm_vim/plugin/howm-date.vim howm_vim_new/plugin/howm-date.vim --- howm_vim/plugin/howm-date.vim 2006-06-04 21:26:21.000000000 +0900 +++ howm_vim_new/plugin/howm-date.vim 2008-03-20 14:11:15.423758000 +0900 @@ -1,11 +1,175 @@ " " howm-date.vim - howm-mode.vim 用の日付処理ライブラリ " -" Last Change: 04-Jun-2006. +" Last Change: 20-Mar-2008. " Written By: Kouichi NANASHIMA scriptencoding euc-jp +if !exists('*strftime') || + \ strftime('%Y-%m-%d %H:%M:%S') !~# '^\d\{4}-\d\d-\d\d \d\d:\d\d:\d\d$' + finish +endif + +" 注意: HowmDate2Int() とは基準日時も返り値の種類も違う +" +" format にしたがって書かれた日付 date を解釈し ( TimeZone を考慮する ), +" 1970-01-01 00:00:00 からの経過秒数を返す. +" 1970-01-01 00:00:00 以前や, +" 2038-01-01 00:00:00 以降のデータの場合は -1 を返す. +" その他, 解釈できなかった場合も -1 を返す. +" 既定値: 年:1970, 月:1, 日:1, 時:0, 分:0, 秒:0, TimeZone:+09:00 +function! HowmDateTime2Int(datetime, format) + " TimeZone の設定 + if !exists('g:howm_timezone_hour') || + \ g:howm_timezone_hour < -12 || 13 < g:howm_timezone_hour + let tz_hour = 9 + endif + if !exists('g:howm_timezone_min') || + \ g:howm_timezone_min < 0 || 59 < g:howm_timezone_min + let tz_min = 0 + endif + + let format = '\V' . escape(a:format, '\') + let format = substitute(format, '\C%F', escape('%Y-%m-%d', '\~&'), 'g') + let format = substitute(format, '\C%T', escape('%H:%M:%S', '\~&'), 'g') + let format = substitute(format, '\C%R', escape('%H:%M', '\~&'), 'g') + + let pat = format + let pat = substitute(pat, '\C%Y', escape('\m\d\{4}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%m', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%d', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%H', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%M', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%S', escape('\m\d\{2}\V', '\~&'), 'g') + if a:datetime !~ pat | return -1 | endif + let date_pat = pat + + " %Y + if format !~# '%Y' + let year = 1970 + else + let pat = format + let pat = substitute(pat, '\C%Y', escape('\m\(\d\{4}\)\V', '\~&'), 'g') + let pat = substitute(pat, '\C%m', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%d', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%H', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%M', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%S', escape('\m\d\{2}\V', '\~&'), 'g') + let year = substitute(a:datetime, pat, '\1', 'g') + 0 + if year < 1970 || 2038 <= year | return -1 | endif + endif + " ec 'year: ' . year + + " %m + if format !~# '%m' + let month = 1 + else + let pat = format + let pat = substitute(pat, '\C%Y', escape('\m\d\{4}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%m', escape('\m\(\d\{2}\)\V', '\~&'), 'g') + let pat = substitute(pat, '\C%d', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%H', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%M', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%S', escape('\m\d\{2}\V', '\~&'), 'g') + let month = substitute(a:datetime, pat, '\1', 'g') + 0 + if month < 1 || 12 < month | return -1 | endif + endif + " ec 'month: ' . month + + " %d + if format !~# '%d' + let day = 1 + else + let pat = format + let pat = substitute(pat, '\C%Y', escape('\m\d\{4}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%m', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%d', escape('\m\(\d\{2}\)\V', '\~&'), 'g') + let pat = substitute(pat, '\C%H', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%M', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%S', escape('\m\d\{2}\V', '\~&'), 'g') + let day = substitute(a:datetime, pat, '\1', 'g') + 0 + if day < 1 || 31 < day | return -1 | endif + if 28 < day + if month =~ '^\%(\<2\|4\|6\|9\|11\)$' && 30 < day | return -1 | endif + if month == '2' + if (year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)) + if 29 < day | return -1 | endif + else + if 28 < day | return -1 | endif + endif + endif + endif + endif + " ec 'day: ' . day + + " %H + if format !~# '%H' + let hour = 0 + else + let pat = format + let pat = substitute(pat, '\C%Y', escape('\m\d\{4}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%m', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%d', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%H', escape('\m\(\d\{2}\)\V', '\~&'), 'g') + let pat = substitute(pat, '\C%M', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%S', escape('\m\d\{2}\V', '\~&'), 'g') + let hour = substitute(a:datetime, pat, '\1', 'g') + 0 + if hour < 0 || 23 < hour | return -1 | endif + endif + " ec 'hour: ' . hour + + " %M + if format !~# '%M' + let min = 0 + else + let pat = format + let pat = substitute(pat, '\C%Y', escape('\m\d\{4}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%m', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%d', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%H', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%M', escape('\m\(\d\{2}\)\V', '\~&'), 'g') + let pat = substitute(pat, '\C%S', escape('\m\d\{2}\V', '\~&'), 'g') + let min = substitute(a:datetime, pat, '\1', 'g') + 0 + if min < 0 || 59 < min | return -1 | endif + endif + " ec 'min: ' . min + + " %S + if format !~# '%S' + let sec = 0 + else + let pat = format + let pat = substitute(pat, '\C%Y', escape('\m\d\{4}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%m', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%d', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%H', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%M', escape('\m\d\{2}\V', '\~&'), 'g') + let pat = substitute(pat, '\C%S', escape('\m\(\d\{2}\)\V', '\~&'), 'g') + let sec = substitute(a:datetime, pat, '\1', 'g') + 0 + if sec < 0 || 59 < sec | return -1 | endif + endif + " ec 'sec: ' . sec + + " 719527 : HowmDate2Int('1970-01-01', '%Y-%m-%d') + " 86400 : 60 * 60 * 24 + let retval = (s:ymd2int(year, month, day) - s:ymd2int(1970, 1, 1)) * 86400 + if format =~# '%H' || format =~# '%M' || format =~# '%S' + " TimeZone を考慮 + let retval = retval + hour * 60 * 60 - (tz_hour * 60 * 60) + if tz_hour > 0 + let retval = retval + min * 60 + (tz_min * 60) + else + let retval = retval + min * 60 - (tz_min * 60) + endif + end + let retval = retval + sec + if retval < 0 | return -1 | endif + " echo strftime('%Y-%m-%d %H:%M:%S', retval) + + return retval +endfunction + " dateFormat のフォーマットで書かれた日付 date を解釈し, " 西暦 0 年 1 月 1 日からの経過日数を返す. function! HowmDate2Int(date, dateFormat) @@ -74,132 +238,203 @@ " 単体テスト用関数 {{{ if exists('g:howm_debug') && g:howm_debug -function! TestHowmDate() - call TestHowmDate2Int() - call Test_date2ymd() - call Test_ymd2int() -endfunction - -" HowmDate2Int() テスト {{{ -function! TestHowmDate2Int() - " 正常処理テスト - call VUAssertEquals(30, HowmDate2Int('0000-01-31', '%Y-%m-%d'), '%Y-%m-%dパターンのテスト') - call VUAssertEquals(30, HowmDate2Int('0000-31-01', '%Y-%d-%m'), '%Y-%d-%mパターンのテスト') - call VUAssertEquals(30, HowmDate2Int('01-0000-31', '%m-%Y-%d'), '%m-%Y-%dパターンのテスト') - call VUAssertEquals(30, HowmDate2Int('01-31-0000', '%m-%d-%Y'), '%m-%d-%Yパターンのテスト') - call VUAssertEquals(30, HowmDate2Int('31-0000-01', '%d-%Y-%m'), '%d-%Y-%mパターンのテスト') - call VUAssertEquals(30, HowmDate2Int('31-01-0000', '%d-%m-%Y'), '%d-%m-%Yパターンのテスト') - - call VUAssertEquals(30, HowmDate2Int('[0000-01-31]@', '[%Y-%m-%d]@'), '[%Y-%m-%d]@パターンのテスト') - call VUAssertEquals(30, HowmDate2Int('[0000-31-01]@', '[%Y-%d-%m]@'), '[%Y-%d-%m]@パターンのテスト') - call VUAssertEquals(30, HowmDate2Int('[01-0000-31]@', '[%m-%Y-%d]@'), '[%m-%Y-%d]@パターンのテスト') - call VUAssertEquals(30, HowmDate2Int('[01-31-0000]@', '[%m-%d-%Y]@'), '[%m-%d-%Y]@パターンのテスト') - call VUAssertEquals(30, HowmDate2Int('[31-0000-01]@', '[%d-%Y-%m]@'), '[%d-%Y-%m]@パターンのテスト') - call VUAssertEquals(30, HowmDate2Int('[31-01-0000]@', '[%d-%m-%Y]@'), '[%d-%m-%Y]@パターンのテスト') - - call VUAssertEquals(30, HowmDate2Int('[0000-01-31]@ a', '[%Y-%m-%d]@'), '後ろに余分な文字のあるパターンのテスト') - call VUAssertEquals(30, HowmDate2Int('a[0000-01-31]@', '[%Y-%m-%d]@'), '前に余分な文字のあるパターンのテスト') - " 異常処理テスト - call VUAssertEquals(-1, HowmDate2Int('2004-06-26', '%m-%Y-%d'), 'パターンと違う順番で日付が出現する場合のテスト') - call VUAssertEquals(-1, HowmDate2Int('aaaa-bb-cc', '%Y-%m-%d'), '内容が日付でない場合のテスト') -endfunction -" HowmDate2Int() テスト }}} -" s:date2ymd() テスト {{{ -function! Test_date2ymd() - " 正常処理テスト - call VUAssertEquals(1, s:date2ymd('2004-06-26', '%Y-%m-%d', 's:date'), '%Y-%m-%dパターンのテスト') - call VUAssertEquals(2004, s:date_year) - call VUAssertEquals(6, s:date_month) - call VUAssertEquals(26, s:date_day) - call VUAssertEquals(1, s:date2ymd('2004-26-06', '%Y-%d-%m', 's:date'), '%Y-%d-%mパターンのテスト') - call VUAssertEquals(2004, s:date_year) - call VUAssertEquals(6, s:date_month) - call VUAssertEquals(26, s:date_day) - call VUAssertEquals(1, s:date2ymd('06-2004-26', '%m-%Y-%d', 's:date'), '%m-%Y-%dパターンのテスト') - call VUAssertEquals(2004, s:date_year) - call VUAssertEquals(6, s:date_month) - call VUAssertEquals(26, s:date_day) - call VUAssertEquals(1, s:date2ymd('06-26-2004', '%m-%d-%Y', 's:date'), '%m-%d-%Yパターンのテスト') - call VUAssertEquals(2004, s:date_year) - call VUAssertEquals(6, s:date_month) - call VUAssertEquals(26, s:date_day) - call VUAssertEquals(1, s:date2ymd('26-2004-06', '%d-%Y-%m', 's:date'), '%d-%Y-%mパターンのテスト') - call VUAssertEquals(2004, s:date_year) - call VUAssertEquals(6, s:date_month) - call VUAssertEquals(26, s:date_day) - call VUAssertEquals(1, s:date2ymd('26-06-2004', '%d-%m-%Y', 's:date'), '%d-%m-%Yパターンのテスト') - call VUAssertEquals(2004, s:date_year) - call VUAssertEquals(6, s:date_month) - call VUAssertEquals(26, s:date_day) - call VUAssertEquals(1, s:date2ymd('[2004-06-26]@', '[%Y-%m-%d]@', 's:date'), '[%Y-%m-%d]@パターンのテスト') - call VUAssertEquals(2004, s:date_year) - call VUAssertEquals(6, s:date_month) - call VUAssertEquals(26, s:date_day) - call VUAssertEquals(1, s:date2ymd('[06-2004-26]@', '[%m-%Y-%d]@', 's:date'), '[%Y-%d-%m]@パターンのテスト') - call VUAssertEquals(2004, s:date_year) - call VUAssertEquals(6, s:date_month) - call VUAssertEquals(26, s:date_day) - call VUAssertEquals(1, s:date2ymd('[06-26-2004]@', '[%m-%d-%Y]@', 's:date'), '[%m-%Y-%d]@パターンのテスト') - call VUAssertEquals(2004, s:date_year) - call VUAssertEquals(6, s:date_month) - call VUAssertEquals(26, s:date_day) - call VUAssertEquals(1, s:date2ymd('[26-06-2004]@', '[%d-%m-%Y]@', 's:date'), '[%m-%d-%Y]@パターンのテスト') - call VUAssertEquals(2004, s:date_year) - call VUAssertEquals(6, s:date_month) - call VUAssertEquals(26, s:date_day) - call VUAssertEquals(1, s:date2ymd('[26-2004-06]@', '[%d-%Y-%m]@', 's:date'), '[%d-%Y-%m]@パターンのテスト') - call VUAssertEquals(2004, s:date_year) - call VUAssertEquals(6, s:date_month) - call VUAssertEquals(26, s:date_day) - call VUAssertEquals(1, s:date2ymd('[2004-26-06]@', '[%Y-%d-%m]@', 's:date'), '[%d-%m-%Y]@パターンのテスト') - call VUAssertEquals(2004, s:date_year) - call VUAssertEquals(6, s:date_month) - call VUAssertEquals(26, s:date_day) - call VUAssertEquals(1, s:date2ymd('2004-06-26a', '%Y-%m-%d', 's:date'), '後ろに余分な文字のあるパターンのテスト') - call VUAssertEquals(2004, s:date_year) - call VUAssertEquals(6, s:date_month) - call VUAssertEquals(26, s:date_day) - call VUAssertEquals(1, s:date2ymd('a2004-06-26', '%Y-%m-%d', 's:date'), '前に余分な文字のあるパターンのテスト') - call VUAssertEquals(2004, s:date_year) - call VUAssertEquals(6, s:date_month) - call VUAssertEquals(26, s:date_day) - " 異常処理テスト - call VUAssertEquals(0, s:date2ymd('2004-06-26', '%m-%Y-%d', 's:date'), 'パターンと違う順番で日付が出現する場合のテスト') - call VUAssertEquals(0, s:date2ymd('aaaa-bb-cc', '%Y-%m-%d', 's:date'), '内容が日付でない場合のテスト') - " 後片付け - unlet s:date_year - unlet s:date_month - unlet s:date_day -endfunction -" s:date2ymd() テスト }}} -" s:ymd2int() テスト {{{ -function! Test_ymd2int() - " 基準日テスト - call VUAssertEquals(0, s:ymd2int(0, 1, 1), '基準日テスト') - " 月変わり処理テスト - call VUAssertEquals(1, s:ymd2int(1, 2, 1) - s:ymd2int(1, 1, 31), '月変わり処理テスト') - call VUAssertEquals(1, s:ymd2int(1, 3, 1) - s:ymd2int(1, 2, 28), '月変わり処理テスト') - call VUAssertEquals(1, s:ymd2int(1, 4, 1) - s:ymd2int(1, 3, 31), '月変わり処理テスト') - call VUAssertEquals(1, s:ymd2int(1, 5, 1) - s:ymd2int(1, 4, 30), '月変わり処理テスト') - call VUAssertEquals(1, s:ymd2int(1, 6, 1) - s:ymd2int(1, 5, 31), '月変わり処理テスト') - call VUAssertEquals(1, s:ymd2int(1, 7, 1) - s:ymd2int(1, 6, 30), '月変わり処理テスト') - call VUAssertEquals(1, s:ymd2int(1, 8, 1) - s:ymd2int(1, 7, 31), '月変わり処理テスト') - call VUAssertEquals(1, s:ymd2int(1, 9, 1) - s:ymd2int(1, 8, 31), '月変わり処理テスト') - call VUAssertEquals(1, s:ymd2int(1,10, 1) - s:ymd2int(1, 9, 30), '月変わり処理テスト') - call VUAssertEquals(1, s:ymd2int(1,11, 1) - s:ymd2int(1,10, 31), '月変わり処理テスト') - call VUAssertEquals(1, s:ymd2int(1,12, 1) - s:ymd2int(1,11, 30), '月変わり処理テスト') - " 年変わり処理テスト - call VUAssertEquals(1, s:ymd2int(2, 1, 1) - s:ymd2int(1,12, 31), '年変わり処理テスト') - " 閏年処理テスト - call VUAssertEquals(1, s:ymd2int(4, 3, 1) - s:ymd2int(4, 2, 29), '閏年処理テスト') - call VUAssertEquals(1, s:ymd2int(8, 3, 1) - s:ymd2int(8, 2, 29), '閏年処理テスト') - call VUAssertEquals(1, s:ymd2int(100, 3, 1) - s:ymd2int(100, 2, 28), '閏年処理テスト') - call VUAssertEquals(1, s:ymd2int(200, 3, 1) - s:ymd2int(200, 2, 28), '閏年処理テスト') - call VUAssertEquals(1, s:ymd2int(400, 3, 1) - s:ymd2int(400, 2, 29), '閏年処理テスト') -endfunction -" s:ymd2int() テスト }}} + function! TestHowmDate() + call TestHowmDate2Int() + call Test_date2ymd() + call Test_ymd2int() + endfunction + + " HowmDateTime2Int() テスト {{{ + function! TestHowmDateTime() + " 年 + call VUAssertEquals(-1, HowmDateTime2Int('1969', '%Y'), '無効な年(下限1)') + call VUAssertEquals(0, HowmDateTime2Int('1970', '%Y'), '有効な年(下限2)') + call VUAssertEquals('1970', + \ strftime('%Y', HowmDateTime2Int('1970', '%Y')), '有効な年(下限3)') + call VUAssertEquals('2037', + \ strftime('%Y', HowmDateTime2Int('2037', '%Y')), '有効な年(上限1)') + call VUAssertEquals(-1, HowmDateTime2Int('2038', '%Y'), '無効な年(上限2)') + " 月 + call VUAssertEquals(-1, HowmDateTime2Int('00', '%m'), '無効な月(下限1)') + call VUAssertEquals('01', + \ strftime('%m', HowmDateTime2Int('01', '%m')), '有効な月(下限2)') + call VUAssertEquals('12', + \ strftime('%m', HowmDateTime2Int('12', '%m')), '有効な月(上限1)') + call VUAssertEquals(-1, HowmDateTime2Int('13', '%m'), '無効な月(上限2)') + " 日 + call VUAssertEquals(-1, HowmDateTime2Int('01-00', '%m-%d'), + \ '無効な日付(下限1)') + call VUAssertEquals('01-01', + \ strftime('%m-%d', HowmDateTime2Int('01-01', '%m-%d')), + \ '有効な日付(下限2)') + call VUAssertEquals('01-31', + \ strftime('%m-%d', HowmDateTime2Int('01-31', '%m-%d')), + \ '有効な日付(上限1)') + call VUAssertEquals(-1, HowmDateTime2Int('01-32', '%m-%d'), + \ '無効な日付(上限2)') + call VUAssertEquals('04-30', + \ strftime('%m-%d', HowmDateTime2Int('04-30', '%m-%d')), + \ '有効な日付(上限3)') + call VUAssertEquals(-1, HowmDateTime2Int('04-31', '%m-%d'), + \ '無効な日付(上限4)') + call VUAssertEquals('2008-02-29', + \ strftime('%Y-%m-%d', HowmDateTime2Int('2008-02-29', '%Y-%m-%d')), + \ '有効な日付(上限5)') + call VUAssertEquals(-1, HowmDateTime2Int('2007-02-29', '%Y-%m-%d'), + \ '無効な日付(上限6)') + " 日時 + call VUAssertEquals('2008-01-01 00:00:00', + \ strftime('%Y-%m-%d %H:%M:%S', + \ HowmDateTime2Int('2008-01-01 00:00:00', '%Y-%m-%d %H:%M:%S')), + \ '有効な日時') + " timezone の関係に無効になる + call VUAssertEquals(-1, + \ HowmDateTime2Int('1970-01-01 00:00:00', '%Y-%m-%d %H:%M:%S'), + \ '無効な日時') + call VUAssertEquals('1970-01-01 09:00:00', + \ strftime('%Y-%m-%d %H:%M:%S', + \ HowmDateTime2Int('1970-01-01 09:00:00', '%Y-%m-%d %H:%M:%S')), + \ '有効な日時') + " %F, %T, %R + call VUAssertEquals('2008-03-19', + \ strftime('%Y-%m-%d', HowmDateTime2Int('2008-03-19', '%F')), + \ '%Fのテスト') + call VUAssertEquals('2008-03-19 20:30:48', + \ strftime('%Y-%m-%d %H:%M:%S', + \ HowmDateTime2Int('2008-03-19 20:30:48', '%F %T')), + \ '%Tのテスト') + call VUAssertEquals('2008-03-19 20:30', + \ strftime('%Y-%m-%d %H:%M', + \ HowmDateTime2Int('2008-03-19 20:30', '%F %R')), + \ '%Rのテスト') + " 無駄な文字をいれてみる + call VUAssertEquals('2008-03-19 20:30:48', + \ strftime('%Y-%m-%d %H:%M:%S', + \ HowmDateTime2Int('[2008-03-19T20:30:48]', '[%FT%T]')), + \ '無駄な文字を含めてみる') + + endfunction + " HowmDateTime2Int() テスト }}} + " HowmDate2Int() テスト {{{ + function! TestHowmDate2Int() + " 正常処理テスト + call VUAssertEquals(30, HowmDate2Int('0000-01-31', '%Y-%m-%d'), '%Y-%m-%dパターンのテスト') + call VUAssertEquals(30, HowmDate2Int('0000-31-01', '%Y-%d-%m'), '%Y-%d-%mパターンのテスト') + call VUAssertEquals(30, HowmDate2Int('01-0000-31', '%m-%Y-%d'), '%m-%Y-%dパターンのテスト') + call VUAssertEquals(30, HowmDate2Int('01-31-0000', '%m-%d-%Y'), '%m-%d-%Yパターンのテスト') + call VUAssertEquals(30, HowmDate2Int('31-0000-01', '%d-%Y-%m'), '%d-%Y-%mパターンのテスト') + call VUAssertEquals(30, HowmDate2Int('31-01-0000', '%d-%m-%Y'), '%d-%m-%Yパターンのテスト') + + call VUAssertEquals(30, HowmDate2Int('[0000-01-31]@', '[%Y-%m-%d]@'), '[%Y-%m-%d]@パターンのテスト') + call VUAssertEquals(30, HowmDate2Int('[0000-31-01]@', '[%Y-%d-%m]@'), '[%Y-%d-%m]@パターンのテスト') + call VUAssertEquals(30, HowmDate2Int('[01-0000-31]@', '[%m-%Y-%d]@'), '[%m-%Y-%d]@パターンのテスト') + call VUAssertEquals(30, HowmDate2Int('[01-31-0000]@', '[%m-%d-%Y]@'), '[%m-%d-%Y]@パターンのテスト') + call VUAssertEquals(30, HowmDate2Int('[31-0000-01]@', '[%d-%Y-%m]@'), '[%d-%Y-%m]@パターンのテスト') + call VUAssertEquals(30, HowmDate2Int('[31-01-0000]@', '[%d-%m-%Y]@'), '[%d-%m-%Y]@パターンのテスト') + + call VUAssertEquals(30, HowmDate2Int('[0000-01-31]@ a', '[%Y-%m-%d]@'), '後ろに余分な文字のあるパターンのテスト') + call VUAssertEquals(30, HowmDate2Int('a[0000-01-31]@', '[%Y-%m-%d]@'), '前に余分な文字のあるパターンのテスト') + " 異常処理テスト + call VUAssertEquals(-1, HowmDate2Int('2004-06-26', '%m-%Y-%d'), 'パターンと違う順番で日付が出現する場合のテスト') + call VUAssertEquals(-1, HowmDate2Int('aaaa-bb-cc', '%Y-%m-%d'), '内容が日付でない場合のテスト') + endfunction + " HowmDate2Int() テスト }}} + " s:date2ymd() テスト {{{ + function! Test_date2ymd() + " 正常処理テスト + call VUAssertEquals(1, s:date2ymd('2004-06-26', '%Y-%m-%d', 's:date'), '%Y-%m-%dパターンのテスト') + call VUAssertEquals(2004, s:date_year) + call VUAssertEquals(6, s:date_month) + call VUAssertEquals(26, s:date_day) + call VUAssertEquals(1, s:date2ymd('2004-26-06', '%Y-%d-%m', 's:date'), '%Y-%d-%mパターンのテスト') + call VUAssertEquals(2004, s:date_year) + call VUAssertEquals(6, s:date_month) + call VUAssertEquals(26, s:date_day) + call VUAssertEquals(1, s:date2ymd('06-2004-26', '%m-%Y-%d', 's:date'), '%m-%Y-%dパターンのテスト') + call VUAssertEquals(2004, s:date_year) + call VUAssertEquals(6, s:date_month) + call VUAssertEquals(26, s:date_day) + call VUAssertEquals(1, s:date2ymd('06-26-2004', '%m-%d-%Y', 's:date'), '%m-%d-%Yパターンのテスト') + call VUAssertEquals(2004, s:date_year) + call VUAssertEquals(6, s:date_month) + call VUAssertEquals(26, s:date_day) + call VUAssertEquals(1, s:date2ymd('26-2004-06', '%d-%Y-%m', 's:date'), '%d-%Y-%mパターンのテスト') + call VUAssertEquals(2004, s:date_year) + call VUAssertEquals(6, s:date_month) + call VUAssertEquals(26, s:date_day) + call VUAssertEquals(1, s:date2ymd('26-06-2004', '%d-%m-%Y', 's:date'), '%d-%m-%Yパターンのテスト') + call VUAssertEquals(2004, s:date_year) + call VUAssertEquals(6, s:date_month) + call VUAssertEquals(26, s:date_day) + call VUAssertEquals(1, s:date2ymd('[2004-06-26]@', '[%Y-%m-%d]@', 's:date'), '[%Y-%m-%d]@パターンのテスト') + call VUAssertEquals(2004, s:date_year) + call VUAssertEquals(6, s:date_month) + call VUAssertEquals(26, s:date_day) + call VUAssertEquals(1, s:date2ymd('[06-2004-26]@', '[%m-%Y-%d]@', 's:date'), '[%Y-%d-%m]@パターンのテスト') + call VUAssertEquals(2004, s:date_year) + call VUAssertEquals(6, s:date_month) + call VUAssertEquals(26, s:date_day) + call VUAssertEquals(1, s:date2ymd('[06-26-2004]@', '[%m-%d-%Y]@', 's:date'), '[%m-%Y-%d]@パターンのテスト') + call VUAssertEquals(2004, s:date_year) + call VUAssertEquals(6, s:date_month) + call VUAssertEquals(26, s:date_day) + call VUAssertEquals(1, s:date2ymd('[26-06-2004]@', '[%d-%m-%Y]@', 's:date'), '[%m-%d-%Y]@パターンのテスト') + call VUAssertEquals(2004, s:date_year) + call VUAssertEquals(6, s:date_month) + call VUAssertEquals(26, s:date_day) + call VUAssertEquals(1, s:date2ymd('[26-2004-06]@', '[%d-%Y-%m]@', 's:date'), '[%d-%Y-%m]@パターンのテスト') + call VUAssertEquals(2004, s:date_year) + call VUAssertEquals(6, s:date_month) + call VUAssertEquals(26, s:date_day) + call VUAssertEquals(1, s:date2ymd('[2004-26-06]@', '[%Y-%d-%m]@', 's:date'), '[%d-%m-%Y]@パターンのテスト') + call VUAssertEquals(2004, s:date_year) + call VUAssertEquals(6, s:date_month) + call VUAssertEquals(26, s:date_day) + call VUAssertEquals(1, s:date2ymd('2004-06-26a', '%Y-%m-%d', 's:date'), '後ろに余分な文字のあるパターンのテスト') + call VUAssertEquals(2004, s:date_year) + call VUAssertEquals(6, s:date_month) + call VUAssertEquals(26, s:date_day) + call VUAssertEquals(1, s:date2ymd('a2004-06-26', '%Y-%m-%d', 's:date'), '前に余分な文字のあるパターンのテスト') + call VUAssertEquals(2004, s:date_year) + call VUAssertEquals(6, s:date_month) + call VUAssertEquals(26, s:date_day) + " 異常処理テスト + call VUAssertEquals(0, s:date2ymd('2004-06-26', '%m-%Y-%d', 's:date'), 'パターンと違う順番で日付が出現する場合のテスト') + call VUAssertEquals(0, s:date2ymd('aaaa-bb-cc', '%Y-%m-%d', 's:date'), '内容が日付でない場合のテスト') + " 後片付け + unlet s:date_year + unlet s:date_month + unlet s:date_day + endfunction + " s:date2ymd() テスト }}} + " s:ymd2int() テスト {{{ + function! Test_ymd2int() + " 基準日テスト + call VUAssertEquals(0, s:ymd2int(0, 1, 1), '基準日テスト') + " 月変わり処理テスト + call VUAssertEquals(1, s:ymd2int(1, 2, 1) - s:ymd2int(1, 1, 31), '月変わり処理テスト') + call VUAssertEquals(1, s:ymd2int(1, 3, 1) - s:ymd2int(1, 2, 28), '月変わり処理テスト') + call VUAssertEquals(1, s:ymd2int(1, 4, 1) - s:ymd2int(1, 3, 31), '月変わり処理テスト') + call VUAssertEquals(1, s:ymd2int(1, 5, 1) - s:ymd2int(1, 4, 30), '月変わり処理テスト') + call VUAssertEquals(1, s:ymd2int(1, 6, 1) - s:ymd2int(1, 5, 31), '月変わり処理テスト') + call VUAssertEquals(1, s:ymd2int(1, 7, 1) - s:ymd2int(1, 6, 30), '月変わり処理テスト') + call VUAssertEquals(1, s:ymd2int(1, 8, 1) - s:ymd2int(1, 7, 31), '月変わり処理テスト') + call VUAssertEquals(1, s:ymd2int(1, 9, 1) - s:ymd2int(1, 8, 31), '月変わり処理テスト') + call VUAssertEquals(1, s:ymd2int(1,10, 1) - s:ymd2int(1, 9, 30), '月変わり処理テスト') + call VUAssertEquals(1, s:ymd2int(1,11, 1) - s:ymd2int(1,10, 31), '月変わり処理テスト') + call VUAssertEquals(1, s:ymd2int(1,12, 1) - s:ymd2int(1,11, 30), '月変わり処理テスト') + " 年変わり処理テスト + call VUAssertEquals(1, s:ymd2int(2, 1, 1) - s:ymd2int(1,12, 31), '年変わり処理テスト') + " 閏年処理テスト + call VUAssertEquals(1, s:ymd2int(4, 3, 1) - s:ymd2int(4, 2, 29), '閏年処理テスト') + call VUAssertEquals(1, s:ymd2int(8, 3, 1) - s:ymd2int(8, 2, 29), '閏年処理テスト') + call VUAssertEquals(1, s:ymd2int(100, 3, 1) - s:ymd2int(100, 2, 28), '閏年処理テスト') + call VUAssertEquals(1, s:ymd2int(200, 3, 1) - s:ymd2int(200, 2, 28), '閏年処理テスト') + call VUAssertEquals(1, s:ymd2int(400, 3, 1) - s:ymd2int(400, 2, 29), '閏年処理テスト') + endfunction + " s:ymd2int() テスト }}} endif " 単体テスト用関数 }}} -" vim:set ts=2 sts=2 sw=2 tw=0 fdm=marker: +" vim:set et ts=2 sts=2 sw=2 tw=0 fdm=marker: diff -ur --binary howm_vim/plugin/howm-mode.vim howm_vim_new/plugin/howm-mode.vim --- howm_vim/plugin/howm-mode.vim 2006-06-04 21:26:21.000000000 +0900 +++ howm_vim_new/plugin/howm-mode.vim 2008-04-16 21:30:17.392062000 +0900 @@ -3,442 +3,1231 @@ " - howm(Hitoride Otegaru Wiki Modoki) " http://howm.sourceforge.jp/index-j.html " -" Last Change: 04-Jun-2006. +" Last Change: 16-Apr-2008. " Written By: Kouichi NANASHIMA +" +" 使用条件 +" - Vim6 以降 +" - strftime() が使える +" - strftime() の format に %Y, %m, %d, %H, %M, %S が使える scriptencoding euc-jp -" variables {{{ -if !exists('g:howm_dir') - let g:howm_dir = "~/howm/" -endif -if !exists('g:howm_filename') - let g:howm_filename = "%Y/%m/%d/%Y-%m-%d-%H%M%S.howm" -endif -if !exists('g:howm_fileencoding') - " let g:howm_fileencoding = "euc-jp" - let g:howm_fileencoding = &enc -endif -if !exists('g:howm_fileformat') - " let g:howm_fileformat = "unix" - let g:howm_fileformat = &ff -endif -if !exists('g:howm_keywordfile') - let g:howm_keywordfile = '~/.howm-keys' -endif -if !exists('g:howm_mapleader') - let g:howm_mapleader = ',' -endif -if !exists('g:howm_instantpreview') - let g:howm_instantpreview = 0 -endif -if !exists('g:howm_hidefile_regexp') - let g:howm_hidefile_regexp = '\(^\|/\)\.\|[~#]$\|\.bak$\|/CVS/' -endif -if !exists('g:howm_reminder_old_format') - let g:howm_reminder_old_format = 0 -endif -if !exists('g:howm_removeEmpty') - let g:howm_removeEmpty = 0 -endif -if !exists('g:howm_debug') - let g:howm_debug = 0 +if v:version < 600 || + \ (!exists('*strftime') || + \ strftime('%Y-%m-%d %H:%M:%S') !~# '^\d\{4}-\d\d-\d\d \d\d:\d\d:\d\d$') + finish endif -" variables-pattern {{{ -" 日付のパターン -" 予定や ToDo などに使用. -if !exists('g:howm_date_pattern') - let g:howm_date_pattern='%Y-%m-%d' -endif -" TODO:match() とか使って自動化 -if !exists('g:howm_date_yearpos') - let g:howm_date_yearpos=1 -endif -if !exists('g:howm_date_monthpos') - let g:howm_date_monthpos=2 -endif -if !exists('g:howm_date_daypos') - let g:howm_date_daypos=3 -endif -" メモタイトルのパターン -if !exists('g:howm_title_pattern') - let g:howm_title_pattern='=' -endif -" goto リンクのパターン -if !exists('g:howm_glink_pattern') - let g:howm_glink_pattern='>>>' -endif -if !exists('g:howm_clink_pattern') - let g:howm_clink_pattern='<<<' -endif -" Preview ヘッダのパターン -if !exists('g:howm_previewheader_pattern') - let g:howm_previewheader_pattern = "\==========================>>> %file%\" -endif -" variables-pattern }}} -" variables-grep {{{ -if !exists('g:howm_grepprg') - if has('win32') - let g:howm_grepprg = '' - else - let g:howm_grepprg = 'grep' +if !exists('s:did_load') + let s:enable_vimgrep = 0 + if (v:version >= 700) && has('quickfix') && (exists(':vimgrep') == 2) + let s:enable_vimgrep = 1 + endif + let s:enable_migemo = 0 + if s:enable_vimgrep && has('migemo') && exists('*migemo') + let s:enable_migemo = 1 endif -endif -" Grep 実行用コマンド群 -" #prg# は g:howm_grepprg で指定したプログラムに置換される -" #searchWord# は検索語に置換される -" #searchWordFile# は検索語を保存した作業用ファイル名に置換される -" (コマンドラインでうまくマルチバイト文字が扱えないときに有効) -" #searchPath# は検索対象パスに置換される -" CYGWIN GNU Grep 用設定 -if !exists('g:howm_grepcmd_regexp') - let g:howm_grepcmd_regexp = '#prg# -HInrE -f #searchWordFile# #searchPath#' -endif -if !exists('g:howm_grepcmd_regexp_ignore') - let g:howm_grepcmd_regexp_ignore = '#prg# -HInrEi -f #searchWordFile# #searchPath#' -endif -if !exists('g:howm_grepcmd_fix') - let g:howm_grepcmd_fix = '#prg# -HInrF -f #searchWordFile# #searchPath#' -endif -if !exists('g:howm_grepcmd_fix_ignore') - let g:howm_grepcmd_fix_ignore = '#prg# -HInrFi -f #searchWordFile# #searchPath#' -endif -" variables-grep }}} -" variables-find {{{ -" old variables -if !exists('g:howm_findprg') - " let g:howm_findprg = 'find' - if has('win32') - let g:howm_findprg = '' - else - let g:howm_findprg = 'find' + " variables {{{ + if !exists('g:howm_dir') + let g:howm_dir = "~/howm/" + endif + if !exists('g:howm_filename') + let g:howm_filename = "%Y/%m/%d/%Y-%m-%d-%H%M%S.howm" + endif + if !exists('g:howm_fileencoding') + " let g:howm_fileencoding = "euc-jp" + let g:howm_fileencoding = &enc + endif + if !exists('g:howm_fileformat') + " let g:howm_fileformat = "unix" + let g:howm_fileformat = &ff + endif + if !exists('g:howm_keywordfile') + let g:howm_keywordfile = '~/.howm-keys' + endif + if !exists('g:howm_schedulefile') + let g:howm_schedulefile = '~/.howm-schedules' + endif + if !exists('g:howm_mapleader') + let g:howm_mapleader = ',' + endif + if !exists('g:howm_hidefile_regexp') + let g:howm_hidefile_regexp = '\(^\|/\)\.\|[~#]$\|\.bak$\|/CVS/' + endif + if !exists('g:howm_removeEmpty') + let g:howm_removeEmpty = 0 + endif + if !exists('g:howm_debug') + let g:howm_debug = 0 + endif + if !exists('g:howm_lineFormat') + let g:howm_lineFormat = "%filename% | %content%" + endif + if !exists('g:howm_lineFormatShowDirectory') + let g:howm_lineFormatShowDirectory = "%filename% | %content%" + endif + if v:version >= 700 && !exists('g:howm_actionlock_list') + let g:howm_actionlock_list = [] + endif + if v:version >= 700 && !exists('g:howm_searchinfo_format') + let fmt = '' + let fmt = fmt . 'type: %TYPE%' . "\n" + let fmt = fmt . 'migemo: %MIGEMO%' . "\n" + let fmt = fmt . 'qtype: %QTYPE%' . "\n" + let fmt = fmt . 'case: %CASE%' . "\n" + let fmt = fmt . 'sort: %SORT%(%ORDER%)' . "\n" + let fmt = fmt . 'time: %time% [sec]' . "\n" + let fmt = fmt . 'query: %query%' . "\n" + let fmt = fmt . 'rquery: %rquery%' . "\n" + let g:howm_searchinfo_format = fmt + unlet fmt + endif + if s:enable_vimgrep && !exists('g:howm_vimgrep_usehide') + let g:howm_vimgrep_usehide = 1 + endif + if !exists('g:howm_ignore_done') + let g:howm_ignore_done = 0 + endif + if !exists('g:howm_auto_show_preview') + let g:howm_auto_show_preview = 0 + endif + if !exists('g:howm_auto_hide_preview') + let g:howm_auto_hide_preview = 0 + endif + if !exists('g:howm_append_editing') + let g:howm_append_editing = 1 + endif + if !exists('g:howm_wildignore') + let g:howm_wildignore = '' endif -endif -let g:howm_findcmd = '#prg# #searchPath# -type f -print' -" variables-find }}} -" variables-migemo {{{ -if !exists('g:howm_migemoprg') - let g:howm_migemoprg = 'migemo' -endif -if !exists('g:howm_migemoopt') - " ruby migemo - let g:howm_migemoopt = '-t egrep -d /usr/share/migemo/migemo-dict' - " cmigemo - " let g:howm_migemoopt = '-q -d /usr/local/share/migemo/euc-jp/migemo-dict' -endif -" variables-migemo }}} -" variables }}} -" constant {{{ -let s:prefix_howm = "howm " -let s:buftitle_ftresult = "Search result" -let s:buftitle_preview = "Preview" -let s:buftitle_summary = "Summary" -let s:buftitle_webimport = "Web import" -let s:prompt_search_egrep = "Full text search(grep): " -let s:prompt_search_fgrep = "Full text search(fgrep): " -let s:prompt_search_migemo = "Full text search(migemo): " -let s:prompt_input_sortkey = "Sort by: " -let s:prompt_input_matchpattern = "Regexp: " -let s:prompt_lzchange = "RET (done), x (canceled), symbol (type), num (laziness): " -let s:msg_ftnomatch = "No match" -let s:msg_wait_search = "Searching..." -let s:msg_wait_parse = "Parsing..." -let s:msg_wait_sort = "Sorting..." -let s:msg_wait_format = "Formatting..." -let s:msg_done = "done." -let s:errmsg_inexecutable = "'%prg%' isn't executable. Please assign valid value to the variable '%var%'." + " variables-pattern {{{ + " 日付のパターン + " 予定や ToDo などに使用. + " TODO:%F(%Y-%m-%d), %T(%H:%M:%S), %R(%H:%M), %% を使えるようにする + if !exists('g:howm_date_pattern') + let g:howm_date_pattern = '%Y-%m-%d' + endif + " メモタイトルのパターン + if !exists('g:howm_title_pattern') + let g:howm_title_pattern = '=' + endif + " goto リンクのパターン + if !exists('g:howm_glink_pattern') + let g:howm_glink_pattern = '>>>' + endif + if !exists('g:howm_clink_pattern') + let g:howm_clink_pattern = '<<<' + endif + " Preview ヘッダのパターン + if !exists('g:howm_previewheader_pattern') + let g:howm_previewheader_pattern = + \ "\==========================>>> %file%\" + endif + " variables-pattern }}} + " variables-grep {{{ + if !exists('g:howm_grepprg') + if has('win32') + let g:howm_grepprg = '' + else + let g:howm_grepprg = 'grep' + endif + endif + " Grep 実行用コマンド群 + " #prg# は g:howm_grepprg で指定したプログラムに置換される + " #searchWord# は検索語に置換される + " #searchWordFile# は検索語を保存した作業用ファイル名に置換される + " (コマンドラインでうまくマルチバイト文字が扱えないときに有効) + " #searchPath# は検索対象パスに置換される + " CYGWIN GNU Grep 用設定 + if !exists('g:howm_grepcmd_regexp') + if has('win32') + let g:howm_grepcmd_regexp = + \ '#prg# -HInrE -f #searchWordFile# "#searchPath#"' + else + let g:howm_grepcmd_regexp = + \ '#prg# -HInrE -f #searchWordFile# #searchPath#' + endif + endif + if !exists('g:howm_grepcmd_regexp_ignore') + if has('win32') + let g:howm_grepcmd_regexp_ignore = + \ '#prg# -HInrEi -f #searchWordFile# "#searchPath#"' + else + let g:howm_grepcmd_regexp_ignore = + \ '#prg# -HInrEi -f #searchWordFile# #searchPath#' + endif + endif + if !exists('g:howm_grepcmd_fix') + if has('win32') + let g:howm_grepcmd_fix = + \ '#prg# -HInrF -f #searchWordFile# "#searchPath#"' + else + let g:howm_grepcmd_fix = + \ '#prg# -HInrF -f #searchWordFile# #searchPath#' + endif + endif + if !exists('g:howm_grepcmd_fix_ignore') + if has('win32') + let g:howm_grepcmd_fix_ignore = + \ '#prg# -HInrFi -f #searchWordFile# "#searchPath#"' + else + let g:howm_grepcmd_fix_ignore = + \ '#prg# -HInrFi -f #searchWordFile# #searchPath#' + endif + endif -let s:pattern_date = g:howm_date_pattern + " variables-grep }}} + " variables-find {{{ + " old variables + if !exists('g:howm_findprg') + " let g:howm_findprg = 'find' + if has('win32') + let g:howm_findprg = '' + else + let g:howm_findprg = 'find' + endif + endif + if !exists('g:howm_findcmd') + if has("win32") + let g:howm_findcmd = '#prg# "#searchPath#" -type f -print' + else + let g:howm_findcmd = '#prg# #searchPath# -type f -print' + endif + endif + " variables-find }}} + " variables-migemo {{{ + if !exists('g:howm_migemoprg') + let g:howm_migemoprg = 'migemo' + endif + if !exists('g:howm_migemoopt') + " ruby migemo + let g:howm_migemoopt = '-t egrep -d /usr/share/migemo/migemo-dict' + " cmigemo + " let g:howm_migemoopt = '-q -d /usr/local/share/migemo/euc-jp/migemo-dict' + endif + if !exists('g:howm_migemocmd') + let g:howm_migemocmd = "echo #searchWord# | #prg# #opt#" + endif + " variables-migemo }}} + + " variables }}} + " constant {{{ + let s:prefix_howm = "howm " + let s:buftitle_menu = "Menu" + let s:buftitle_ftresult = "Search result" + let s:buftitle_preview = "Preview" + let s:buftitle_summary = "Summary" + let s:buftitle_webimport = "Web import" + let s:prompt_search_egrep = "Full text search(grep): " + let s:prompt_search_fgrep = "Full text search(fgrep): " + let s:prompt_search_vgrep = "Full text search(vgrep): " + let s:prompt_search_migemo = "Full text search(migemo): " + let s:prompt_input_sortkey = "Sort by: " + let s:prompt_input_matchpattern = "Regexp: " + let s:prompt_lzchange = + \ "RET (done), x (canceled), symbol (type), num (laziness): " + let s:prompt_dtchange = + \ 'RET (goto), +num (shift), yymmdd (set), . (today): ' + let s:msg_ftnomatch = "No match" + let s:msg_wait_search = "Searching..." + let s:msg_wait_parse = "Parsing..." + let s:msg_wait_sort = "Sorting..." + let s:msg_wait_format = "Formatting..." + let s:msg_wait_rebuild = "Rebuilding..." + let s:msg_done = "done." + let s:errmsg_inexecutable = + \ "'%prg%' isn't executable. " . + \ "Please assign valid value to the variable '%var%'." + let s:errmsg_cantmkdir = "cannot create directory '%dir%'" + let s:errmsg_migemo = + \ "migemo検索はASCIIの印字可能文字を2文字以上入力してください" + let s:errmsg_invalidstype = "sortType が不正です" + let s:errmsg_invalidqtype = "searchWordType が不正です" + let s:errmsg_regexpgrep = + \ "g:howm_grepprg 以外では正規表現(grep)は扱えません" + let s:errmsg_regexpvim = + \ ":vimgrep 以外では正規表現(Vim)は扱えません" + let s:pattern_date = g:howm_date_pattern let s:pattern_date = substitute(s:pattern_date, '%Y', '\\(\\d\\{4}\\)', '') let s:pattern_date = substitute(s:pattern_date, '%m', '\\(\\d\\{2}\\)', '') let s:pattern_date = substitute(s:pattern_date, '%d', '\\(\\d\\{2}\\)', '') -function! s:CountLines(str) - let i = 0 - let idx = match(a:str, "\") - while idx != -1 - let i = i + 1 - let idx = match(a:str, "\", idx + 1) - endwhile - - return i -endfunction -let s:num_previewheader_lines = s:CountLines(g:howm_previewheader_pattern) - -" constant-actionlock {{{ -let s:actionlock_pat1 = g:howm_glink_pattern.' *.*$' -let s:actionlock_func1 = 's:ActionLockGotoLink' -let s:actionlock_pat2 = g:howm_clink_pattern -let s:actionlock_func2 = 's:ActionLockComeFromLink' -let s:actionlock_pat3 = '' -let s:actionlock_func3 = 's:ActionLockKeyword' -let s:actionlock_pat4 = '{[ *-]}' -let s:actionlock_func4 = 's:ActionLockCheckOff' -let s:actionlock_pat5 = '{_}' -let s:actionlock_func5 = 's:ActionLockTimeStamp' -let s:actionlock_pat6 = "s\\?https\\?://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]\\+" -let s:actionlock_func6 = 's:ActionLockURL' -let s:actionlock_pat7 = '\(\['.s:pattern_date.'\]\)\@<=[-!+@]\d*' -let s:actionlock_func7 = 's:ActionLockImportantDate' -let s:actionlock_pat8 = "{s\\?https\\?://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]\\+}" -let s:actionlock_func8 = 's:ActionLockWebImport' -let s:actionlock_pat9 = s:pattern_date -let s:actionlock_func9 = 's:ActionLockDate' - -if g:howm_reminder_old_format != 0 - " TODO:番号直指定がいや - let s:actionlock_pat7 = '@\['.s:pattern_date.'\]\(-\d\+\|[\!+@]\(\d*\)\)\?' + function! s:CountLines(str) + let i = 0 + let idx = match(a:str, "\") + while idx != -1 + let i = i + 1 + let idx = match(a:str, "\", idx + 1) + endwhile + return i + endfunction + let s:num_previewheader_lines = s:CountLines(g:howm_previewheader_pattern) + + " constant-actionlock {{{ + let s:actionlock_pat1 = g:howm_glink_pattern . ' *.*$' + let s:actionlock_func1 = 's:ActionLockGotoLink' + let s:actionlock_pat2 = g:howm_clink_pattern + let s:actionlock_func2 = 's:ActionLockComeFromLink' + let s:actionlock_pat3 = s:pattern_date + let s:actionlock_func3 = 's:ActionLockDate' + let s:actionlock_pat4 = '{[ *-]}' + let s:actionlock_func4 = 's:ActionLockCheckOff' + let s:actionlock_pat5 = '{_}' + let s:actionlock_func5 = 's:ActionLockTimeStamp' + let s:actionlock_pat6 = + \ "s\\?https\\?://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]\\+" + let s:actionlock_func6 = 's:ActionLockURL' + let s:actionlock_pat7 = '\(\[' . s:pattern_date . '\]\)\@<=[-!+@]\d*' + let s:actionlock_func7 = 's:ActionLockImportantDate' + let s:actionlock_pat8 = + \ "{s\\?https\\?://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]\\+}" + let s:actionlock_func8 = 's:ActionLockWebImport' + let s:actionlock_pat9 = '' + let s:actionlock_func9 = 's:ActionLockKeyword' + + " constant-actionlock }}} + " constant-sort {{{ + let s:laziness_normal = 1 + let s:laziness_todo = 7 + let s:init_todo = -7 + let s:laziness_deadline = 7 + let s:init_deadline = -2 + let s:laziness_schedule = 1 + " constant-sort }}} + + " constant }}} + " commands {{{ + command! -nargs=? HowmSchedule + \ :call HowmCommand('ShowScheduleA', ) + command! -nargs=? HowmSearchF + \ :call HowmCommand('FullTextSearchInputFgrepA', ) + command! -nargs=? HowmSearchE + \ :call HowmCommand('FullTextSearchInputEgrepA', ) + command! -nargs=? HowmSearchV + \ :call HowmCommand('FullTextSearchInputVgrepA', ) + command! -nargs=? HowmSearchM + \ :call HowmCommand('FullTextSearchInputMigemoA', ) + " commands }}} + " keymaps {{{ + if exists('g:mapleader') + let s:leader = g:mapleader + endif + let g:mapleader = g:howm_mapleader + if !hasmapto('HOWM_ShowDirectory') + silent! nmap ,a HOWM_ShowDirectory + endif + if !hasmapto('HOWM_OpenMemo') + silent! nmap ,c HOWM_OpenMemo + endif + if !hasmapto('HOWM_SearchF') + silent! nmap ,s HOWM_SearchF + endif + if !hasmapto('HOWM_SearchE') + silent! nmap ,g HOWM_SearchE + endif + if !hasmapto('HOWM_SearchV') + silent! nmap ,v HOWM_SearchV + endif + if !hasmapto('HOWM_SearchM') + silent! nmap ,m HOWM_SearchM + endif + if !hasmapto('HOWM_ShowSchedule') + silent! nmap ,y HOWM_ShowSchedule + endif + if !hasmapto('HOWM_ShowTodo') + silent! nmap ,t HOWM_ShowTodo + endif + if !hasmapto('HOWM_ShowMenu') + silent! nmap ,, HOWM_ShowMenu + endif + if !hasmapto('HOWM_RebuildKeywordFile') + silent! nmap ,rk HOWM_RebuildKeywordFile + endif + if !hasmapto('HOWM_RebuildScheduleFile') + silent! nmap ,ry HOWM_RebuildScheduleFile + endif + noremap