Subscribe to 10 GOTO 10        RSS Feed
-----

Programmers Notepad Quotes

Icon Leave Comment
The following is a snippet of code in python for programmer's notepad:

###############################################################################
## 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()

0 Comments On This Entry

 

April 2019

S M T W T F S
 123456
78910111213
14151617181920
21 22 2324252627
282930    

Recent Entries

Search My Blog

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)