[Geany-Devel] Querying current file and cursor location
Thomas Young
thomasyoung at free.fr
Thu Jan 17 13:17:47 UTC 2013
Hello,
I've hacked a small change into Geany locally, to help with integration
with gdb.
Basically, what I've done is to add a '--print-location' command line
option, which essentially just duplicates the functionality of the
existing '--list-documents' option (through main.c/h and socket.c/h),
but with the actual string generation bit that corresponds to
build_document_list() changed to the following:
static gchar *build_location(void)
{
GString *location = g_string_new(NULL);
const gchar *filename;
gint pos, line, col;
GeanyDocument *doc = document_get_current();
if(doc)
{
filename = DOC_FILENAME(doc);
pos = sci_get_current_position(doc->editor->sci);
line = sci_get_line_from_position(doc->editor->sci, pos);
col = sci_get_col_from_position(doc->editor->sci, pos);
g_string_append_printf(location, "%s:%d:%d", filename, line + 1, col);
g_string_append_c(location, '\n');
}
return g_string_free(location, FALSE);
}
So what the overall change does then is basically to allow you to query
for the currently selected file, and current cursor location within that
file, from outside of geany, like so:
thomas at MS-7752 ~ $ geany --print-location
/home/thomas/Downloads/geany_git/src/socket.c:600:33
I can then use this in a python command within gdb (running completely
separately within a terminal) to set break points for positions selected
in files in Geany within having to actually type the whole filename and
line number bit each time.
This was based on the nightly build for January 17th, and seems to be
working correctly.
Should I submit a patch for this change?
If so, how?
(Not used to this whole open source malarky!)
I got the nightly build archive instead of using git, but I have copies
of the source archive both before and after the change.
Is it possible for this change (or something similar) to be included in
the Geany mainline?
Best regards,
Thomas
More information about the Devel
mailing list