Paranthesis closure in Geany for c++

143 Views Asked by At

After typing

int func(){

And pressing enter I'm getting like this , since I have enabled auto close plugin

 int func(){
      //cursor stays here }

But what i need is

int func(){
     //cursor stays here
   }

I'm able to achieve the required indentation by changing snippets.conf, but I have to press c and Tab, where

c=%brace_open%%cursor%%brace_close%
brace_open={\n\t
brace_close=\n}\n

Auto-close plugin settings:

Auto-close plugin settings

is there any other way of achieving ?? Thanks in advance.

2

There are 2 best solutions below

0
On

Check out https://plugins.geany.org/autoclose.html for autoclose plugin. This will solve your problem.

In Linux you can directly install it by sudo apt-get install geany-plugin-autoclose

1
On

I haven't been able to figure out how to get exactly what you've indicated, but the Autoclose plugin can get close. Typing int func(){ and pressing Enter gives the following, where the | character represents the cursor location:

int func(){
    |
}

EDIT:

My Autoclose settings are as shown below. But that turns out not to be the whole story. See after the image for more.

Autoclose Configure Plugins dialog

While looking into this some more, I discovered some strange behavior. I don't know if it's at the root of your problem or not, but it's maybe something to consider.

Autoclose worked as I described when pressing Enter on the main keyboard, but not when pressing Enter on the keypad, with or without NumLock enabled. In the latter case, I got the same result you did.

I normally use an antique IBM Model M keyboard, so to eliminate any chance of the problem being caused by the keyboard itself, I tried a modern USB keyboard with keypad. The results were exactly the same.

Having a suspicion as to what was happening, and since it's open source, I pulled down the Autoclose source code and took a look. And found...

static gboolean
auto_close_chars(
    AutocloseUserData *data,
    GdkEventKey       *event)
{
    ...
    else if (ch == GDK_Return)
    {
        return improve_indent(sci, editor, pos);
    }
    ...
}

A general search for GDK_Return turned up gdkkeysyms.h that defines all of the GDK key codes. In that, there's GDK_Return and also GDK_KP_Enter, where "KP" means "keypad". Since Autoclose doesn't recognize GDK_KP_Enter, it'll fail to respond to pressing Enter on the keypad.

So, if you're using a full keyboard with keypad, it should work ok so long as Enter on the main keyboard is being used. On the other hand, If you're using a laptop where there's only one Enter key, all bets are off.