"MirrorChar" by AllenDang
Rating:









(0 votes)
| Name: | MirrorChar |
|---|---|
| Uploaded By: | AllenDang |
| Date Created: | May 7, 2009 3:21 a.m. |
| Date Modified: | May 7, 2009 3:24 a.m. |
| Description: | Inserts right side bracket and quotation automatically. |
| Num Views: | 697 |
| Num Downloads: | 264 |
Contents
###############################################################################
## Inserts right side bracket and quotation automatically.
## By: Allen Dang
import pn, pypn.glue
import scintilla
from pypn.decorators import script
mirrorChars = ('\'', '"', '(', '[')
oldonCharAdded = pypn.glue.onCharAdded
def onCharAdded(c, doc):
""" Inserts right side bracket and quotation automatically. """
oldonCharAdded(c, doc)
editor = scintilla.Scintilla(pn.CurrentDoc())
if (c in mirrorChars):
pos = editor.CurrentPos
leftChar = editor.GetTextRange(pos - 2, pos - 1)
if (c == '\'' or c == '"'):
if (leftChar != c):
editor.AddText(1, c)
editor.CharLeft()
elif (c == '('):
editor.AddText(1, ')')
editor.CharLeft()
elif (c == '['):
editor.AddText(1, ']')
editor.CharLeft()
pypn.glue.onCharAdded = onCharAdded
How about including { as well?
mirrorChars = ('\'', '"', '(', '[', '{')
....
elif (c == '{'):
editor.AddText(1, '}')
editor.CharLeft()
Posted by sam on Feb. 28, 2010 at 7:37 a.m.