Re: Templates/Snippets in KDevelop 5.6.2

Milian Wolff <[email protected]> Tue, 07 Mar 2023 09:41:19 +0100
Newsgroups gmane.comp.kde.devel.kdevelop
Message-ID <4015432.MHq7AAxBmi@agathemoarbauer>
On Mittwoch, 1. März 2023 10:58:31 CET Rechtsanwalt Georg Michael Steyer 
wrote:
> Dear developers,

Hey Georg.

> 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"!

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)

> 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:

...

> * Copyright %{year} Milian Wolff <[email protected]>

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).

HTH

-- 
Milian Wolff
http://milianw.de
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEezawi1aUvUGg3A1+8zYW/HGdOX8FAmQG+K8ACgkQ8zYW/HGd
OX+gTRAA0ElVvrNKCIZJNcCnU1gRNbBvi05BfRlKfXaBsLTrD4+o3UZS2WHssp5S
ohoIzLgeE3i6vV+ByMDQsuFwfU6fRMDd2VD8IvB18nlgnbiHb0XZyelRdvxTxs51
mOkmDmP2VU6W0+qtRNljv6hW6PSlPJnu79SYJlvEqsWgLAt5KPNCUHoPJuSY0G6s
6vXDArKWB2khdefnjye0NpKDybGSsKEznqjFJ9yj4YWLiPc26/7vaw+PcH0Tfpwm
EemRCAHhMZBp1GPhva2MVeAIDiOOgJeoo0ozGFORshkAcGWAreVBRMc6r7B7KLeA
29qnnRq3Z9MnEVTegpczrCjZI/6/qbIg66rT2VXPzBEPfzeaXdgP6plcPoXZPliS
rClKG1FRYsPVt9wCFdYtURnR0qtmt776gZouJpKVyKbi2yuQa6nd+WWA8+hZWHFs
GlYrnaay22HKrI+UpRM17FcITN4X+JoaFL7Pynqo961FNeAq+IqCnrpI15MxHKeY
WiBg8czURB8oOjd1hDgo5R2IE4jjW7jl84Z0Td0FnhpdbOL3kPkuLInMm3odWCSH
uNOirZnFoTIOYTCOe4b58HFuLufrXS/6nlvPgUYGjHUfIRP+CB4eBeaQORvhJsYQ
i5NwX/YePogU9o/Gusv6uakMjVl51fv+EPltpAsliYznR8opJds=
=yOCJ
-----END PGP SIGNATURE-----