Is there an auto-close curly brackets plugin for the Geany IDE?

7.3k views Asked by At

Geany is the closest thing I can find to the perfect web development IDE. However, I can't find a way to automatically close curly brackets ({).

For example, typing:

function test()
{

..and pressing RETURN should cause this to happen:

function test()
{
    // cursor ends up here (indented by 1 tab)
}

Is there anything that can make Geany do that?

5

There are 5 answers

4
Valor On

This is a native feature of Geany,

Go to Preferences, then Completions, down there you can choose which one you want to auto close.

Check here for screenshots

0
Ivan DImitrov On

You make something else: If you want, open https://plugins.geany.org/autoclose.html and see "autoclose" plugin. You can install with : sudo apt-get install geany-plugins-autoclose and It is all

0
Tanishk Tonk On

The Auto-close doesn't work if we place brackets inside another pair of brackets. For example, the inner bracket doesn't auto-close.{{|}

However, we can use the following snippet to create a block.

{={\n\t%cursor%\n}

But in order to use this snippet, we first have to include '{' char in our wordchars set by changing the below line in snippets.conf file.

wordchars=_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{
0
GingerPlusPlus On

That isn't full answer to your question, but may be helpful.

I have Geany not in english, I make translations of menu's fields on my own.

Geany has a feature: when you type special text and press Tab, the text is going to be replaced with another text.

It works by default for if, else, for, while, do, switch and try.

Configuration of this feature is in [Tools]/[Config files]/[snippets.conf].
After doing some changes, save file and click [Tools]/[Reload configuration].

I added two lines to section C++:

class=class %cursor%%block%;\n
struct=struct %cursor%%block%;\n

With block=\s{\n\t%cursor%\n}

It doesn't let you press { Enter or { Tab to get

{
    //cursor
}

because {=anything is ignored, I don't know why.

What you can do? You can have some another text, replaced using {\n\t%cursor%\n}, or define keybinding inserting it.

0
MIRMIX On

Geany can have user defined snippets. It is possible to open snippet configuration file from menu.

Tools ->
        Configuration files ->
                               snippets.conf

Go to the language block where you want to add that feature. For example:

  [C]
  if=if (%cursor%)%block_cursor%
  else=else%block_cursor%
  for=for (i = 0; i < %cursor%; i++)%block_cursor%
  while=while (%cursor%)%block_cursor%
  do=do\n{\n\t%cursor%\n} while (%cursor%)\n%cursor%
  switch=switch (%cursor%)%brace_open%case %cursor%:\n\t\t%cursor%\n\t\tbreak;\n\tdefault:\n\t\t%cursor%\n%brace_close%%cursor%

At first it can be thought that the problem can be fixed just with adding this line

 {=%\n{\n\t%cursor%\n}%

But Geany does not accept that when snippet is one non alphabetic character. It will work for any other alphabetic character like this

 b=%\n{\n\t%cursor%\n}% or  bl=%\n{\n\t%cursor%\n}%

However I dont think it is what you want. The real solution you can find from geanys menu.

 Edit
      ->Preferences
                    ->Editor
                            ->Completions 

Tick the Auto-close quotes and brackets then click on apply and saveenter image description here