#545 automatically insert selection inside matching parens/quotes


11:05:15: This is Geany 0.21 (svn >= r5734).

Currently, when selecting some text and hitting '(' (and the 'auto-close quotes and brackets' option is activated), Geany will remove the selection and insert matching parens.

I think it would be more efficient if in such cases the selection would be inserted inside the matching items. If the user intended to replace the text, she will hit del/backspace before inserting the parens. Otherwise, it would make it much easier to enclose some random code within matching parens/quotes: (have the appropriate option activated and) select random code and insert a paren or quote. I am given to understand that this is how TextMate handles this.

What do you think?


  • Alex M

    Alex M - 2011-11-14

    I've written a small plugin that (kind of) lets you do that. The only problem is it requires you to press ctrl with the quote/bracket/whatever. I'll keep looking into how I can do it without pressing ctrl, but I suspect it will a bit more complicated.

    Let me know if you'd like the plug in as is and I'll attach it here.

  • landroni

    landroni - 2011-11-14

    Please attach your plugin here so that others could test (or inspect the code).


  • Alex M

    Alex M - 2011-11-14

    I've attached the code and plugin file. It's the first plugin I've written, so I imagine the code is of pretty poor quality...

    Also, it can only wrap text in parenthesis and single/double quotes. I'd have done square brackets too, but ctrl+[ already seems to do something (although I can't find that keybinding anywhere in Geany). Please let me know what should be changed, if this is even needed at all, etc.

  • Alex M

    Alex M - 2011-11-14

    Actually, I guess I can't attach files. Here's the code, there are compile instructions at the top - http://pastebin.com/u1rP2uRg

  • Alex M

    Alex M - 2011-11-15

    Sorry for triple posting, but I've got it working so you can just select text and type a quote, double quote, parenthesis, or square bracket to enclose the text - no ctrl needed. Code here - http://pastebin.com/549Dazj0

  • landroni

    landroni - 2011-11-15

    Thanks so much for working on this. You should be able to attach files if you click on 'Add a file'.

    However, it may be better to post your patch on geany-devel for review from real programmers (unfortunately not myself).

  • Alex M

    Alex M - 2011-11-20

    Alright, I posted this to geany-devel and got some feedback. They thought it would be more useful to have a number of different "wrap" character pairs which can be tied to keybindings. So for example, you could set '(' and ')' as the first wrap pair, bind the first wrap pair to ctrl+(, and then when you press that keybinding the selected text will be wrapped in '(' and ')'.

    So, that's what the plugin does now. It's a little small to be a plugin of its own so someone suggested adding it to the Addons plugin, but I'm not sure if/when/how that would happen. In the meantime, if you want to use it I've put it up here - https://github.com/pzoxiuv/Geany-Plugins.

    Also, I'll look into how feasible it would be to add an option allowing you to wrap text without keybindings (just by selecting text and hitting '(' or something), as that's what you originally wanted.

  • Nathan B

    Nathan B - 2011-11-26

    Thanks @pzoxicuv, this is great!

    My opinion is that this should be the default behavior for 'auto-close quotes and brackets', instead of as a plugin.
    I also don't think any extra configuration options are necessary - nobody would complain about it if they've already turned on the 'auto-close' feature. I think hard-coded completions for '', "", (), [], and {} would be fine.
    I also agree that the actual characters are much more appropriate triggers than 'Ctrl+<key>'.

    Thanks again!

  • Nobody/Anonymous


    I know it's been awhile, but I thought I should mention here that this feature has now been added to the Addons plugin, part of the geany-plugins project.



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks