I would like ZEUS to add a header at the top of each file:
! Last edited on DATE TIME by PROGRAMMER
where ! is the comment identifier.
Is there a way to do this?
Is this part of Source Control?
Edited by and Edited when
-
- Posts: 38
- Joined: Thu Apr 07, 2005 7:07 pm
Is there a way to do this?
This Lua script will insert such a comment to the top of the current file:
Code: Select all
function key_macro()
-- macro only works for documents
local document = is_document()
if document == 0 then
message("This macro only works for document files!")
beep()
return
end
-- macro only works for read/write documents
local locked = is_read_only()
if locked == 1 then
message("The current document is marked as read only!")
beep()
return
end
-- move to start of document
MoveDocumentStart()
-- get the user name found in Options, Editor Options menu, User Defines
local string user_name = macro_tag("$UN")
local string user_initials = macro_tag("$UI")
local string user_id = macro_tag("$UID")
-- get date/time using zeus macro tags (see onlin help for more details)
local string c_date = macro_tag("$DT<d MMMM yyyy> ")
local string c_time = macro_tag("$T<HH:mm tt> ")
-- build up comment string
local string comment = "! Last edited on " .. c_date .. " " .. c_time .." by " .. user_name .. " " .. user_id .. " " .. user_initials .. "\n"
-- print comment
write(comment)
end
key_macro() -- run the macro
You will have to change the macro to only work for a given file extension. This code can be used to get the extension of the current file.I would like ZEUS to add a header at the top of each file:
Code: Select all
-- get the current file extensions
local extension = macro_tag("$Ext")
Most version controls do have such a feature. For more details you will need to refer to the documentation of the version control you are using. If you are using CVS, a search of the Web will probably supply the answer.Is this part of Source Control?
Alternatively you could modify the macro to also do the actual check-in by adding this line of code:
Code: Select all
-- check in the file
SccFileCheckIn()
-
- Posts: 38
- Joined: Thu Apr 07, 2005 7:07 pm
That works quite well.
I made a few modifications:
1) check to see if there is already a time stamp line
2) check the file extensions (as you suggested)
3) restore the cursor position after the time stamp is updated
4) set to insert mode so I don't overwrite the first line!
5) save the file
6) associate the file with Cntl-S
I may update my code if for Cntl-A (save all files) using
1) is_modified
2) navigateviewnext
and cycle through all the open files, saving code that has been modified with the updated time stamp
This is what I'm using now:
I made a few modifications:
1) check to see if there is already a time stamp line
2) check the file extensions (as you suggested)
3) restore the cursor position after the time stamp is updated
4) set to insert mode so I don't overwrite the first line!
5) save the file
6) associate the file with Cntl-S
I may update my code if for Cntl-A (save all files) using
1) is_modified
2) navigateviewnext
and cycle through all the open files, saving code that has been modified with the updated time stamp
This is what I'm using now:
Code: Select all
function key_macro()
-- macro only works for documents
local document = is_document()
if document == 0 then
message("This macro only works for document files!")
beep()
return
end
-- don't set header or save unmodified documents
local changed = is_modified()
if changed == 0 then
return
end
-- macro only works for read/write documents
local locked = is_read_only()
if locked == 1 then
message("The current document is marked as read only!")
beep()
return
end
-- get the current file extensions
cExt = macro_tag("$Ext")
cExt = string.lower(cExt)
if cExt == ".for" then
screen_update_disable()
-- do not want to overwrite the first line!
InsertModeSet()
iCur = get_cursor_pos()
iLin = get_line_pos()
-- move to start of document
MoveDocumentStart()
cLine = get_line_text()
if string.sub(cLine,1,16) == "! Last edited on" then
LineCut()
end
-- get the user name found in Options, Editor Options menu, User Defines
local string user_name = macro_tag("$UN")
local string user_initials = macro_tag("$UI")
local string user_id = macro_tag("$UID")
-- get date/time using zeus macro tags (see onlin help for more details)
local string c_date = macro_tag("$DT<d MMMM yyyy> ")
local string c_time = macro_tag("$T<HH:mm tt> ")
-- build up comment string
local string comment = "! Last edited on " .. c_date .. " " .. c_time .." by " .. user_name .. " " .. user_id .. " " .. user_initials .. "\n"
-- print comment
write(comment)
set_line_pos(iLin)
set_cursor_pos(iCur)
screen_update_enable()
screen_update()
end
FileSave()
end
key_macro() -- run the macro