-
Notifications
You must be signed in to change notification settings - Fork 0
/
dates.rc
40 lines (36 loc) · 1.31 KB
/
dates.rc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
; $Header: /usr/build/vile/vile/macros/RCS/dates.rc,v 1.2 2001/09/24 00:24:39 tom Exp $
; These macros illustrate the use of the &date function.
; Insert/update a timestamp at the first place in the file with "Last updated:",
; or similar text. Bound this to F19 (which is shift-F9 on xterm) to show the
; difference between an insert-binding and a regular binding.
store-procedure InsertTimestamp
~local $curcol $curline $ignorecase $search
~local %label %stamp %length
setv %label='\<last \(update\|change\)[d]\?:'
setv %stamp=&date '%Y/%m/%d %H:%M:%S' &stime
setl ignorecase
goto-beginning-of-file
~force search-forward %label
~if &seq $match ''
write-message 'InsertTimestamp - fail'
~else
write-message 'InsertTimestamp - ok'
setv %length &sub &add $curcol &len $match 1
goto-bol
setv $line &cat &left $line %length &cat ' ' %stamp
~endif
~endm
bind-insmode-key InsertTimestamp #-(
; Show the date/time when the file was last modified.
store-procedure ShowTimestamp
write-message &cat 'File last modified: ' &date '%Y/%m/%d %H:%M:%S' &ftime $cbufname
~endm
bind-key ShowTimestamp #-9
; Make a write-hook (if the buffer is modified, the macro will change the
; last-updated field before writing).
store-procedure UpdateTimestamp
~if $modified
InsertTimestamp
~endif
~endm
setv $write-hook UpdateTimestamp