hi guys! i've recently switched to geany from cdt (eclipse plugin for c/c++). when you create a new header file in cdt it's default content is like below:
#ifndef SOMEHEADER_H_ #define SOMEHEADER_H_
#endif /*SOMEHEADER_H_*/
where SOMEHEADER is the name of the file. Can you tell me how can i make it in geany? I have created a template and put it into ~/.geany/templates but geany doesn't seem to see it even after restart. my template has this content:
#ifndef {filename} #define {filename}
#endif /*{filename}*/
but filename is not what i need. I got stuck at this point. Need your help.
On Tue, 04 Nov 2008 15:24:05 +0200, jay jay.27182818@gmail.com wrote:
Hi Jay,
sorry for the late answer.
hi guys! i've recently switched to geany from cdt (eclipse plugin for c/c++). when you create a new header file in cdt it's default content is like below:
#ifndef SOMEHEADER_H_ #define SOMEHEADER_H_
#endif /*SOMEHEADER_H_*/
where SOMEHEADER is the name of the file. Can you tell me how can i make it in geany? I have created a template and put it into ~/.geany/templates but geany doesn't seem to see it even after restart. my template has this content:
#ifndef {filename} #define {filename}
#endif /*{filename}*/
but filename is not what i need. I got stuck at this point. Need your help.
Unfortunately, most of the wildcards (to be more specific: all except {fileheader}) are not replaced for custom file templates. I just changed this in the SVN version so that the other wildcards can be used, too. So, also {filename} will now be replaced.
But this still doesn't help you because when you create a new document from a fle template, Geany will name this document 'untitled.xxx' where xxx is the extension of the template file.
So, even if you would use something like
ifndef {filename} define {filename}
endif /*{filename}*/
would result in
#ifndef untitled.h #define untitled.h
#endif /*untitled.h*/
The problem is that you want to have the final filename in the document after you initially saved it to disk. But at this point Geany doesn't know anything anymore about the template.
I don't think we should do anything about this in Geany itself. But it should be possible and reasonable to do this for a plugin, maybe with some other useful additions to the template system. If anyone wants to work on this, feel free to do so and to ask for help.
Regards, Enrico
On Mon, 2008-11-10 at 20:01 +0100, Enrico Tröger wrote:
On Tue, 04 Nov 2008 15:24:05 +0200, jay jay.27182818@gmail.com wrote:
Hi Jay,
sorry for the late answer.
hi guys! i've recently switched to geany from cdt (eclipse plugin for c/c++). when you create a new header file in cdt it's default content is like below:
#ifndef SOMEHEADER_H_ #define SOMEHEADER_H_
#endif /*SOMEHEADER_H_*/
where SOMEHEADER is the name of the file. Can you tell me how can i make it in geany? I have created a template and put it into ~/.geany/templates but geany doesn't seem to see it even after restart. my template has this content:
#ifndef {filename} #define {filename}
#endif /*{filename}*/
but filename is not what i need. I got stuck at this point. Need your help.
Unfortunately, most of the wildcards (to be more specific: all except {fileheader}) are not replaced for custom file templates. I just changed this in the SVN version so that the other wildcards can be used, too. So, also {filename} will now be replaced.
But this still doesn't help you because when you create a new document from a fle template, Geany will name this document 'untitled.xxx' where xxx is the extension of the template file.
So, even if you would use something like
ifndef {filename} define {filename}
endif /*{filename}*/
would result in
#ifndef untitled.h #define untitled.h
#endif /*untitled.h*/
The problem is that you want to have the final filename in the document after you initially saved it to disk. But at this point Geany doesn't know anything anymore about the template.
I don't think we should do anything about this in Geany itself. But it should be possible and reasonable to do this for a plugin, maybe with some other useful additions to the template system. If anyone wants to work on this, feel free to do so and to ask for help.
Regards, Enrico
Geany mailing list Geany@uvena.de http://lists.uvena.de/cgi-bin/mailman/listinfo/geany
Hi Enrico,
thanks for reply. it would be great to move all template related stuff into a plugin. most ide's like eclipse or netbeans or even vs first ask user to select a template and then to specify a name for the new file. if i'm not mistaken eclipse cdt can create unnamed files the same way geany does but in such cases it doesn't use any templates. so geany is just missing asking for a filename. It'd be nice if you make it possible for plugins to intercept menu actions like file creation or saving - it will make it easy to store all template related code in a plugin that would handle creating new files.
Jay
On Mon, 10 Nov 2008 21:55:11 +0200, jay jay.27182818@gmail.com wrote:
Hey,
thanks for reply. it would be great to move all template related stuff into a plugin. most ide's like eclipse or netbeans or even vs first ask user to select a template and then to specify a name for the new file. if i'm not mistaken eclipse cdt can create unnamed files the same way geany does but in such cases it doesn't use any templates. so geany is just missing asking for a filename. It'd be nice if you make it
Yes, Geany asks first for the filename when the file is actually to be saved, not when creating. I like it this way as it makes creating files more easy and fast.
possible for plugins to intercept menu actions like file creation or saving - it will make it easy to store all template related code in a plugin that would handle creating new files.
To some extend, this is already possible. There are plugin signals emitted when a document is created, opened, saved and closed. Hwoever, except for closed, these signals are emitted after the corresponding action. But this might be still enough for a template plugin to add the desired functionality. Feel free to work on this, if any API changes/additions needed, just tell us about and we'll see how we can solve it.
Regards, Enrico
On Mon, 10 Nov 2008 21:17:48 +0100 Enrico Tröger enrico.troeger@uvena.de wrote:
thanks for reply. it would be great to move all template related stuff into a plugin. most ide's like eclipse or netbeans or even vs first ask user to select a template and then to specify a name for the new file. if i'm not mistaken eclipse cdt can create unnamed files the same way geany does but in such cases it doesn't use any templates. so geany is just missing asking for a filename. It'd be nice if you make it
Yes, Geany asks first for the filename when the file is actually to be saved, not when creating. I like it this way as it makes creating files more easy and fast.
One idea: maybe when using New with Template and the template uses {filename}, Geany could flag this in a private document field, and not transform it until the file is saved. On saving, Geany could check if the 'replace_template_filename' field is set, and replace all instances of {filename} with the proper filename.
Regards, Nick
On Wed, 2008-11-12 at 12:34 +0000, Nick Treleaven wrote:
One idea: maybe when using New with Template and the template uses {filename}, Geany could flag this in a private document field, and not transform it until the file is saved. On saving, Geany could check if the 'replace_template_filename' field is set, and replace all instances of {filename} with the proper filename.
maybe geany could use some default name such as 'noname.ext' before a document is actually created. On saving it could use the template as a regular expression and locate the string 'noname.ext' and replace it with the actual value.
Jay
On Wed, 12 Nov 2008 12:34:59 +0000, Nick Treleaven nick.treleaven@btinternet.com wrote:
On Mon, 10 Nov 2008 21:17:48 +0100 Enrico Tröger enrico.troeger@uvena.de wrote:
thanks for reply. it would be great to move all template related stuff into a plugin. most ide's like eclipse or netbeans or even vs first ask user to select a template and then to specify a name for the new file. if i'm not mistaken eclipse cdt can create unnamed files the same way geany does but in such cases it doesn't use any templates. so geany is just missing asking for a filename. It'd be nice if you make it
Yes, Geany asks first for the filename when the file is actually to be saved, not when creating. I like it this way as it makes creating files more easy and fast.
One idea: maybe when using New with Template and the template uses {filename}, Geany could flag this in a private document field, and not transform it until the file is saved. On saving, Geany could check if the 'replace_template_filename' field is set, and replace all instances of {filename} with the proper filename.
This still won't solve the problem of replacing {filename} with HEADERFILE_H. But maybe we could add another wildcard like {FILENAME} which will replace the filename with an uppercase variant.
Maybe we don't need an additional flag at all when we extend the existing code in replace_header_filename() (document.c) to work on the whole file, not only the first three lines.
But I'd still like to have all this done in a plugin in some way. Either a new one or by extending the classbuilder plugin to be more flexible.
Regards, Enrico
Sorry for the late reply.
On Wed, 12 Nov 2008 21:08:37 +0100 Enrico Tröger enrico.troeger@uvena.de wrote:
One idea: maybe when using New with Template and the template uses {filename}, Geany could flag this in a private document field, and not transform it until the file is saved. On saving, Geany could check if the 'replace_template_filename' field is set, and replace all instances of {filename} with the proper filename.
This still won't solve the problem of replacing {filename} with HEADERFILE_H. But maybe we could add another wildcard like {FILENAME} which will replace the filename with an uppercase variant.
Yes, it would need something like {BASENAME}_H.
Maybe we don't need an additional flag at all when we extend the existing code in replace_header_filename() (document.c) to work on the whole file, not only the first three lines.
The problem is to avoid false positives - having a flag when using new with template reduces the problem of unwanted replacements, at least when saving a file not created with a file template.
But I think there could be a wider issue with templates - e.g. what if someone wants a {filename} string to appear in their template file and not be replaced? Using any kind of escaping for all braces e.g. {} would be annoying. So maybe a solution is to make template markers more unusual, e.g. %?filename?%.
But I'd still like to have all this done in a plugin in some way. Either a new one or by extending the classbuilder plugin to be more flexible.
Well, as Lex said it would be strange to use a plugin for C/C++ header file templates and normal New with Template file templates for all other files.
Regards, Nick
On Thu, 20 Nov 2008 18:41:23 +0000, Nick Treleaven nick.treleaven@btinternet.com wrote:
Maybe we don't need an additional flag at all when we extend the existing code in replace_header_filename() (document.c) to work on the whole file, not only the first three lines.
The problem is to avoid false positives - having a flag when using new with template reduces the problem of unwanted replacements, at least when saving a file not created with a file template.
But I think there could be a wider issue with templates - e.g. what if someone wants a {filename} string to appear in their template file and not be replaced? Using any kind of escaping for all braces e.g. {} would be annoying. So maybe a solution is to make template markers more unusual, e.g. %?filename?%.
It depends how urgent is the case someone really wants "{filename}" not to be replaced. Furthermore, all templates are editable and each {filename} occurrence (or whatever wildcard) can be removed. I personally find using something like %?filename?% much more annoying and it would break any existing user-modified templates.
The last resort would be to make the wildcards configurable. But this I really don't want to have in the core, this should be done in a plugin.
But I'd still like to have all this done in a plugin in some way. Either a new one or by extending the classbuilder plugin to be more flexible.
Well, as Lex said it would be strange to use a plugin for C/C++ header file templates and normal New with Template file templates for all other files.
I didn't mean to use a plugin for special C/C++ header stuff. Either we move most things of the template code into a plugin so that using such a plugin is more reasonable. Or we just add {BASENAME} as a template. This could work as long until someone else requests another fancy template feature.
Regards, Enrico
On Fri, 21 Nov 2008 15:51:02 +0100 Enrico Tröger enrico.troeger@uvena.de wrote:
But I think there could be a wider issue with templates - e.g. what if someone wants a {filename} string to appear in their template file and not be replaced? Using any kind of escaping for all braces e.g. {} would be annoying. So maybe a solution is to make template markers more unusual, e.g. %?filename?%.
It depends how urgent is the case someone really wants "{filename}" not to be replaced.
Maybe it won't be much of a problem, who knows.
Furthermore, all templates are editable and each {filename} occurrence (or whatever wildcard) can be removed.
(Not sure what you meant by this - I was talking about when the user has made a template that contains that string and wants to keep it, instead of having it replaced.)
I personally find using something like %?filename?% much more annoying and it would break any existing user-modified templates.
Yes, so if it doesn't affect people much just keep the current syntax.
Well, as Lex said it would be strange to use a plugin for C/C++ header file templates and normal New with Template file templates for all other files.
I didn't mean to use a plugin for special C/C++ header stuff. Either we move most things of the template code into a plugin so that using such a plugin is more reasonable.
OK, maybe.
Or we just add {BASENAME} as a template. This could work as long until someone else requests another fancy template feature.
Heh, and maybe it should be {c_header_string} or something so that chars like '-' get replaced with underscores.
Regards, Nick
On Mon, 24 Nov 2008 16:16:06 +0000, Nick Treleaven nick.treleaven@btinternet.com wrote:
On Fri, 21 Nov 2008 15:51:02 +0100 Enrico Tröger enrico.troeger@uvena.de wrote:
But I think there could be a wider issue with templates - e.g. what if someone wants a {filename} string to appear in their template file and not be replaced? Using any kind of escaping for all braces e.g. {} would be annoying. So maybe a solution is to make template markers more unusual, e.g. %?filename?%.
It depends how urgent is the case someone really wants "{filename}" not to be replaced.
Maybe it won't be much of a problem, who knows.
Furthermore, all templates are editable and each {filename} occurrence (or whatever wildcard) can be removed.
(Not sure what you meant by this - I was talking about when the user has made a template that contains that string and wants to keep it, instead of having it replaced.)
Hmm, so using two wildcard formats? One to be replaced on file creation and to be replaced when saving the file?
Or we just add {BASENAME} as a template. This could work as long until someone else requests another fancy template feature.
Heh, and maybe it should be {c_header_string} or something so that chars like '-' get replaced with underscores.
Yeah and two months one comes and want somthing similar for Java or whatever and wants to get it replaced using CamelCase and yet another one wants it to be all lowercase or whatever. Anyway, to solve this for now, we could add {BASENAME} or {c_header_string} or something like this.
Regards, Enrico
On Thu, 27 Nov 2008 19:52:17 +0100 Enrico Tröger enrico.troeger@uvena.de wrote:
Furthermore, all templates are editable and each {filename} occurrence (or whatever wildcard) can be removed.
(Not sure what you meant by this - I was talking about when the user has made a template that contains that string and wants to keep it, instead of having it replaced.)
Hmm, so using two wildcard formats? One to be replaced on file creation and to be replaced when saving the file?
No, just one format. Maybe in practice it's unlikely that {filename} would be in a template anyway.
Or we just add {BASENAME} as a template. This could work as long until someone else requests another fancy template feature.
Heh, and maybe it should be {c_header_string} or something so that chars like '-' get replaced with underscores.
Yeah and two months one comes and want somthing similar for Java or whatever and wants to get it replaced using CamelCase and yet another one wants it to be all lowercase or whatever. Anyway, to solve this for now, we could add {BASENAME} or {c_header_string} or something like this.
OK.
Regards, Nick
2008/11/11 Enrico Tröger enrico.troeger@uvena.de
On Tue, 04 Nov 2008 15:24:05 +0200, jay jay.27182818@gmail.com wrote:
Hi Jay,
sorry for the late answer.
hi guys! i've recently switched to geany from cdt (eclipse plugin for c/c++). when you create a new header file in cdt it's default content is like below:
#ifndef SOMEHEADER_H_ #define SOMEHEADER_H_
#endif /*SOMEHEADER_H_*/
where SOMEHEADER is the name of the file. Can you tell me how can i make it in geany? I have created a template and put it into ~/.geany/templates but geany doesn't seem to see it even after restart. my template has this content:
#ifndef {filename} #define {filename}
#endif /*{filename}*/
but filename is not what i need. I got stuck at this point. Need your help.
Unfortunately, most of the wildcards (to be more specific: all except {fileheader}) are not replaced for custom file templates. I just changed this in the SVN version so that the other wildcards can be used, too. So, also {filename} will now be replaced.
But this still doesn't help you because when you create a new document from a fle template, Geany will name this document 'untitled.xxx' where xxx is the extension of the template file.
So, even if you would use something like
ifndef {filename} define {filename}
endif /*{filename}*/
would result in
#ifndef untitled.h #define untitled.h
#endif /*untitled.h*/
The problem is that you want to have the final filename in the document after you initially saved it to disk. But at this point Geany doesn't know anything anymore about the template.
Perhaps in the meantime Jay could use a snippet and insert it after saving the file. e.g.defining in section [C] in your snippets.conf hguard=#ifndef HAVE_{filename}\n#define HAVE_{filename}\n\n#endif
This still requires editing the result as it will contain a dot (.h) which isn't allowed in identifiers but it is part way there. Perhaps adding an extra substitute thats equivalent of %e in the make commands would be an easy fix?
I don't think we should do anything about this in Geany itself. But it should be possible and reasonable to do this for a plugin, maybe with some other useful additions to the template system. If anyone wants to work on this, feel free to do so and to ask for help.
Regards, Enrico
-- Get my GPG key from http://www.uvena.de/pub.asc
Geany mailing list Geany@uvena.de http://lists.uvena.de/cgi-bin/mailman/listinfo/geany
On Tue, 11 Nov 2008 10:34:54 +1100, "Lex Trotman" elextr@gmail.com wrote:
2008/11/11 Enrico Tröger enrico.troeger@uvena.de
On Tue, 04 Nov 2008 15:24:05 +0200, jay jay.27182818@gmail.com wrote:
Hi Jay,
sorry for the late answer.
hi guys! i've recently switched to geany from cdt (eclipse plugin for c/c++). when you create a new header file in cdt it's default content is like below:
#ifndef SOMEHEADER_H_ #define SOMEHEADER_H_
#endif /*SOMEHEADER_H_*/
where SOMEHEADER is the name of the file. Can you tell me how can i make it in geany? I have created a template and put it into ~/.geany/templates but geany doesn't seem to see it even after restart. my template has this content:
#ifndef {filename} #define {filename}
#endif /*{filename}*/
but filename is not what i need. I got stuck at this point. Need your help.
Unfortunately, most of the wildcards (to be more specific: all except {fileheader}) are not replaced for custom file templates. I just changed this in the SVN version so that the other wildcards can be used, too. So, also {filename} will now be replaced.
But this still doesn't help you because when you create a new document from a fle template, Geany will name this document 'untitled.xxx' where xxx is the extension of the template file.
So, even if you would use something like
ifndef {filename} define {filename}
endif /*{filename}*/
would result in
#ifndef untitled.h #define untitled.h
#endif /*untitled.h*/
The problem is that you want to have the final filename in the document after you initially saved it to disk. But at this point Geany doesn't know anything anymore about the template.
Perhaps in the meantime Jay could use a snippet and insert it after saving the file.
In the meantime? This is not going to change unless someone writes a plugin.
e.g.defining in section [C] in your snippets.conf hguard=#ifndef HAVE_{filename}\n#define HAVE_{filename}\n\n#endif
This still requires editing the result as it will contain a dot (.h) which isn't allowed in identifiers but it is part way there. Perhaps adding an extra substitute thats equivalent of %e in the make commands would be an easy fix?
Maybe the classbuilder plugin might help you. It does create header files with appropriate header guards. Just check it out.
Regards, Enrico