On 04/14/2010 01:56 PM, Colomban Wendling wrote:
Hi Jordan,
jordan a écrit :
I'm trying to write a plug-in that among other things adds a function header. Unfortunately this is also my first C program so it has been more of a learning experience then anything, but I'm finally at the point where it sort of works.
What does your plugin, apart adding a function header? I'm curious. And hum, I'm working on something similar to this part: a "generic" documentation generator [1].
Currently just function header, but as I figure things out I'd like to do a function generator as well, that would in turn call the header generator if that was selected. Currently it works for the most part if the defiinition is on a single line. It displays a dialog with the method name, and labels and GtkEntrys to enter a description for the method and if applicable any parameters, and return value.
Currently my plug-in reads the current line and breaks it down, however it's my understanding that some C programmers may break a function definition over several lines, in which case my plug-in would not work properly.
Yes. Many programmers (I'm of these) breaks function definition in multiple line, actually I do something like this:
return_type function_name (type arg1, type arg2, ...)
…and of course it is a little harder to naively parse (not so much in facts, but doesn't allow what you do).
I would also like to make it so the function definition for whatever the current function is would be used.
So this brings me to my questions, is there an easy way to determine if the current position in the editor is part of a function or not? If so is there an easy way to get the function definition? If not could someone maybe point me to some tutorials about parsing text in c.
As Enzo said, there is the scope to determine if a particular line is part of a function or not, but its is not supported by every tag generator used by Geany. What I personally chose was to walk the tag list and find the tag closest to the current line. Tweaking this way a bit gives quite good results.
And for the function definition, see the tag list, there is everything you probably want (or almost). One missing thing is the argument list – I personally chose to fix this with a regular expression, but there might be better solutions; for example if hard-coded things are acceptable, a custom argument parser is a somewhat easy task.
How do I access the scope, or this tag list you speak of, I noticed nothing like that in plug-in api documentation?
Also currently the header that is generated by my plug-in c style multi line hard coded, and I was wondering if at some time more of the methods in templates.c would be opened up to the API?
I don't know exactly your goals, but Geany's templates are not complete. if I'm right: they are very simple, which is good, but doesn't support things like loops and so (as far as I know, tell me if I'm wrong). Since I didn't find any template parser in C, I written my own [2] for the needs of the plugin I write. It is heavily more complex, but OTOH more powerful… choice is not easy, is it? :D If you're interested, feel free to use it.
I was only thinking templates so that coding styles would be easy to enforce, by easily allowing the user to change the style of the header.
Regards, Colomban
[1] no it's not dead, you'll see soon (for those who understand ^^) [2] http://ctpl.tuxfamily.org/ ; but if you're interested, wait for the upcoming 0.2 release that will be somewhat different in its API. It's almost ready and can be found in the git master. _______________________________________________ Geany-devel mailing list Geany-devel@uvena.de http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel