Author Topic: "Variables" in "Default code" ?  (Read 8232 times)

Offline polygon7

  • Multiple posting newcomer
  • *
  • Posts: 104
    • Home site
"Variables" in "Default code" ?
« 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?
best regards,
p7
 Free open source UML modeling tool: ArgoUML

Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Re: "Variables" in "Default code" ?
« Reply #1 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.

Offline polygon7

  • Multiple posting newcomer
  • *
  • Posts: 104
    • Home site
Re: "Variables" in "Default code" ?
« Reply #2 on: February 04, 2006, 05:42:17 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

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: "Variables" in "Default code" ?
« Reply #3 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).
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline polygon7

  • Multiple posting newcomer
  • *
  • Posts: 104
    • Home site
Re: "Variables" in "Default code" ?
« Reply #4 on: February 04, 2006, 06:03:49 pm »
Thanks, now i see :)
best regards,
p7
 Free open source UML modeling tool: ArgoUML

takeshimiya

  • Guest
Re: "Variables" in "Default code" ?
« Reply #5 on: February 04, 2006, 09:15:28 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?

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: "Variables" in "Default code" ?
« Reply #6 on: February 04, 2006, 09:21:47 pm »
Maybe 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

  • Guest
Re: "Variables" in "Default code" ?
« Reply #7 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...