Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 3rd, 2012  |  syntax: None  |  size: 1.12 KB  |  views: 129  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import geany
  2.  
  3. class AutoCloseBracketPlugin(geany.Plugin):
  4.  
  5.         __plugin_name__ = "Auto Close Bracket Plugin"
  6.         __plugin_version__ = "0.01"
  7.         __plugin_description__ = "Inserts the close bracket automatically in a context sensitive way."
  8.         __plugin_author__ = "Francesco Pasqua <cesconix87@gmail.com>"
  9.  
  10.         bracket = {
  11.                 '{' : '}',
  12.                 '[' : ']',
  13.                 '(' : ')'
  14.         }
  15.         openedBracket = bracket.keys()
  16.         closedBracket = bracket.values()
  17.  
  18.         sci = None # ScintillaObject
  19.  
  20.         def __init__(self):
  21.                 geany.Plugin.__init__(self)
  22.                 geany.signals.connect("editor-notify", self.onEditorNotify)
  23.  
  24.         def onEditorNotify(self, obj, editor, nt):
  25.                 self.sci = editor.scintilla
  26.                 if nt.nmhdr.code == 2001: # modify: SCN_CARHADDED
  27.                         self.onCharAdded(nt.ch)
  28.  
  29.         def onCharAdded(self, char):
  30.                 if char in self.openedBracket:
  31.                         self.onOpenedBracket(char)
  32.                 if char in self.closedBracket:
  33.                         self.onClosedBracket(char)
  34.  
  35.         def onOpenedBracket(self, char):
  36.                 self.sci.insert_text(self.bracket[char])
  37.  
  38.         def onClosedBracket(self, char):
  39.                 currentPosition = self.sci.get_current_position()
  40.                 if (char == self.sci.get_char_at(currentPosition)):
  41.                         print dir(self.sci)
  42.                         self.sci.send_command('')
clone this paste RAW Paste Data