I find that I tend to do a lot of search and replaces on quotes... Its a dumb thing that just sort of happens. You were thinking in the wrong language and typed a bunch of stuff using the wrong quotation marks. Or you past in some text and find that you need to escape a bunch of quotation marks. Sure you could use a search and replace but this can make the operation into 1 little script which you can assign to an keyboard shortcut:
escapeTools.py:
###############################################################################
## QuoteTools.py scripts -- Provides some quick access to regex operations on
## selected text. Specifically dealing with quotation marks.
## By: NickDMax
import pn
import scintilla
from pypn.decorators import script
@script("Escape quotes", "Text")
def EscapeQuotes():
""" Escape quotation marks within current selection """
doc = pn.CurrentDoc()
if doc is not None: #Lets try not to crash pn too often...
editor = scintilla.Scintilla(pn.CurrentDoc())
start = editor.SelectionStart
editor.BeginUndoAction()
editor.ReplaceAllInRange("\"", "\\\"", editor.SelectionStart, editor.SelectionEnd)
editor.SetSel(start, start)
editor.EndUndoAction()
@script("UnEscape quotes", "Text")
def UnEscapeQuotes():
""" Unescape quotation marks within current selection """
doc = pn.CurrentDoc()
if doc is not None: #Lets try not to crash pn too often...
editor = scintilla.Scintilla(pn.CurrentDoc())
start = editor.SelectionStart
editor.BeginUndoAction()
editor.ReplaceAllInRange("\\\"", "\"", editor.SelectionStart, editor.SelectionEnd)
editor.SetSel(start, start)
editor.EndUndoAction()
@script("Single2Double", "Text")
def Single2Double():
""" Converts single quotation marks to doubles within current selection """
doc = pn.CurrentDoc()
if doc is not None: #Lets try not to crash pn too often...
editor = scintilla.Scintilla(pn.CurrentDoc())
start = editor.SelectionStart
editor.BeginUndoAction()
editor.ReplaceAllInRange("\'", "\"", editor.SelectionStart, editor.SelectionEnd)
editor.SetSel(start, start)
editor.EndUndoAction()
@script("Double2Single", "Text")
def Double2Single():
""" Converts double quotation marks to singles within current selection """
doc = pn.CurrentDoc()
if doc is not None: #Lets try not to crash pn too often...
editor = scintilla.Scintilla(pn.CurrentDoc())
start = editor.SelectionStart
editor.BeginUndoAction()
editor.ReplaceAllInRange("\"", "\'", editor.SelectionStart, editor.SelectionEnd)
editor.SetSel(start, start)
editor.EndUndoAction()
@script("XML Escape", "Text")
def XMLEscape():
""" Preforms XML escapes for the current selection """
doc = pn.CurrentDoc()
if doc is not None: #Lets try not to crash pn too often...
editor = scintilla.Scintilla(pn.CurrentDoc())
start = editor.SelectionStart
editor.BeginUndoAction()
editor.ReplaceAllInRange("&", "&", editor.SelectionStart, editor.SelectionEnd)
editor.ReplaceAllInRange("\"", """, editor.SelectionStart, editor.SelectionEnd)
editor.ReplaceAllInRange("\'", "'", editor.SelectionStart, editor.SelectionEnd)
editor.ReplaceAllInRange("<", "<", editor.SelectionStart, editor.SelectionEnd)
editor.ReplaceAllInRange(">", ">", editor.SelectionStart, editor.SelectionEnd)
editor.SetSel(start, start)
editor.EndUndoAction()
@script("XML UnEscape", "Text")
def UNXMLEscape():
""" Unescape XML sequences in the current selection """
doc = pn.CurrentDoc()
if doc is not None: #Lets try not to crash pn too often...
editor = scintilla.Scintilla(pn.CurrentDoc())
start = editor.SelectionStart
editor.BeginUndoAction()
editor.ReplaceAllInRange(""", "\"", editor.SelectionStart, editor.SelectionEnd)
editor.ReplaceAllInRange("'", "\'", editor.SelectionStart, editor.SelectionEnd)
editor.ReplaceAllInRange("<", "<", editor.SelectionStart, editor.SelectionEnd)
editor.ReplaceAllInRange(">", ">", editor.SelectionStart, editor.SelectionEnd)
editor.ReplaceAllInRange("&", "&", editor.SelectionStart, editor.SelectionEnd)
editor.SetSel(start, start)
editor.EndUndoAction()