Code::Blocks Forums

User forums => Help => Topic started by: polygon7 on February 04, 2006, 12:04:43 PM

Title: "Variables" in "Default code" ?
Post by: polygon7 on February 04, 2006, 12:04:43 PM
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?
Title: Re: "Variables" in "Default code" ?
Post by: 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.
Title: Re: "Variables" in "Default code" ?
Post by: polygon7 on February 04, 2006, 05:42:17 PM
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.
Title: Re: "Variables" in "Default code" ?
Post by: thomas on February 04, 2006, 05:51:14 PM
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).
Title: Re: "Variables" in "Default code" ?
Post by: polygon7 on February 04, 2006, 06:03:49 PM
Thanks, now i see :)
Title: Re: "Variables" in "Default code" ?
Post by: takeshimiya on February 04, 2006, 09:15:28 PM
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?
Title: Re: "Variables" in "Default code" ?
Post by: thomas on February 04, 2006, 09:21:47 PM
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
Title: Re: "Variables" in "Default code" ?
Post by: takeshimiya on February 04, 2006, 09:27:46 PM
There are some things that deserve an option but doesn't deserve a gui. Let's see how...