-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hi everyone,
I've started yesterday to write a (small) plugin to generate advanced documentation comments since I'm not pretty sure Geany's core is the right place. With advanced, I mean I would try to support Doxygen as well as GTK+ doc style, generate list of parameters automatically and so on.
But as you could know/see, finding well the start of the current function is not easy without reparsing all the file (which is not easy too and may be resource greedy). Then I thought that all the stuff I need to generate the doc comment for the current function appears in the tag panel. Moreover, the tag list would ease support of many languages… well, just no need to rewrite each parser. I've taken a look at what Geany does to generate doc comments, and it seems to use the symbol list; but it seems not accessible from plugins.
Then, I have some questions: * Is it possible to get tags for the current function, or at least function's start line, from inside a plugin? * Am I in the wrong way for anything? (is there a better way to get current function property; should I only improve Geany's functionality; …) And additionally: * Is there a way to add an item into the editor_popup=>insert_comments submenu from a plugin?
Thanks for spending time on reading me, Colomban
PS: Please excuse and tell me if I ask stupid questions.
On Mon, 23 Feb 2009 15:36:40 +0100, Colomban Wendling ban-ubuntu@club-internet.fr wrote:
Hey,
I've started yesterday to write a (small) plugin to generate advanced documentation comments since I'm not pretty sure Geany's core is the right place. With advanced, I mean I would try to support Doxygen as well as GTK+ doc style, generate list of parameters automatically and so on.
Sounds cool.
Then, I have some questions:
- Is it possible to get tags for the current function, or at least
function's start line, from inside a plugin?
Not directly. Without having tested, it should be possible to get the tag list for a document by using the 'tm_file' field of the GeanyDocument structure.
GeanyDocument *doc; TMWorkObject *tm_wo = doc->tm_file; GPtrArray *tags = tm_wo->tags_array;
This should give you an array of TMTag objects for the current file, then you can search this array for the corresponding TMTag object of the desired line in the document or function name or whatever. The above is untested but should work or at least should suffice as a start to get it working :).
- Am I in the wrong way for anything? (is there a better way to get
current function property; should I only improve Geany's functionality; …)
I'd say it depends on how heavy your improvements will go. It's probably best to first develop it as a plugin and then we can still think about integrating it into the core.
- Is there a way to add an item into the
editor_popup=>insert_comments submenu from a plugin?
For some example code, see src/scplugin.c and src/gui.c of the spellcheck plugin [1].
In plugin_init() just create your menu item and attach it to the menu. The pointer to the submenu item you want can be retrieved with:
ui_lookup_widget(geany->main_widgets->editor_menu, "comments");
Don't forget to destroy the create menu item(s) in plugin_cleanup().
In case you want show/hide/update the menu item when the editor menu is actually shown, you need to connect to the "update-editor-menu" signal.
[1] http://geany-plugins.svn.sourceforge.net/viewvc/geany-plugins/trunk/
Regards, Enrico
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hi, Sorry for the latency, I was busy these last days.
Then, I have some questions: * Is it possible to get tags for the current function, or at least function's start line, from inside a plugin?
Not directly. Without having tested, it should be possible to get the tag list for a document by using the 'tm_file' field of the GeanyDocument structure.
GeanyDocument *doc; TMWorkObject *tm_wo = doc->tm_file; GPtrArray *tags = tm_wo->tags_array;
This should give you an array of TMTag objects for the current file, then you can search this array for the corresponding TMTag object of the desired line in the document or function name or whatever. The above is untested but should work or at least should suffice as a start to get it working :).
Perfect, it works well :) But I need to update the tag list manually to generate correct documentation and insert it a the right place, but even if it can be found in the online API doc and in tm_source_file.[ch], tm_source_file_buffer_update() seems not usable from plugins (gets me an undefined symbol error). Is it normal? If yes, is there another way to update tag list dynamically?
The pointer to the submenu item you want can be retrieved with:
ui_lookup_widget(geany->main_widgets->editor_menu, "comments");
Don't forget to destroy the create menu item(s) in plugin_cleanup().
In case you want show/hide/update the menu item when the editor menu is actually shown, you need to connect to the "update-editor-menu" signal.
Thanks again, it's exactly what I was searching for. But again, a question: how can I know the click position that popuped the menu (and perhaps if it was popuped by a click and not a keyboard shortcut) to be able to generate the doc for the function below pointer and not at current position in the buffer?
Thanks a lot for support! Regards, Colomban
On Sat, 28 Feb 2009 19:21:36 +0100, Colomban wrote:
Hey,
Sorry for the latency, I was busy these last days.
Similar here :).
Then, I have some questions: * Is it possible to get tags for the current function, or at least function's start line, from inside a plugin?
Not directly. Without having tested, it should be possible to get the tag list for a document by using the 'tm_file' field of the GeanyDocument structure.
GeanyDocument *doc; TMWorkObject *tm_wo = doc->tm_file; GPtrArray *tags = tm_wo->tags_array;
This should give you an array of TMTag objects for the current file, then you can search this array for the corresponding TMTag object of the desired line in the document or function name or whatever. The above is untested but should work or at least should suffice as a start to get it working :).
Perfect, it works well :) But I need to update the tag list manually to generate correct documentation and insert it a the right place, but even if it can be found in the online API doc and in tm_source_file.[ch], tm_source_file_buffer_update() seems not usable from plugins (gets me
tm_source_file_buffer_update() is experimental to update the tags array from the current buffer in Geany, i.e. the displayed text instead of reading the file contents from a file. But this doesn't work at all yet and so is disabled. Additionally, this is not part of the plugin API and so you get an undefined symbol error. Simply ignore it.
Instead use tm_source_file_update() which should work ok but be aware that it reads the contents from the file on disk, so when the document in Geany has changes, you should save it first with document_save_file (). And at this point, tm_source_file_update() is already called after saving the document, so no need to call it manually.
The pointer to the submenu item you want can be retrieved with:
ui_lookup_widget(geany->main_widgets->editor_menu, "comments");
Don't forget to destroy the create menu item(s) in plugin_cleanup().
In case you want show/hide/update the menu item when the editor menu is actually shown, you need to connect to the "update-editor-menu" signal.
Thanks again, it's exactly what I was searching for. But again, a question: how can I know the click position that popuped the menu (and perhaps if it was popuped by a click and not a keyboard shortcut) to be able to generate the doc for the function below pointer and not at current position in the buffer?
The position where the menu was popped up is given in the "update-editor-menu" handler, check the 'pos' argument.
For key events, sci_get_current_position() should give you the correct position.
Regards, Enrico
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hi,
Enrico Tröger a écrit :
Perfect, it works well :) But I need to update the tag list manually to generate correct documentation and insert it a the right place, but even if it can be found in the online API doc and in tm_source_file.[ch], tm_source_file_buffer_update() seems not usable from plugins (gets me
tm_source_file_buffer_update() is experimental to update the tags array from the current buffer in Geany, i.e. the displayed text instead of reading the file contents from a file. But this doesn't work at all yet and so is disabled. Additionally, this is not part of the plugin API and so you get an undefined symbol error. Simply ignore it.
Instead use tm_source_file_update() which should work ok but be aware that it reads the contents from the file on disk, so when the document in Geany has changes, you should save it first with document_save_file (). And at this point, tm_source_file_update() is already called after saving the document, so no need to call it manually.
OK. But isn't it possible to at least emulate tm_source_file_buffer_update() by i.e. writing given buffer to a temporary file and updating current document's tags with newly parsed ones? 'Cause I think it is a little ill to force saving of the file only for updating tags. I know my proposal wouldn't have gains of memory parsing (no need to write/read file) but it should work as a temporary workaround, if I miss nothing. What do you think?
But yes, by saving the document it works well regardless my above words.
Thanks again, it's exactly what I was searching for. But again, a question: how can I know the click position that popuped the menu (and perhaps if it was popuped by a click and not a keyboard shortcut) to be able to generate the doc for the function below pointer and not at current position in the buffer?
The position where the menu was popped up is given in the "update-editor-menu" handler, check the 'pos' argument.
Thanks, I'll take a look at it.
Regards, Colomban
On Tue, 03 Mar 2009 20:13:50 +0100, Colomban wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hi,
Enrico Tröger a écrit :
Perfect, it works well :) But I need to update the tag list manually to generate correct documentation and insert it a the right place, but even if it can be found in the online API doc and in tm_source_file.[ch], tm_source_file_buffer_update() seems not usable from plugins (gets me
tm_source_file_buffer_update() is experimental to update the tags array from the current buffer in Geany, i.e. the displayed text instead of reading the file contents from a file. But this doesn't work at all yet and so is disabled. Additionally, this is not part of the plugin API and so you get an undefined symbol error. Simply ignore it.
Instead use tm_source_file_update() which should work ok but be aware that it reads the contents from the file on disk, so when the document in Geany has changes, you should save it first with document_save_file (). And at this point, tm_source_file_update() is already called after saving the document, so no need to call it manually.
OK. But isn't it possible to at least emulate tm_source_file_buffer_update() by i.e. writing given buffer to a temporary file and updating current document's tags with newly parsed ones? 'Cause I think it is a little ill to force saving of the file only for updating tags. I know my proposal wouldn't have gains of memory parsing (no need to write/read file) but it should work as a temporary workaround, if I miss nothing. What do you think?
Theoretically possible but doesn't make much sense in practise. To do what you want, you would have to create a temporary file, write the current editor's content in it, then create a TMSourceFile for this temporary file, update it, read its tags and delete everything again.
Possible but seems kind of weird to me.
Regards, Enrico