[Geany-Devel] Querying current file and cursor location

Lex Trotman elextr at gmail.com
Fri Jan 18 09:55:09 UTC 2013


On 18 January 2013 20:36, Thomas Young <thomasyoung at free.fr> wrote:
> Hmm.. not sure what happens if the filename is UTF-8.

DOC_FILENAME is always UTF-8.

>
> Basically, where some existing code (which is documented as supporting UTF-8
> filenames) was doing;
>
>                 filename = DOC_FILENAME(documents[i]);
>                 g_string_append(doc_list, filename);
>                 g_string_append_c(doc_list, '\n');
>
> I am doing instead:
>
>
>                 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\n", filename,
> line + 1, col);

And what if filename contains a : ?  Anyway it will be written in
UTF-8, you will have to handle locale encoding elsewhere maybe.

Cheers
Lex

>
>
>
> On 18/01/13 09:10, Thomas Young wrote:
>>
>> Cheers Steve.
>>
>> Ok, I changed spaces to tabs, and a patch from diff output is attached.
>> Will try and do things more properly next time!
>>
>> Thomas
>>
>> On 17/01/13 17:15, Steven Blatnick wrote:
>>>
>>> I'm new too, but the first time I submitted something, they took a patch
>>> I attached to an email sent to this mailing list.  Subsequent
>>> submissions, I signed up for a github account and forked geany and
>>> geany-plugins.  Using git hub, changes can be submitted through a "pull
>>> request".  I also signed up to SourceForge for submitting bugs.
>>>
>>> Here is where I read about the process:
>>> http://www.geany.org/Contribute/Developers
>>>
>>> So far I've found the people on this project have been helpful and
>>> friendly compared to my minor previous experiences with open source
>>> projects.
>>>
>>> Welcome :-)
>>>
>>> Steven Blatnick
>>>
>>>
>>> On 01/17/2013 06:17 AM, Thomas Young wrote:
>>>>
>>>> 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
>>>> _______________________________________________
>>>> Devel mailing list
>>>> Devel at lists.geany.org
>>>> https://lists.geany.org/cgi-bin/mailman/listinfo/devel
>>>
>>>
>>> _______________________________________________
>>> Devel mailing list
>>> Devel at lists.geany.org
>>> https://lists.geany.org/cgi-bin/mailman/listinfo/devel
>>>
>>
>>
>> _______________________________________________
>> Devel mailing list
>> Devel at lists.geany.org
>> https://lists.geany.org/cgi-bin/mailman/listinfo/devel
>>
> _______________________________________________
> Devel mailing list
> Devel at lists.geany.org
> https://lists.geany.org/cgi-bin/mailman/listinfo/devel


More information about the Devel mailing list