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