[Geany-devel] Adding auto-close brackets, braces and string

ioguix at free.fr ioguix at xxxxx
Tue Dec 2 05:03:36 UTC 2008


Hi,

Thanks for the feedback ! Your advices and tips are appreciated :)

On Sun, 30 Nov 2008, Enrico Tröger wrote:

> On Fri, 28 Nov 2008 05:55:25 +0100 (CET), ioguix at free.fr wrote:
>
>> Hi,
>>
>> First of all, thanks for this great piece of code that is Geany !
>>
>> Now, I would like to use auto-close brackets, brace and string in
>> Geany. As it doesn't looks very complicated, it could be a fairly easy
>> feature to implement for a first time contributor like me.
>>
>> So here is my proposal:
>> These options will auto-close ( [ { ' and " while typing, positionning
>> the cursor between the pair.
>> Nothing really revolutionar here as some IDE already implement that.
>> Moreover, it sounds this cannot be done using snippets and I can't
>> seriously think about doing a plugin for such a feature (I'm not even
>> sure it's fesable). So I believe it belongs to Geany's core.
>
> As long as it is configurable(i.e. I can disable it :D) I'm fine with
> this. We already have the basic code for this in Geany, even
> though it's only used for LaTeX right now.
> Check auto_close_bracket() in src/editor.c. Remove the check for the
> lexer == latex and add the missing characters (currently it only works
> for { and [.

Thanks for this info. I began to play with that, it looks to be the 
perfect place.

>> - where should I put the booleans options in the conf panel ?
>> "Editor" > "Completion" tab sounds obvious, what do you think about
>> that ?
>> - should I group brackets and braces, under the same checkbox and
>> [single-]quotes in an other one ?
>> - what about adding a "Typing" Section to group these options in the
>> completion tab ?
>
> Just put one checkbox in Editor->Completions, toggling the feature on
> and off.
> The easiest solution to make the completed characters configurable
> could be:
> Add a text field (GtkEntry) which holds all valid opening
> braces (and a single and double quote). The user can remove some of
> these to disable completion for those. The tooltip should make clear
> what can be entered and what not.
>
> But this is not the most user-friendly way, I think :).
>
> Alternatively, you could add a frame containing checkboxes for each of
> your suggested characters but for storage in the config file use a
> string containing the opening braces/brackets/... or an integer
> containing a bitmask to avoid having too many trivial settings.

I choosed the alternative :)
I added a "Auto-close brackets and quotes" frame in the "Completion" tab 
with 5 checkboxes for each ( { [ " '.

> Last note: if you edit the preferences dialog, please use Glade 2.10,
> newer versions generate code which is incompatible with GTK 2.6. If you
> can't use it, then just skip the GUI part of the prefs dialog, we will
> do this then.
Well, I already noticed that before mailing here and setted up a glade 
2.10 binary in my geany dev folder :)
After some mess with it (first time I'm using it), I finally managed to 
create to interface and connect everything to the conf file.
As you wished, the checkboxes states are saved in an integer so far.

One question: to keep the code readable, I used these macros to define the 
values:
#define AC_PARENTHESIS 1
#define AC_CBRACKET 2
#define AC_SBRACKET 4
#define AC_SQUOTE 8
#define AC_DQUOTE 16

What is your policy about that ? Is it ok or do you prefer to put values 
directly in the code ?

I hope I'll find time this week to finish everything...I have the feeling 
the "hardest" part is behind me ;)

-- 
Guillaume (ioguix) de Rorthais


More information about the Devel mailing list