User forums > Help
Different handling of placeholders
(1/1)
rechtsanwaltsteyer:
Hello everyone,
her my until now unresponded question again:
Since version 20.03 and also in the current version 25.03, I have an unsolvable problem:
1. If I enter a placeholder under Settings/Editor/Code Specification, such as "$(NOW_L)", the current date and time is displayed in the subsequently generated single file (*.cpp/*.h).
2. However, if I enter the same placeholders in /usr/share/codeblocks/templates/wizard/console/cpp/main.cpp, when generating a new project, "$(NOW_L)" is displayed in main.cpp instead of the current date and time.
My question: Why this different treatment of "$(NOW_L)?"
Thank you in advance!
Michael
blauzahn:
Maybe because macro expansion is better used reluctantly? Like minimizing the usage of the c-preprocessor. Currently, I do not use default-code but I would be fine with how it is as you described.
I briefly searched cb-source for default-code. The function that expands placeholders is in trunk/src/sdk/editormanager.cpp:495
--- Code: ---cbEditor* EditorManager::New(const wxString& newFileName)
{
// wxString old_title = Manager::Get()->GetAppWindow()->GetTitle(); // Fix for Bug #1389450
// create a dummy file
if (!newFileName.IsEmpty() && !wxFileExists(newFileName) && wxDirExists(wxPathOnly(newFileName)))
{
wxFile f(newFileName, wxFile::write);
if (!f.IsOpened())
return nullptr;
}
cbEditor* ed = new cbEditor(m_pNotebook, newFileName, m_Theme);
// if ((newFileName.IsEmpty() && !ed->SaveAs()) || !ed->Save())
// {
// //DeletePage(ed->GetPageIndex());
// ed->Destroy();
// Manager::Get()->GetAppWindow()->SetTitle(old_title); // Though I can't reproduce the bug, this does no harm
// return 0;
// }
// add default text
wxString key;
key.Printf(_T("/default_code/set%d"), (int)FileTypeOf(ed->GetFilename()));
wxString code = Manager::Get()->GetConfigManager(_T("editor"))->Read(key, wxEmptyString);
// Allow usage of macros
// TODO (Morten#5#): Is it worth making this configurable?!
Manager::Get()->GetMacrosManager()->ReplaceMacros(code);
ed->GetControl()->SetText(code);
ed->SetColourSet(m_Theme);
AddEditorBase(ed);
ed->Show(true);
SetActiveEditor(ed);
CodeBlocksEvent evt(cbEVT_EDITOR_OPEN, -1, nullptr, ed);
Manager::Get()->GetPluginManager()->NotifyPlugins(evt);
return ed;
}
--- End code ---
see the lines:
--- Code: --- // Allow usage of macros
// TODO (Morten#5#): Is it worth making this configurable?!
Manager::Get()->GetMacrosManager()->ReplaceMacros(code);
--- End code ---
Apart from that snippet, at first glance, I did not find in the source code any further rationale for the decision you asked for.
The code entered into the settings dialog can be found in ~/.config/codeblocks/default.con. Please search for default_code within that file.
Why do you want the creation date of a source file in the first place? I'd rather look up in version control when it was added. With that username, do you do that for legal reasons?
rechtsanwaltsteyer:
Thank you very much for the suggestions. In all the IDEs (Code::Blocks, KDevelop, and Qt Creator) i use, I have created some snippets/placeholders for different needs and a date snippet/placeholder to document the date of initial creation and subsequent versions in the source code header. Since I'm the only one working on the code, this allows me to avoid using Git and other version control systems.
Greatings Michael
FrankPeelo:
Hallo Georg
Just a comment -- I also did not use version control for private projects at home, but I have found you're much better off using one even there! I use Mercurial at home, even for typing up a song (I use mup from arkkra.com). Git is ok too, maybe a little harder when beginning. You don't need the repository to be anywhere other than in your work directory. You don't need to sync to a github or push to a remote repository or anything, or to be able to fork - although those features may be of use to you in the future. Just start with the basics, create a local repository and check in your changes. Just being able to see the differences in the file over time, and to put comments when you're checking in changes, is really useful. You're just way better off with any such tool.
Cheers
Frank
Navigation
[0] Message Index
Go to full version