4
votes

Does anyone know of a short cut to place my name and the date where the cursor is i.e.

 //021208 DarkAxi0m

so i don't keep check what the date is when i'm adding comments.

Im using Delphi7, with CnPack And GExperts Installed. I think it should be able to be done with one of those experts.

6
This is a pretty old question and an answer has already been accepted so I'd just like to emphasize for anyone else who happens to find it that using the commit log of a version control system is far superior to using date-stamped comments as an adhoc journal of changes. Comments should be used to inform, explain, clarify or warn about a section of code. Any other use is likely to introduce noise that distracts from the purpose of the code. - Kenneth Cochran

6 Answers

5
votes

I use GExperts to do this, like so:

in the

GExperts\Configuration

Select the Editor Experts tab.

In the list of experts, select

Insert Date\Time

Click on the configuration, insert the desired text:

'//' ddmmyy 'DarkAxi0m: ' //021208 DarkAxi0m:

After, to insert your new Date name comment all you need to do is:

ctrl+alt+a

I setup most programmers at the job like that.

2
votes

It is also simple to do with GExperts' Expand Macro Template (found in Editor Experts).

I use this expansion to insert yyyy-mm-dd at the current position:

%YEAR%-%MONTH%-%DAY%|

2
votes

For a solution that will work in most applications under Windows, not only in Delphi, you can use Authotkey (free, autohotkey.com). One of its many features is the ability to expand strings that you type - typically used for autocorrecting typos.

I start all my shortcut strings with a semicolon, since it practically never leads strings I type in real life, so in your example, to insert a comment-date-username sequence, I would want to type semicolon, slash, slash:

;//

The Authotkey script (which you can put in an .ahk text file and add the file to Autostart) would look like this:

::;//::                             ; this means: when I type ";//", do what follows
FormatTime, curDate,, yyyy-MM-dd    ; the double comma is intended
SendInput // %curDate% %A_UserName% ; variable expansion
return

This produces the following output:

// 2008-12-05 moodforaday

AHK syntax is a little dense, but there is an extensive help file.

On edit: this script could be expanded to apply the correct comment syntax depending on the IDE you are working in at the moment. You would detect active window title, find a signature substring ("Delphi") and choose the proper comment character(s). This way you could type the same hotstring to insert your comment regardless of the current IDE or language. You can also use SendInput to position the caret the way Delphi templates do.

1
votes

Never mind found one in CnPack/Soure Templates Added the template

  //%Date% DarkAxi0m

Note: i should look in the menus more closely

1
votes

You might also look at the Live Templates feature, which can be scripted to do just what you want:

http://cc.codegear.com/Item/24990

Don't be put off by the name, it includes a template script to include the date, time, including the ability to format it as you want.

1
votes

Here is a variation with GExperts (www.gexperts.org) that makes it easy to search for changes based on developer or date.

Example of output and comment:

   //07.25.2009 (SLB20090725) - Added 3rd optional parameter.

Besides an easily readable date I can easy search for comments programmer, by year, year+month etc.) For example I can search for (SLB200905 for any comments I logged in May of 2009.

To do: Under the GExperts menu open Configuration... (at the bottom of the list) then select the Editor Experts tab. Locate 'Insert Date/Time' and double click on it.

//mm.dd.yyyy '(ABC'yyyymmdd') -'

Where ABC is the programmers name, initials, id, or whatever.

Then use Ctrl-Alt-A when in Delphi's IDE to insert

This should work in any verison of Delphi supported by GExperts.