giobauermeister / gedit-pair-char-autocomplete

Automatically exported from code.google.com/p/gedit-pair-char-autocomplete
1 stars 0 forks source link

Enhancement: Support enter inside parenthesis #2

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The stock gedit Bracket Completion plugin does two nice things that this plugin 
doesn't seem to. Would you consider adding these features? I'll post each one 
as a separate issue so you can track them separately.

Desired behaviour
If I type the open bracket then press enter, two new lines are inserted with 
the correct indentation, then the cursor is moved up one line.

To explain, I type open bracket, enter and I get this:
    {
    <- cursor is moved here
    }

This is really helpful for function declarations.

Original issue reported on code.google.com by callum.m...@gmail.com on 15 May 2011 at 8:17

GoogleCodeExporter commented 8 years ago
I've had a quick bash at modifying the code to do this. I'm not familiar with 
python and this is the first time I've ever worked with gedit plugins, so I'm 
sure the code could be improved radically. In my limited testing, it seems to 
work as I expected it to. Patch attached.

Original comment by callum.m...@gmail.com on 15 May 2011 at 9:26

Attachments:

GoogleCodeExporter commented 8 years ago
Nice job! I've integrated the patch into the main branch and created a new 
download. I'll have a look at the other issue whenever I get a chance. Thanks 
for the patch!

Original comment by kevin.mcguinness@gmail.com on 16 May 2011 at 10:26

GoogleCodeExporter commented 8 years ago
I think the patch could be improved a little, what do you think?

For example, I call self.get_char_under_cursor() twice. Would it be better to 
store that as a variable? I'd assumed so, but I wasn't sure if I could simply 
declare a new variable as in PHP, so I just used the function call twice.

Original comment by callum.m...@gmail.com on 16 May 2011 at 11:12

GoogleCodeExporter commented 8 years ago
Ok, I answered my own question, and created a second patch. Do you think this 
one is better than the first? I'm not very familiar with python / gedit, so it 
might be a minor change that's not worth the hassle.

Original comment by callum.m...@gmail.com on 16 May 2011 at 11:19

Attachments:

GoogleCodeExporter commented 8 years ago
Yep, that could be better alright -- although I don't think that 
get_char_under_cursor() is a very expensive operation. You don't need to 
declare variables in python, just assign them and then use them. So you could 
rewrite that part as:

cursor_ch = self.get_char_under_cursor(doc)
if (self.is_closing_paren(cursor_ch) and 
  self.would_balance_parens(doc, cursor_ch )):
  ...

That's a little more tidy actually :-) I've added you as a committer to the 
project anyway, so feel free to make changes to the main branch.

Original comment by kevin.mcguinness@gmail.com on 16 May 2011 at 11:24

GoogleCodeExporter commented 8 years ago
Heh, yeah, sorry.. replied before I read your next comment there. Yes, the 
second patch is a bit better. You can commit the changes to the default branch 
yourself if you like.

Original comment by kevin.mcguinness@gmail.com on 16 May 2011 at 11:26

GoogleCodeExporter commented 8 years ago
Ok, update committed. Another two firsts, first use of hg and first commit to 
Google Code. :-)

Original comment by callum.m...@gmail.com on 16 May 2011 at 11:58

GoogleCodeExporter commented 8 years ago
Good stuff, cheers!

Original comment by kevin.mcguinness@gmail.com on 16 May 2011 at 12:09