News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

"Variables" in "Default code" ?

Started by polygon7, February 04, 2006, 12:04:43 PM

Previous topic - Next topic

polygon7

Hi,
is it possible to add "variables" (global or project or whatever variables) to deafult code?
I want something like that:

"Variables":
Quote
@author = p7
@date= 01 Feb 2006
@project_name= Some project
@currdate= `date`

Default code with "variables"
Quote
**********************************************
Author: @author
Date: @date
Project: @project_name
Comments:
Last modification: @currdate
**********************************************

Default code in c/cpp/h file:
Quote
**********************************************
Author: p7
Date: 01 Feb 2006
Project: Some project
Comments:
Last modification: 04 Feb 2006
**********************************************
How to make it?
best regards,
p7
Free open source UML modeling tool: ArgoUML

Game_Ender

You mean you want CodeBlocks to automatically replace @author with your name whenever it saves a file?  But keep the keyword when you open it?  You should take a look at Subversion it offers similar functionality and seems to fit better with the source control system.  Also @ could not be used for keywords because it conflicts with doxygen style comments.

polygon7

Quote from: Game_Ender on February 04, 2006, 05:03:11 PM
You mean you want CodeBlocks to automatically replace @author with your name whenever it saves a file?  But keep the keyword when you open it?  You should take a look at Subversion it offers similar functionality and seems to fit better with the source control system.  Also @ could not be used for keywords because it conflicts with doxygen style comments.
No, no. I want C::B to replace variables only with new files and only in "default code" placed at the top of c/cpp/h files.
KDevelop have dialog window for author, licenece, email and other things for "default code" when you create project.
I think something similar could be achieved using "default code" variables in C::B.

"@" is used as example it can be any character.

For example:
You have this "variable" set:
Quote@author = Game_Ender
You make new project "FooBar", then you open Settings->Editor->Default Code, and put:
Quote
/****************************
* Author: @author
* Project: @project_name
* File:      @file_name
*
****************************/
And then for every new c/cpp/h file in project FooBar C::B puts:
Quote
/****************************
* Author: Game_Ender
* Project: FooBar
* File:      FooBar.c / FooBar.h / whatever
*
****************************/

Sorry but my english isn't good, and i dont know how to explain it more clearly.
best regards,
p7
Free open source UML modeling tool: ArgoUML

thomas

What you want is possible, and it is quite easy too (in principle). All you need to do is add one call to MacrosManager::ReplaceMacros(). This will replace $(ANY_VARIABLE).

In any case, you should add a config option to turn this behaviour on and off, otherwise it may interfere with code that contains something that looks like a variable (in which case this behaviour is not wanted).
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

polygon7

best regards,
p7
Free open source UML modeling tool: ArgoUML

takeshimiya

Quote from: thomas on February 04, 2006, 05:51:14 PM
In any case, you should add a config option to turn this behaviour on and off, otherwise it may interfere with code that contains something that looks like a variable (in which case this behaviour is not wanted).

Maybe it's not necesary, what about replacing only variables that have been defined, and left intact those who not?

thomas

Quote from: Takeshi Miya on February 04, 2006, 09:15:28 PMMaybe it's not necesary, what about replacing only variables that have been defined, and left intact those who not?
No
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

takeshimiya

There are some things that deserve an option but doesn't deserve a gui. Let's see how...