Bug 466826 - Kdevelop Snippets ${date} etc are ignored
Summary: Kdevelop Snippets ${date} etc are ignored
Status: RESOLVED NOT A BUG
Alias: None
Product: kdevplatform
Classification: Developer tools
Component: templates (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-03-04 12:53 UTC by Georg Michael Steyer
Modified: 2023-03-13 08:34 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Georg Michael Steyer 2023-03-04 12:53:38 UTC
Dear developers,
unfortunately, I have a problem with Kdevelop 5.6.2 that I couldn't 
solve even after extensive online research. Probably "I can't see the 
forest for the trees"!
In all project templates that are relevant to me (cmake_plaincpp.tar.bz2 
and cmake_plainc.tar.bz2), I have added a header to the main.cpp. There 
and as a separate text module I would like to implement the date and 
time. Sorry, that is not possible. Neither %{date} nor ${date} expand to 
the current date after inclusion in the source code. If I try to use the 
online text module by Milian Wolf (see below), "%{year}" is not expanded 
to the current year (2023) in my source code (main.cpp). Here is his 
snippet:
/*
* This file is part of KDevelop
*
* Copyright %{year} Milian Wolff <mail@milianw.de>
*
* This program .... .

*/
My own template should look like /usr/share/kdevcodegen/licenses/GPL v3:
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <copyright holder>
by Attorney Georg Michael Steyer, Leverkusen
Created on <day>.<month>.<year>
Rev. 1.000.003 of <day>.<month>.<year>
This program...

But also here "<day>.<month>.<year>" are not expanded to the current date.
Comment 1 Igor Kushnir 2023-03-05 08:26:03 UTC
Maybe this date feature simply doesn't exist? I don't see anything date-related in the relevant code: https://invent.kde.org/kdevelop/kdevelop/-/blob/master/plugins/appwizard/appwizardplugin.cpp#L255
You can implement the feature yourself if you need it badly enough.
Comment 2 Igor Kushnir 2023-03-05 08:31:41 UTC
There *is* <year>, <month> and <day> support, but only in file templates, not app templates: https://invent.kde.org/kdevelop/kdevelop/-/blob/333b00441f10b8c4f8af35405d20338356fb14a9/plugins/filetemplates/licensepage.cpp#L242
Comment 3 Igor Kushnir 2023-03-13 08:34:19 UTC
Here is reformatted Milian's reply to the duplicate kdevelop-devel mailing list question:

That area is also a bit messy in KDevelop, and not something I use frequently 
myself. First of all, can you please be more specific what kind of template/
snippet you are using? We sadly have basically three different systems in 
place:

- new file template (#1)
- new project template (#2)
- text snippets to insert an open document (#3)

> * Copyright %{year} Milian Wolff <mail@milianw.de>
I assume here you are talking about the "snippets" plugin (#3), there the 
syntax would be:
${year()}
And you'll have to provide a javascript function like this in the `scripts` 
tab:
function year() { return new Date().getFullYear(); }

> My own template should look like /usr/share/kdevcodegen/licenses/GPL v3:
> Copyright (C) <year> <copyright holder>
> But also here "<day>.<month>.<year>" are not expanded to the current date.
For project templates (#2), we rely on grantlee which is similar to django in 
spirit. There, the syntax would be something like
{% now "yyyy" %}
if I'm not mistaken.
The `<year>` token is only replaced for file templates (#1).