1 " vi:set ts=8 sts=2 sw=2 tw=0:
3 " autodate.vim - A plugin to update time stamps automatically
5 " Maintainer: MURAOKA Taro <koron@tka.att.ne.jp>
6 " Last Change: 06-Feb-2006.
10 " :Autodate Manually autodate.
11 " :AutodateON Turn on autodate in current buffer (default).
12 " :AutodateOFF Turn off autodate in current buffer.
15 " Each global variable (option) is overruled by buffer variable (what
19 " Format string used for time stamps. See |strftime()| for details.
20 " See MonthnameString() for special extension of format.
21 " Default: '%d-%3m-%Y'
24 " The number of lines searched for the existence of a time stamp when
25 " writing a buffer. The search range will be from top of buffer (or
26 " line 'autodate_start_line') to 'autodate_lines' lines below. The
27 " bigger value you have, the longer it'll take to search words. You
28 " can expect to improve performance by decreasing the value of this
32 " 'autodate_start_line'
33 " Line number to start searching for time stamps when writing buffer
35 " If minus, line number is counted from the end of file.
38 " 'autodate_keyword_pre'
39 " A prefix pattern (see |pattern| for details) which denotes time
40 " stamp's location. If empty, default value will be used.
41 " Default: '\cLast Change:'
43 " 'autodate_keyword_post'
44 " A postfix pattern which denotes time stamp's location. If empty,
45 " default value will be used.
49 " Write a line as below (case ignored) somewhere in the first 50 lines of
52 " When writing the buffer to a file, this line will be modified and a time
53 " stamp will be inserted automatically. Example:
54 " Last Change: 11-May-2002.
56 " You can execute :Autodate command to update time stamps manually. The
57 " range of lines which looks for a time stamp can also be specified. When
58 " no range is given, the command will be applied to the current line.
60 " :%Autodate " Whole file
61 " :\<,\>Autodate " Range selected by visual mode
62 " :Autodate " Current cursor line
64 " The format of the time stamp to insert can be specified by
65 " 'autodate_format' option. See |strftime()| (vim script function) for
66 " details. Sample format settings and the corresponding outputs are show
68 " FORMAT: %Y/%m/%d OUTPUT: 2001/12/24
69 " FORMAT: %H:%M:%S OUTPUT: 10:06:32
70 " FORMAT: %y%m%d-%H%M OUTPUT: 011224-1006
72 " Autodate.vim determines where to insert a time stamp by looking for a
73 " KEYWORD. A keyword consists of a PREFIX and a POSTFIX part, and they
74 " can be set by 'autodate_keyword_pre' and 'autodate_keyword_post'
75 " options, respectively. If you set these values as below in your .vimrc:
76 " :let autodate_format = ': %Y/%m/%d %H:%M:%S '
77 " :let autodate_keyword_pre = '\$Date'
78 " :let autodate_keyword_post = '\$'
79 " They will function like $Date$ in cvs. Example:
80 " $Date: 2001/12/24 10:06:32 $
82 " Just another application. To insert a time stamp between '<!--DATE-->'
83 " when writing HTML, try below:
84 " :let b:autodate_keyword_pre = '<!--DATE-->'
85 " :let b:autodate_keyword_post = '<!--DATE-->'
86 " It will be useful if to put these lines in your ftplugin/html.vim.
88 " <!--DATE-->24-Dec-2001<!--DATE-->
90 " In addition, priority is given to a buffer local option (what starts in
91 " b:) about all the options of autodate.
94 " To make vim NOT TO LOAD this plugin, write next line in your .vimrc:
95 " :let plugin_autodate_disable = 1
97 " Japanese Description:
99 " :Autodate Žè“®‚Ń^ƒCƒ€ƒXƒ^ƒ“ƒv�X�V
100 " :AutodateON Œ»�݂̃oƒbƒtƒ@‚ÌŽ©“®�X�V‚ð—LŒø‰»
101 " :AutodateOFF Œ»�݂̃oƒbƒtƒ@‚ÌŽ©“®�X�V‚𖳌ø‰»
103 " ƒIƒvƒVƒ‡ƒ“: (‚»‚ꂼ‚ê‚̃IƒvƒVƒ‡ƒ“‚̓oƒbƒtƒ@”Å(b:)‚ª—D�悳‚ê‚é)
106 " ƒ^ƒCƒ€ƒXƒ^ƒ“ƒv‚ÉŽg—p‚³‚ê‚éƒtƒH�[ƒ}ƒbƒg•¶Žš—ñ�BƒtƒH�[ƒ}ƒbƒg‚Ì�Ú�ׂÍ
107 " |strftime()|‚ðŽQ�Æ�BƒtƒH�[ƒ}ƒbƒg‚Ö‚Ì“ÆŽ©Šg’£‚ɂ‚¢‚Ä‚ÍMonthnameString()
108 " ‚ðŽQ�Æ�B�È—ª’l: '%d-%3m-%Y'
111 " •Û‘¶Žž‚Ƀ^ƒCƒ€ƒXƒ^ƒ“ƒv‚Ì‘¶�Ý‚ðƒ`ƒFƒbƒN‚·‚é�s�”�B‘�‚₹‚Α�‚â‚·‚Ù‚Ç
112 " ƒL�[ƒ��[ƒh‚ðŒŸ�õ‚·‚邽‚ß‚ÉŽžŠÔ‚ª‚©‚©‚è“®�삪’x‚‚È‚é�B‹t‚É’x‚¢‚ÆŠ´‚¶
113 " ‚½‚Æ‚«‚É‚Í�¬‚³‚È’l‚ð�Ý’è‚·‚ê‚΃pƒtƒH�[ƒ}ƒ“ƒX‚̉ü‘P‚ªŠú‘Ò‚Å‚«‚é�B
116 " 'autodate_keyword_pre'
117 " ƒ^ƒCƒ€ƒXƒ^ƒ“ƒv‚Ì‘¶�Ý‚ðŽ¦‚·‘O’uƒL�[ƒ��[ƒh(�³‹K•\Œ»)�B•K�{�B‹ó•¶Žš—ñ‚ð
118 " Žw’è‚·‚é‚Æ�È—ª’l‚ªŽg‚í‚ê‚é�B�È—ª’l: '\cLast Change:'
120 " 'autodate_keyword_post'
121 " ƒ^ƒCƒ€ƒXƒ^ƒ“ƒv‚Ì‘¶�Ý‚ðŽ¦‚·Œã’uƒL�[ƒ��[ƒh(�³‹K•\Œ»)�B•K�{�B‹ó•¶Žš—ñ‚ð
122 " Žw’è‚·‚é‚Æ�È—ª’l‚ªŽg‚í‚ê‚é�B�È—ª’l: '\.'
125 " ƒtƒ@ƒCƒ‹‚Ì�擪‚©‚ç50�sˆÈ“à‚É
127 " ‚Æ�‘‚¢‚½�s(‘啶Žš�¬•¶Žš‚Í‹æ•Ê‚µ‚Ü‚¹‚ñ)‚ð—pˆÓ‚·‚é‚Æ�Aƒtƒ@ƒCƒ‹‚Ì•Û‘¶(:w)Žž
128 " ‚ÉŽ©“®“I‚É‚»‚ÌŽž��(ƒ^ƒCƒ€ƒXƒ^ƒ“ƒv)‚ª‘}“ü‚³‚ê‚Ü‚·�BŒ‹‰Ê—á:
129 " Last Change: 11-May-2002.
131 " ExƒRƒ}ƒ“ƒh‚Ì:Autodate‚ðŽÀ�s‚·‚邱‚Æ‚ÅŽè“®‚Ń^ƒCƒ€ƒXƒ^ƒ“ƒv‚Ì�X�V‚ª�s‚È‚¦
132 " ‚Ü‚·�B‚»‚Ì�ۂɃ^ƒCƒ€ƒXƒ^ƒ“ƒv‚ð’T‚·”͈͂ðŽw’è‚·‚邱‚Æ‚à‚Å‚«‚Ü‚·�B“Á‚ɔ͈Í
133 " ‚ðŽw’肵‚È‚¯‚ê‚΃J�[ƒ\ƒ‹‚Ì‚ ‚é�s‚ª‘Î�Û‚É‚È‚è‚Ü‚·�B—á:
134 " :%Autodate " ƒtƒ@ƒCƒ‹‘S‘Ì
135 " :\<,\>Autodate " ƒrƒWƒ…ƒAƒ‹‘I‘ð—̈æ
136 " :Autodate " Œ»�݃J�[ƒ\ƒ‹‚Ì‚ ‚é�s
138 " ‘}“ü‚·‚éƒ^ƒCƒ€ƒXƒ^ƒ“ƒv‚Ì�‘Ž®‚̓IƒvƒVƒ‡ƒ“'autodate_format'‚ÅŽw’è‚·‚邱‚Æ
139 " ‚ª‚Å‚«‚Ü‚·�B�Ú�ׂÍVimƒXƒNƒŠƒvƒgŠÖ�”|strftime()|‚Ì�à–¾‚É�]‚¢‚Ü‚·�BˆÈ‰º‚É
140 " �‘Ž®‚Æ‚»‚Ì�o—Í‚Ì—á‚ðŽ¦‚µ‚Ü‚·:
141 " �‘Ž®: %Y/%m/%d �o—Í: 2001/12/24
142 " �‘Ž®: %H:%M:%S �o—Í: 10:06:32
143 " �‘Ž®: %y%m%d-%H%M �o—Í: 011224-1006
145 " autodate.vim‚̓L�[ƒ��[ƒh‚ð’T‚·‚±‚ƂŃ^ƒCƒ€ƒXƒ^ƒ“ƒv‚ð‘}“ü‚·‚ׂ«ˆÊ’u‚ðŒˆ’è
146 " ‚µ‚Ä‚¢‚Ü‚·�BƒL�[ƒ��[ƒh‚Í‘O’u•”‚ÆŒã’u•”‚©‚ç‚È‚è�A‚»‚ꂼ‚êƒIƒvƒVƒ‡ƒ“‚Ì
147 " 'autodate_keyword_pre'‚Æ'autodate_keyword_post'‚ð�Ý’è‚·‚邱‚Æ‚Å•Ï�X‚Å‚«
148 " ‚Ü‚·�BŒÂ�l�Ý’èƒtƒ@ƒCƒ‹(_vimrc)‚ÅŽŸ‚̂悤‚É�Ý’è‚·‚é‚Æ:
149 " :let autodate_format = ': %Y/%m/%d %H:%M:%S '
150 " :let autodate_keyword_pre = '\$Date'
151 " :let autodate_keyword_post = '\$'
152 " cvs‚É‚¨‚¯‚é$Date$‚̂悤‚É“®�삵‚Ü‚·�B—á:
153 " $Date: 2001/12/24 10:06:32 $
155 " ‰ž—p‚Æ‚µ‚ÄHTML‚ð‹L�q‚·‚é�Û‚É<!--DATE-->‚ň͂܂ꂽ’†‚Ƀ^ƒCƒ€ƒXƒ^ƒ“ƒv‚ð‘}
156 " “ü‚³‚¹‚½‚¢�ê�‡‚É‚Í:
157 " :let b:autodate_keyword_pre = '<!--DATE-->'
158 " :let b:autodate_keyword_post = '<!--DATE-->'
159 " ‚ÆŽw’肵‚Ü‚·�Bftplugin/html.vim‚Å�Ý’è‚·‚é‚Æ•Ö—˜‚Å‚µ‚傤�B—á:
160 " <!--DATE-->24-Dec-2001<!--DATE-->
162 " ‚È‚¨autodate‚Ì‘�‚ẴIƒvƒVƒ‡ƒ“‚ɂ‚¢‚Ä�Aƒoƒbƒtƒ@ƒ��[ƒJƒ‹ƒIƒvƒVƒ‡ƒ“(b:‚Å
163 " Žn‚Ü‚é‚à‚Ì)‚ª—D�悳‚ê‚Ü‚·�B
165 " ‚±‚̃vƒ‰ƒOƒCƒ“‚ð“Ç�ž‚Ý‚½‚‚È‚¢Žž‚Í.vimrc‚ÉŽŸ‚̂悤‚É�‘‚‚±‚Æ:
166 " :let plugin_autodate_disable = 1
168 if exists('plugin_autodate_disable')
173 "---------------------------------------------------------------------------
179 if !exists('autodate_format')
180 let g:autodate_format = '%d-%3m-%Y'
186 if !exists('autodate_lines')
187 let g:autodate_lines = 50
191 " 'autodate_start_line'
193 if !exists('autodate_start_line')
194 let g:autodate_start_line = 1
198 " 'autodate_keyword_pre'
200 if !exists('autodate_keyword_pre')
201 let g:autodate_keyword_pre = '\cLast Change:'
205 " 'autodate_keyword_post'
207 if !exists('autodate_keyword_post')
208 let g:autodate_keyword_post = '\.'
211 "---------------------------------------------------------------------------
214 command! -range Autodate call <SID>Autodate(<line1>, <line2>)
215 command! AutodateOFF let b:autodate_disable = 1
216 command! AutodateON let b:autodate_disable = 0
220 autocmd BufUnload,FileWritePre,BufWritePre * call <SID>Autodate()
222 endif " has("autocmd")
224 "---------------------------------------------------------------------------
228 " Autodate([{firstline} [, {lastline}]])
230 " {firstline}‚Æ{lastline}‚ÅŽw’肳‚ꂽ”͈͂ɂ‚¢‚Ä�Aƒ^ƒCƒ€ƒXƒ^ƒ“ƒv‚ÌŽ©“®
231 " ƒAƒbƒvƒf�[ƒg‚ð�s‚È‚¤�B{firstline}‚ª�È—ª‚³‚ꂽ�ê�‡‚̓tƒ@ƒCƒ‹‚Ì�擪�A
232 " {lastline}‚ª�È—ª‚³‚ꂽ�ê�‡‚Í{firstline}‚©‚ç'autodate_lines'�s‚͈̔͂ª‘Î
235 function! s:Autodate(...)
237 if (exists('b:autodate_disable') && b:autodate_disable != 0) || &modified == 0
242 if a:0 > 0 && a:1 > 0
245 let firstline = s:GetAutodateStartLine()
249 if a:0 > 1 && a:2 <= line('$')
252 let lastline = firstline + s:GetAutodateLines() - 1
254 if lastline > line('$')
255 let lastline = line('$')
259 if firstline <= lastline
260 call s:AutodateStub(firstline, lastline)
265 " GetAutodateStartLine()
267 " ’T�õŠJŽn“_‚ðŽæ“¾‚·‚é
269 function! s:GetAutodateStartLine()
271 if exists('b:autodate_start_line')
272 let retval = b:autodate_start_line
273 elseif exists('g:autodate_start_line')
274 let retval = g:autodate_start_line
278 let retval = retval + line('$') + 1
289 " autodate‘Î�۔͈͂ðŽæ“¾‚·‚é
291 function! s:GetAutodateLines()
292 if exists('b:autodate_lines') && b:autodate_lines > 0
293 return b:autodate_lines
294 elseif exists('g:autodate_lines') && g:autodate_lines > 0
295 return g:autodate_lines
302 " AutodateStub(first, last)
304 " Žw’肳‚ꂽ”͈͂ɂ‚¢‚ă^ƒCƒ€ƒXƒ^ƒ“ƒv‚ÌŽ©“®ƒAƒbƒvƒf�[ƒg‚ð�s‚È‚¤�B
306 function! s:AutodateStub(first, last)
308 " Verify pre-keyword.
309 if exists('b:autodate_keyword_pre') && b:autodate_keyword_pre != ''
310 let pre = b:autodate_keyword_pre
312 if exists('g:autodate_keyword_pre') && g:autodate_keyword_pre != ''
313 let pre = g:autodate_keyword_pre
315 let pre = '\cLast Change:'
319 " Verify post-keyword.
320 if exists('b:autodate_keyword_post') && b:autodate_keyword_post != ''
321 let post = b:autodate_keyword_post
323 if exists('g:autodate_keyword_post') && g:autodate_keyword_post != ''
324 let post = g:autodate_keyword_post
331 if exists('b:autodate_format') && b:autodate_format != ''
332 let format = b:autodate_format
334 if exists('g:autodate_format') && g:autodate_format != ''
335 let format = g:autodate_format
337 let format = '%d-%3m-%Y'
341 " Generate substitution pattern
342 let pat = '\('.pre.'\s*\)\(\S.*\)\?\('.post.'\)'
343 let sub = Strftime2(format)
346 echo "range=".a:first."-".a:last
354 let curline = getline(i)
356 let newline = substitute(curline, pat, '\1' . sub . '\3', '')
357 if curline !=# newline
358 call setline(i, newline)
366 " Strftime2({format} [, {time}])
367 " Enchanced version of strftime().
369 " strftime()‚̃tƒH�[ƒ}ƒbƒgŠg’£ƒo�[ƒWƒ‡ƒ“�BƒtƒH�[ƒ}ƒbƒg�‘Ž®‚Í‚Ù‚Æ‚ñ‚ǃIƒŠƒW
370 " ƒiƒ‹‚ƈê���B‚µ‚©‚µŒŽ‚̉pŒê–¼‚É’uŠ·‚í‚é“Á•Ê‚È�‘Ž® %{n}m ‚ªŽg—p‰Â”\�B{n}‚É
371 " ‚͉pŒê–¼‚Ì•¶Žš—ñ‚Ì’·‚³‚ðŽw’è‚·‚é(�Å‘å9)�B0‚ðŽw’è‚·‚ê‚Η]•ª‚È‹ó”’‚Í•t‰Á‚³
374 " :echo Strftime2("%d-%3m-%Y")
376 " :echo Strftime2("%d-%0m-%Y")
379 function! Strftime2(...)
381 " Get {time} argument.
385 let time = localtime()
387 " Parse special format.
389 let format = substitute(format, '%\(\d\+\)m', '\=MonthnameString(-1, submatch(1), time)', 'g')
390 let format = substitute(format, '%\(\d\+\)a', '\=DaynameString(-1, submatch(1), time)', 'g')
391 return strftime(format, time)
398 " MonthnameString([{month} [, {length} [, {time}]]])
399 " Get month name string in English with first specified letters.
401 " ‰pŒê‚ÌŒŽ–¼‚ðŽw’肵‚½’·‚³‚Å•Ô‚·�B{month}‚ð�È—ª‚µ‚½�ê�‡‚É‚ÍŒ»�Ý‚ÌŒŽ–¼‚ª•Ô
402 " ‚³‚ê‚é�B{month}‚É–³Œø‚ÈŽw’è(1�`12ˆÈŠO)‚ª�s‚È‚í‚ꂽ�ê�‡‚Í{time}‚ÅŽ¦‚³‚ê‚é
403 " ŒŽ–¼‚ª•Ô‚³‚ê‚é�B{time}‚ð�È—ª‚µ‚½�ê�‡‚É‚Í‘ã‚í‚è‚É|localtime()|‚ªŽg—p‚³‚ê
404 " ‚é�B{length}‚É‚Í•Ô‚·–¼‘O‚Ì’·‚³‚ðŽw’è‚·‚邪�È—ª‚·‚é‚Æ”CˆÓ’·‚É‚È‚é�B
406 " :echo MonthnameString(8) . " 2001"
408 " :echo MonthnameString(8,3) . " 2001"
411 function! MonthnameString(...)
412 " Get {time} argument.
416 let time = localtime()
419 if a:0 > 0 && (a:1 >= 1 && a:1 <= 12)
422 let month = substitute(strftime('%m', time), '^0\+', '', '')
425 if a:0 > 1 && (a:2 >= 1 && a:2 <= 9)
428 let length = strpart('785534469788', month - 1, 1)
430 " Generate string of month name.
431 return strpart('January February March April May June July August SeptemberOctober November December ', month * 9 - 9, length)
435 " DaynameString([{month} [, {length} [, {time}]]])
436 " Get day name string in English with first specified letters.
438 " ‰pŒê‚Ì—j“ú–¼‚ðŽw’肵‚½’·‚³‚Å•Ô‚·�B{day}‚ð�È—ª‚µ‚½�ê�‡‚É‚Í–{“ú‚Ì—j“ú–¼‚ª
439 " •Ô‚³‚ê‚é�B{day}‚É–³Œø‚ÈŽw’è(0�`6ˆÈŠO)‚ª�s‚È‚í‚ꂽ�ê�‡‚Í{time}‚ÅŽ¦‚³‚ê‚é
440 " —j“ú–¼‚ª•Ô‚³‚ê‚é�B{time}‚ð�È—ª‚µ‚½�ê�‡‚É‚Í‘ã‚í‚è‚É|localtime()|‚ªŽg—p‚³
441 " ‚ê‚é�B{length}‚É‚Í•Ô‚·–¼‘O‚Ì’·‚³‚ðŽw’è‚·‚邪�È—ª‚·‚é‚Æ”CˆÓ’·‚É‚È‚é�B
443 " :echo DaynameString(0)
445 " :echo DaynameString(5,3).', 13th'
448 function! DaynameString(...)
449 " Get {time} argument.
453 let time = localtime()
456 if a:0 > 0 && (a:1 >= 0 && a:1 <= 6)
459 let day = strftime('%w', time) + 0
462 if a:0 > 1 && (a:2 >= 1 && a:2 <= 9)
465 let length = strpart('6798686', day, 1)
467 " Generate string of day name.
468 return strpart('Sunday Monday Tuesday WednesdayThursday Friday Saturday ', day * 9, length)