"""
TODO: What kind of syntax is handled in the Preview "language" type? Raw?
"""

import keyword

import wx
import wx.stc as stc

if wx.Platform == '__WXMSW__':
    faces = { 'times': 'Times New Roman',
              'mono' : 'Courier New',
              'helv' : 'Arial',
              'other': 'Comic Sans MS',
              'size' : 10,
              'size2': 8,
             }
elif wx.Platform == '__WXMAC__':
    faces = { 'times': 'Times New Roman',
              'mono' : 'Monaco',
              'helv' : 'Arial',
              'other': 'Comic Sans MS',
              'size' : 12,
              'size2': 10,
             }
else:
    faces = { 'times': 'Times',
              'mono' : 'Courier',
              'helv' : 'Helvetica',
              'other': 'new century schoolbook',
              'size' : 12,
              'size2': 10,
             }

class StyledTextCtrl(stc.StyledTextCtrl):
    """docstring for StyledTextCtrl"""
    fold_symbols = 2

    def __init__(self, parent, ID, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0):
        stc.StyledTextCtrl.__init__(self, parent, ID, pos, size, style)
    

    def Lexer(self, lexer):
        # Non-namespace method
        if lexer == 'python':
            self.__Python__()

        elif lexer == 'C++':
            self.__Cpp__()
        
        elif lexer == 'XRC':
            self.__XRC__()
        
        elif lexer == 'lisp':
            self.__Lisp__()
        
        elif lexer == 'perl':
            self.__Perl__()

        elif lexer == 'preview': # Raw code?
            self.__Preview__()

    def __Python__(self):
        self.SetLexer(stc.STC_LEX_PYTHON)
        self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
        self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT)

        self.SetLexer(stc.STC_LEX_PYTHON)
        self.SetKeyWords(0, " ".join(keyword.kwlist))

        self.SetProperty("fold", "1")
        self.SetProperty("tab.timmy.whinge.level", "1")
        self.SetMargins(0,0)

        self.SetViewWhiteSpace(False)
        # self.SetBufferedDraw(False)
        # self.SetViewEOL(True)
        # self.SetEOLMode(stc.STC_EOL_CRLF)
        # self.SetUseAntiAliasing(True)

        self.SetEdgeMode(stc.STC_EDGE_BACKGROUND)
        self.SetEdgeColumn(78)

        # Setup a margin to hold fold markers
        # self.SetFoldFlags(16)  ###  WHAT IS THIS VALUE?  WHAT ARE THE OTHER FLAGS?  DOES IT MATTER?
        
        self.SetMarginType(1, stc.STC_MARGIN_NUMBER)
        self.SetMarginMask(1, 0)
        self.SetMarginWidth(1, 20)
        self.SetMarginSensitive(2, True)

        if self.fold_symbols == 0:
            # Arrow pointing right for contracted folders, arrow pointing down for expanded
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_ARROWDOWN, "black", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_ARROW, "black", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_EMPTY, "black", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_EMPTY, "black", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_EMPTY,     "white", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY,     "white", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY,     "white", "black")

        elif self.fold_symbols == 1:
            # Plus for contracted folders, minus for expanded
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_MINUS, "white", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_PLUS,  "white", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_EMPTY, "white", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_EMPTY, "white", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_EMPTY, "white", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black")

        elif self.fold_symbols == 2:
            # Like a flattened tree control using circular headers and curved joins
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_CIRCLEMINUS,          "white", "#404040")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_CIRCLEPLUS,           "white", "#404040")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_VLINE,                "white", "#404040")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_LCORNERCURVE,         "white", "#404040")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_CIRCLEPLUSCONNECTED,  "white", "#404040")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_CIRCLEMINUSCONNECTED, "white", "#404040")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNERCURVE,         "white", "#404040")

        elif self.fold_symbols == 3:
            # Like a flattened tree control using square headers
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_BOXMINUS,          "white", "#808080")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_BOXPLUS,           "white", "#808080")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_VLINE,             "white", "#808080")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_LCORNER,           "white", "#808080")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_BOXPLUSCONNECTED,  "white", "#808080")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER,           "white", "#808080")


        #self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI)
        #self.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick)
        #self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed)

        # Make some styles,  The lexer defines what each style is used for, we
        # just have to define what each style looks like.  This set is adapted from
        # Scintilla sample property files.

        # Global default styles for all languages
        self.StyleSetSpec(stc.STC_STYLE_DEFAULT,     "face:%(helv)s,size:%(size)d" % faces)
        self.StyleClearAll()  # Reset all to be like the default

        # Global default styles for all languages
        self.StyleSetSpec(stc.STC_STYLE_DEFAULT,     "face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_STYLE_LINENUMBER,  "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces)
        self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces)
        self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT,  "fore:#FFFFFF,back:#0000FF,bold")
        self.StyleSetSpec(stc.STC_STYLE_BRACEBAD,    "fore:#000000,back:#FF0000,bold")

        # Python styles
        # Default
        self.StyleSetSpec(stc.STC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
        # Comments
        self.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#007F00,face:%(other)s,size:%(size)d" % faces)
        # Number
        self.StyleSetSpec(stc.STC_P_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
        # String
        self.StyleSetSpec(stc.STC_P_STRING, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
        # Single quoted string
        self.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
        # Keyword
        self.StyleSetSpec(stc.STC_P_WORD, "fore:#00007F,bold,size:%(size)d" % faces)
        # Triple quotes
        self.StyleSetSpec(stc.STC_P_TRIPLE, "fore:#7F0000,size:%(size)d" % faces)
        # Triple double quotes
        self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, "fore:#7F0000,size:%(size)d" % faces)
        # Class name definition
        self.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#0000FF,bold,underline,size:%(size)d" % faces)
        # Function or method name definition
        self.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#007F7F,bold,size:%(size)d" % faces)
        # Operators
        self.StyleSetSpec(stc.STC_P_OPERATOR, "bold,size:%(size)d" % faces)
        # Identifiers
        self.StyleSetSpec(stc.STC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
        # Comment-blocks
        self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, "fore:#7F7F7F,size:%(size)d" % faces)
        # End of line where string is not closed
        self.StyleSetSpec(stc.STC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % faces)

        self.SetCaretForeground("BLUE")

    def __Cpp__(self):
        self.StyleClearAll()
        self.SetLexer(stc.STC_LEX_CPP)
        self.StyleSetSpec(stc.STC_C_COMMENT, 'fore:#408060,size:%(size)d' % faces)
        self.StyleSetSpec(stc.STC_C_COMMENTLINE, 'fore:#408060,size:%(size)d' % faces)
        self.StyleSetSpec(stc.STC_C_COMMENTDOC, 'fore:#408060,size:%(size)d' % faces)
        self.StyleSetSpec(stc.STC_C_NUMBER, 'fore:#0076AE,size:%(size)d' % faces)
        self.StyleSetSpec(stc.STC_C_WORD, 'bold,fore:#800056,size:%(size)d' % faces)
        self.StyleSetSpec(stc.STC_C_STRING, 'fore:#2a00ff,size:%(size)d' % faces)
        self.StyleSetSpec(stc.STC_C_PREPROCESSOR, 'bold,fore:#800056,size:%(size)d' % faces)
        self.StyleSetSpec(stc.STC_C_OPERATOR, 'bold,size:%(size)d' % faces)
        self.StyleSetSpec(stc.STC_C_STRINGEOL, 'back:#FFD5FF,size:%(size)d' % faces)

    def __XRC__(self):
        pass

    def __Lisp__(self):
        self.StyleClearAll()
        self.SetLexer(stc.STC_LEX_LISP)
        self.SetKeyWords(0, "abort abs access acons acos acosh add-method adjoin "
                    "adjust-array adjustable-array-p alist allocate-instance "
                    "alpha-char-p alphanumericp and append apply applyhook apropos "
                    "apropos-list aref arithmetic-error arithmetic-error-operands "
                    "arithmetic-error-operation array array-dimension "
                    "array-dimension-limit array-dimensions array-displacement "
                    "array-element-type array-has-fill-pointer-p "
                    "array-in-bounds-p array-rank array-rank-limit "
                    "array-row-major-index array-total-size "
                    "array-total-size-limit arrayp ash asin asinh assert assoc "
                    "assoc-if assoc-if-not atan atanh atom backquote baktrace "
                    "base-char base-string bignum bignums bit bit-and bit-andc1 "
                    "bit-andc2 bit-eqv bit-ior bit-nand bit-nor bit-not bit-orc1 "
                    "bit-orc2 bit-vector bit-vector-p bit-xor block boole boole-1 "
                    "boole-2 boole-and boole-andc1 boole-andc2 boole-c1 boole-c2 "
                    "boole-clr boole-eqv boole-ior boole-nand boole-nor boole-orc1 "
                    "boole-orc2 boole-set boole-xor boolean both-case-p boundp "
                    "break broadcast-stream broadcast-stream-streams "
                    "built-in-class butlast byte byte-position byte-size caaaar "
                    "caaadr caaar caadar caaddr caadr caar cadaar cadadr cadar "
                    "caddar cadddr caddr cadr call-arguments-limit call-method "
                    "call-next-method capitalize car case catch ccase cdaaar "
                    "cdaadr cdaar cdadar cdaddr cdadr cdar cddaar cddadr cddar "
                    "cdddar cddddr cdddr cddr cdr ceil-error ceil-error-name "
                    "ceiling cerror change-class char char-bit char-bits "
                    "char-bits-limit char-code char-code-limit char-control-bit "
                    "char-downcase char-equal char-font char-font-limit "
                    "char-greaterp char-hyper-bit char-int char-lessp "
                    "char-meta-bit char-name char-not-equal char-not-greaterp "
                    "char-not-lessp char-super-bit char-upcase char/= char<= char= "
                    "char>= character characterp check-type cirhash cis class "
                    "class-name class-of clear-input clear-output close code-char "
                    "coerce commonp compilation-speed compile compile-file "
                    "compile-file-pathname compiled-function compiled-function-p "
                    "compiler-let compiler-macro compiler-macro-function "
                    "complement complex complexp compute-applicable-methods "
                    "compute-restarts concatenate concatenated-stream "
                    "concatenated-stream-streams cond condition conjugate cons "
                    "consp constantly constantp continue control-error copy "
                    "copy-list copy-pprint-dispatch copy-readtable copy-seq "
                    "copy-structure copy-symbol copy-tree cos cosh count count-if "
                    "count-if-not ctypecase debug decf declaim declaration declare "
                    "decode-float decode-universal-time defclass defconstant "
                    "defgeneric define-compiler-macro define-condition "
                    "define-method-combination define-modify-macro "
                    "define-setf-expander define-setf-method define-symbol-macro "
                    "defmacro defmethod defpackage defparameter defsetf defstruct "
                    "deftype defun defvar delete delete-duplicates delete-file "
                    "delete-if delete-if-not delete-package denominator "
                    "deposite-field describe describe-object destructuring-bind "
                    "digit-char digit-char-p directory directory-namestring "
                    "disassemble division-by-zero do do* do-all-symbols "
                    "do-external-symbols do-symbols dolist dotimes double-float "
                    "double-float-epsilon double-float-negative-epsilion dpb "
                    "dribble dynamic-extent ecase echo-stream "
                    "echo-stream-input-stream echo-stream-output-stream ed eigth "
                    "elt encode-universal-time end-of-file endp enough-namestring "
                    "ensure-directories-exist ensure-generic-function eq eql equal "
                    "equalp error errset etypecase eval eval-when evalhook evenp "
                    "every exp export expt extend-char fboundp fceiling "
                    "fdefinition fflor fifth file-author file-error "
                    "file-error-pathname file-length file-namestring file-position "
                    "file-stream file-string-length file-write-date fill "
                    "fill-pointer find find-all-symbols find-class find-if "
                    "find-if-not find-method find-package find-restart find-symbol "
                    "finish-output first fixnum flet float float-digits "
                    "float-precision float-radix float-sign floating-point-inexact "
                    "floating-point-invalid-operation floating-point-underflow "
                    "floatp floor fmakunbound force-output format formatter fourth "
                    "fresh-line fround ftruncate ftype funcall function "
                    "function-keywords function-lambda-expression functionp gbitp "
                    "gcd generic-function gensym gentemp get get-decoded-time "
                    "get-dispatched-macro-character get-internal-real-time "
                    "get-internal-run-time get-macro-character "
                    "get-output-stream-string get-properties get-setf-expansion "
                    "get-setf-method get-universial-time getf gethash go "
                    "graphic-char-p handler-bind handler-case hash hash-table "
                    "hash-table-count hash-table-p hash-table-rehash-size "
                    "hash-table-rehash-threshold hash-table-size hash-table-test "
                    "host-namestring identity if if-exists ignorable ignore "
                    "ignore-errors imagpart import in-package incf "
                    "initialize-instance inline input-stream-p inspect int-char "
                    "integer integer-decode-float integer-length integerp "
                    "interactive-stream-p intern internal-time-units-per-second "
                    "intersection invalid-method-error invoke-debugger "
                    "invoke-restart invoke-restart-interactively isqrt keyword "
                    "keywordp l labels lambda lambda-list-keywords "
                    "lambda-parameters-limit last lcm ldb ldb-test ldiff "
                    "least-negative-double-float least-negative-long-float "
                    "least-negative-normalized-double-float "
                    "least-negative-normalized-long-float "
                    "least-negative-normalized-short-font "
                    "least-negative-normalized-single-font "
                    "least-negative-short-font least-negative-single-font "
                    "least-positive-double-float least-positive-long-float "
                    "least-positive-normalized-double-float "
                    "least-positive-normalized-long-float "
                    "least-positive-normalized-short-float "
                    "least-positive-normalized-single-float "
                    "least-positive-short-float least-positive-single-float length "
                    "let let* lisp lisp-implementation-type "
                    "lisp-implementation-version list list* "
                    "list-all-packages list-lenght listen listp load "
                    "load-logical-pathname-translation load-time-value locally "
                    "log logand logandc1 logandc2 logbitp logcount logeqv "
                    "logical-pathname logical-pathname-translations logior lognand "
                    "lognor lognot logorc1 logorc2 logtest logxor long-float "
                    "long-float-epsilon long-float-negative-epsilon long-site-name "
                    "loop loop-finish lower-case-p machine-instance machine-type "
                    "machine-version macro-function macroexpand macroexpand-1 "
                    "macroexpand-l macrolet make make-array make-broadcast-stream "
                    "make-char make-concatenated-stream make-condition "
                    "make-dispatch-macro-character make-echo-stream "
                    "make-hash-table make-instance make-instances-obsolete "
                    "make-list make-load-form make-load-form-saving-slots "
                    "make-method make-package make-pathname make-random-state "
                    "make-sequence make-string make-string-input-stream "
                    "make-string-output-stream make-symbol make-synonym-stream "
                    "make-two-way-stream makunbound map map-into mapc mapcan "
                    "mapcar mapcon maphash mapl maplist mask-field max member "
                    "member-if member-if-not merge merge-pathname merge-pathnames "
                    "method method-combination method-combination-error "
                    "method-qualifiers min minusp mismatch mod "
                    "most-negative-double-float most-negative-fixnum "
                    "most-negative-long-float most-negative-short-float "
                    "most-negative-single-float most-positive-fixnum "
                    "most-positive-long-float most-positive-short-float "
                    "most-positive-single-float muffle-warning "
                    "multiple-value-bind multiple-value-call multiple-value-limit "
                    "multiple-value-list multiple-value-prog1 multiple-value-seteq "
                    "multiple-value-setq name name-char namestring nbutlast nconc "
                    "next-method-p nil nintersection ninth no-applicable-method "
                    "no-next-method not notany notevery notinline nreconc nreverse "
                    "nset-difference nset-exclusive-or nstring nstring-capitalize "
                    "nstring-downcase nstring-upcase nstubst-if-not nsublis nsubst "
                    "nsubst-if nth nth-value nthcdr null number numberp numerator "
                    "nunion oddp open open-stream-p optimize or otherwise "
                    "output-stream-p package package-error package-error-package "
                    "package-name package-nicknames package-shadowing-symbols "
                    "package-use-list package-used-by-list packagep pairlis "
                    "parse-error parse-integer parse-namestring pathname "
                    "pathname-device pathname-directory pathname-host "
                    "pathname-match-p pathname-name pathname-type "
                    "pathname-version pathnamep peek-char phase pi plist plusp pop "
                    "position position-if position-if-not pprint pprint-dispatch "
                    "pprint-exit-if-list-exhausted pprint-fill pprint-indent "
                    "pprint-linear pprint-logical-block pprint-newline pprint-pop "
                    "pprint-tab pprint-tabular prin1 prin1-to-string princ "
                    "princ-to-string print print-not-readable "
                    "print-not-readable-object print-object probe-file proclaim "
                    "prog prog* prog1 prog2 progn program-error progv provide "
                    "psetf psetq push pushnew putprop quote random random-state "
                    "random-state-p rassoc rassoc-if rassoc-if-not ration rational "
                    "rationalize rationalp read read-byte read-car-no-hang "
                    "read-char read-delimited-list read-eval-print "
                    "read-from-string read-line read-preserving-whitespace "
                    "read-squence reader-error readtable readtable-case readtablep "
                    "real realp realpart reduce reinitialize-instance rem remf "
                    "remhash remove remove-duplicates remove-if "
                    "remove-if-not remove-method remprop rename-file "
                    "rename-package replace require rest restart restart-bind "
                    "restart-case restart-name return return-from revappend "
                    "reverse room rotatef round row-major-aref rplaca rplacd "
                    "safety satisfies sbit scale-float schar search second "
                    "sequence serious-condition set set-char-bit set-difference "
                    "set-dispatched-macro-character set-exclusive-or "
                    "set-macro-character set-pprint-dispatch "
                    "set-syntax-from-char setf setq seventh shadow "
                    "shadowing-import shared-initialize shiftf short-float "
                    "short-float-epsilon short-float-negative-epsilon "
                    "short-site-name signal signed-byte signum simple-array "
                    "simple-base-string simple-bit-vector- simple-bit-vector-p "
                    "simple-condition simple-condition-format-arguments "
                    "simple-condition-format-control simple-error simple-string "
                    "simple-string-p simple-type-error simple-vector "
                    "simple-vector-p simple-warning sin single-float "
                    "single-float-epsilon single-float-negative-epsilon sinh "
                    "sixth sleep slot-boundp slot-exists-p slot-makunbound "
                    "slot-missing slot-unbound slot-value software-type "
                    "software-version some sort space special special-form-p "
                    "special-operator-p speed sqrt stable-sort standard "
                    "standard-char standard-char-p standard-class "
                    "standard-generic-function standard-method standard-object "
                    "step storage-condition store-value stream stream-element-type "
                    "stream-error stream-error-stream stream-external-format "
                    "streamp streamup string string-capitalize string-char "
                    "string-char-p string-downcase string-equal string-greaterp "
                    "string-left-trim string-lessp string-not-equal "
                    "string-not-greaterp string-not-lessp string-right-strim "
                    "string-right-trim string-stream string-trim string-upcase "
                    "string/= string< string<= string= string> string>= stringp "
                    "structure structure-class structure-object style-warning "
                    "sublim sublis subseq subsetp subst subst-if subst-if-not "
                    "substitute substitute-if substitute-if-not subtypep svref "
                    "sxhash symbol symbol-function symbol-macrolet symbol-name "
                    "symbol-package symbol-plist symbol-value symbolp "
                    "synonym-stream synonym-stream-symbol sys system t tagbody "
                    "tailp tan tanh tenth terpri the third throw time trace "
                    "translate-logical-pathname translate-pathname tree-equal "
                    "truename truncase truncate two-way-stream "
                    "two-way-stream-input-stream two-way-stream-output-stream "
                    "type type-error type-error-datnum type-error-expected-type "
                    "type-of typecase typep unbound-slot unbound-slot-instance "
                    "unbound-variable undefined-function unexport unintern union "
                    "unless unread unread-char unsigned-byte untrace unuse-package "
                    "unwind-protect update-instance-for-different-class "
                    "update-instance-for-redefined-class "
                    "upgraded-array-element-type upgraded-complex-part-type "
                    "upper-case-p use-package use-value user user-homedir-pathname "
                    "value value-list values vector vector-pop vector-push "
                    "vector-push-extend vectorp warn warning when "
                    "wild-pathname-p with-accessors with-compilation-unit "
                    "with-condition-restarts with-hash-table-iterator "
                    "with-input-from-string with-open-file with-open-stream "
                    "with-output-to-string with-package-iterator "
                    "with-simple-restart with-slots with-standard-io-syntax write "
                    "write-byte write-char write-line write-sequence" )
        self.SetKeyWords(1, ":abort :adjustable :append :array :base :case :circle "
                        ":conc-name :constructor :copier :count :create :default "
                        ":device :directory :displaced-index-offset :displaced-to "
                        ":element-type :end :end1 :end2 :error :escape :external "
                        ":from-end :gensym :host :include :if-does-not-exist "
                        ":if-exists :index :inherited :internal :initial-contents "
                        ":initial-element :initial-offset :initial-value :input "
                        ":io :junk-allowed :key :length :level :name :named "
                        ":new-version :nicknames :output :ouput=file :overwrite "
                        ":predicate :preserve-whitespace :pretty :print "
                        ":print-function :probe :radix :read-only :rehash-size "
                        ":rehash-threshold :rename :size :rename-and-delete :start "
                        ":start1 :start2 :stream :supersede :test :test-not :use "
                        ":verbose :version")
        self.SetLexer(stc.STC_LEX_LISP)
        self.StyleSetSpec(stc.STC_LISP_COMMENT, "fore:#007F00,face:%(other)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_DEFAULT, "fore:#808080,face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_IDENTIFIER, "fore:#007F7F,bold,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_KEYWORD, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_KEYWORD_KW, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_MULTI_COMMENT, "fore:#7F7F7F,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_OPERATOR, "bold,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_SPECIAL, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_STRING, "fore:#7F0000,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_STRINGEOL, "fore:#0000FF,bold,underline,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_SYMBOL, "fore:#00007F,bold,size:%(size)d" % faces)

    def __Perl__(self):
        self.SetLexer(stc.STC_LEX_PERL)
        pass

    def __Preview__(self):
        pass

"""
TODO: What kind of syntax is handled in the Preview "language" type? Raw?
"""

import keyword

import wx
import wx.stc as stc

if wx.Platform == '__WXMSW__':
    faces = { 'times': 'Times New Roman',
              'mono' : 'Courier New',
              'helv' : 'Arial',
              'other': 'Comic Sans MS',
              'size' : 10,
              'size2': 8,
             }
elif wx.Platform == '__WXMAC__':
    faces = { 'times': 'Times New Roman',
              'mono' : 'Monaco',
              'helv' : 'Arial',
              'other': 'Comic Sans MS',
              'size' : 12,
              'size2': 10,
             }
else:
    faces = { 'times': 'Times',
              'mono' : 'Courier',
              'helv' : 'Helvetica',
              'other': 'new century schoolbook',
              'size' : 12,
              'size2': 10,
             }

class StyledTextCtrl(stc.StyledTextCtrl):
    """docstring for StyledTextCtrl"""
    fold_symbols = 2

    def __init__(self, parent, ID, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0):
        stc.StyledTextCtrl.__init__(self, parent, ID, pos, size, style)
    

    def Lexer(self, lexer):
        # Non-namespace method
        if lexer == 'python':
            self.__Python__()

        elif lexer == 'C++':
            self.__Cpp__()
        
        elif lexer == 'XRC':
            self.__XRC__()
        
        elif lexer == 'lisp':
            self.__Lisp__()
        
        elif lexer == 'perl':
            self.__Perl__()

        elif lexer == 'preview': # Raw code?
            self.__Preview__()

    def __Python__(self):
        self.SetLexer(stc.STC_LEX_PYTHON)
        self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
        self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT)

        self.SetLexer(stc.STC_LEX_PYTHON)
        self.SetKeyWords(0, " ".join(keyword.kwlist))

        self.SetProperty("fold", "1")
        self.SetProperty("tab.timmy.whinge.level", "1")
        self.SetMargins(0,0)

        self.SetViewWhiteSpace(False)
        # self.SetBufferedDraw(False)
        # self.SetViewEOL(True)
        # self.SetEOLMode(stc.STC_EOL_CRLF)
        # self.SetUseAntiAliasing(True)

        self.SetEdgeMode(stc.STC_EDGE_BACKGROUND)
        self.SetEdgeColumn(78)

        # Setup a margin to hold fold markers
        # self.SetFoldFlags(16)  ###  WHAT IS THIS VALUE?  WHAT ARE THE OTHER FLAGS?  DOES IT MATTER?
        
        self.SetMarginType(1, stc.STC_MARGIN_NUMBER)
        self.SetMarginMask(1, 0)
        self.SetMarginWidth(1, 20)
        self.SetMarginSensitive(2, True)

        if self.fold_symbols == 0:
            # Arrow pointing right for contracted folders, arrow pointing down for expanded
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_ARROWDOWN, "black", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_ARROW, "black", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_EMPTY, "black", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_EMPTY, "black", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_EMPTY,     "white", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY,     "white", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY,     "white", "black")

        elif self.fold_symbols == 1:
            # Plus for contracted folders, minus for expanded
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_MINUS, "white", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_PLUS,  "white", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_EMPTY, "white", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_EMPTY, "white", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_EMPTY, "white", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black")

        elif self.fold_symbols == 2:
            # Like a flattened tree control using circular headers and curved joins
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_CIRCLEMINUS,          "white", "#404040")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_CIRCLEPLUS,           "white", "#404040")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_VLINE,                "white", "#404040")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_LCORNERCURVE,         "white", "#404040")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_CIRCLEPLUSCONNECTED,  "white", "#404040")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_CIRCLEMINUSCONNECTED, "white", "#404040")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNERCURVE,         "white", "#404040")

        elif self.fold_symbols == 3:
            # Like a flattened tree control using square headers
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN,    stc.STC_MARK_BOXMINUS,          "white", "#808080")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDER,        stc.STC_MARK_BOXPLUS,           "white", "#808080")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB,     stc.STC_MARK_VLINE,             "white", "#808080")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL,    stc.STC_MARK_LCORNER,           "white", "#808080")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND,     stc.STC_MARK_BOXPLUSCONNECTED,  "white", "#808080")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080")
            self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER,           "white", "#808080")


        #self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI)
        #self.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick)
        #self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed)

        # Make some styles,  The lexer defines what each style is used for, we
        # just have to define what each style looks like.  This set is adapted from
        # Scintilla sample property files.

        # Global default styles for all languages
        self.StyleSetSpec(stc.STC_STYLE_DEFAULT,     "face:%(helv)s,size:%(size)d" % faces)
        self.StyleClearAll()  # Reset all to be like the default

        # Global default styles for all languages
        self.StyleSetSpec(stc.STC_STYLE_DEFAULT,     "face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_STYLE_LINENUMBER,  "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces)
        self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces)
        self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT,  "fore:#FFFFFF,back:#0000FF,bold")
        self.StyleSetSpec(stc.STC_STYLE_BRACEBAD,    "fore:#000000,back:#FF0000,bold")

        # Python styles
        # Default
        self.StyleSetSpec(stc.STC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
        # Comments
        self.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#007F00,face:%(other)s,size:%(size)d" % faces)
        # Number
        self.StyleSetSpec(stc.STC_P_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
        # String
        self.StyleSetSpec(stc.STC_P_STRING, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
        # Single quoted string
        self.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
        # Keyword
        self.StyleSetSpec(stc.STC_P_WORD, "fore:#00007F,bold,size:%(size)d" % faces)
        # Triple quotes
        self.StyleSetSpec(stc.STC_P_TRIPLE, "fore:#7F0000,size:%(size)d" % faces)
        # Triple double quotes
        self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, "fore:#7F0000,size:%(size)d" % faces)
        # Class name definition
        self.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#0000FF,bold,underline,size:%(size)d" % faces)
        # Function or method name definition
        self.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#007F7F,bold,size:%(size)d" % faces)
        # Operators
        self.StyleSetSpec(stc.STC_P_OPERATOR, "bold,size:%(size)d" % faces)
        # Identifiers
        self.StyleSetSpec(stc.STC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
        # Comment-blocks
        self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, "fore:#7F7F7F,size:%(size)d" % faces)
        # End of line where string is not closed
        self.StyleSetSpec(stc.STC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % faces)

        self.SetCaretForeground("BLUE")

    def __Cpp__(self):
        self.StyleClearAll()
        self.SetLexer(stc.STC_LEX_CPP)
        self.StyleSetSpec(stc.STC_C_COMMENT, 'fore:#408060,size:%(size)d' % faces)
        self.StyleSetSpec(stc.STC_C_COMMENTLINE, 'fore:#408060,size:%(size)d' % faces)
        self.StyleSetSpec(stc.STC_C_COMMENTDOC, 'fore:#408060,size:%(size)d' % faces)
        self.StyleSetSpec(stc.STC_C_NUMBER, 'fore:#0076AE,size:%(size)d' % faces)
        self.StyleSetSpec(stc.STC_C_WORD, 'bold,fore:#800056,size:%(size)d' % faces)
        self.StyleSetSpec(stc.STC_C_STRING, 'fore:#2a00ff,size:%(size)d' % faces)
        self.StyleSetSpec(stc.STC_C_PREPROCESSOR, 'bold,fore:#800056,size:%(size)d' % faces)
        self.StyleSetSpec(stc.STC_C_OPERATOR, 'bold,size:%(size)d' % faces)
        self.StyleSetSpec(stc.STC_C_STRINGEOL, 'back:#FFD5FF,size:%(size)d' % faces)

    def __XRC__(self):
        pass

    def __Lisp__(self):
        self.StyleClearAll()
        self.SetLexer(stc.STC_LEX_LISP)
        self.SetKeyWords(0, "abort abs access acons acos acosh add-method adjoin "
                    "adjust-array adjustable-array-p alist allocate-instance "
                    "alpha-char-p alphanumericp and append apply applyhook apropos "
                    "apropos-list aref arithmetic-error arithmetic-error-operands "
                    "arithmetic-error-operation array array-dimension "
                    "array-dimension-limit array-dimensions array-displacement "
                    "array-element-type array-has-fill-pointer-p "
                    "array-in-bounds-p array-rank array-rank-limit "
                    "array-row-major-index array-total-size "
                    "array-total-size-limit arrayp ash asin asinh assert assoc "
                    "assoc-if assoc-if-not atan atanh atom backquote baktrace "
                    "base-char base-string bignum bignums bit bit-and bit-andc1 "
                    "bit-andc2 bit-eqv bit-ior bit-nand bit-nor bit-not bit-orc1 "
                    "bit-orc2 bit-vector bit-vector-p bit-xor block boole boole-1 "
                    "boole-2 boole-and boole-andc1 boole-andc2 boole-c1 boole-c2 "
                    "boole-clr boole-eqv boole-ior boole-nand boole-nor boole-orc1 "
                    "boole-orc2 boole-set boole-xor boolean both-case-p boundp "
                    "break broadcast-stream broadcast-stream-streams "
                    "built-in-class butlast byte byte-position byte-size caaaar "
                    "caaadr caaar caadar caaddr caadr caar cadaar cadadr cadar "
                    "caddar cadddr caddr cadr call-arguments-limit call-method "
                    "call-next-method capitalize car case catch ccase cdaaar "
                    "cdaadr cdaar cdadar cdaddr cdadr cdar cddaar cddadr cddar "
                    "cdddar cddddr cdddr cddr cdr ceil-error ceil-error-name "
                    "ceiling cerror change-class char char-bit char-bits "
                    "char-bits-limit char-code char-code-limit char-control-bit "
                    "char-downcase char-equal char-font char-font-limit "
                    "char-greaterp char-hyper-bit char-int char-lessp "
                    "char-meta-bit char-name char-not-equal char-not-greaterp "
                    "char-not-lessp char-super-bit char-upcase char/= char<= char= "
                    "char>= character characterp check-type cirhash cis class "
                    "class-name class-of clear-input clear-output close code-char "
                    "coerce commonp compilation-speed compile compile-file "
                    "compile-file-pathname compiled-function compiled-function-p "
                    "compiler-let compiler-macro compiler-macro-function "
                    "complement complex complexp compute-applicable-methods "
                    "compute-restarts concatenate concatenated-stream "
                    "concatenated-stream-streams cond condition conjugate cons "
                    "consp constantly constantp continue control-error copy "
                    "copy-list copy-pprint-dispatch copy-readtable copy-seq "
                    "copy-structure copy-symbol copy-tree cos cosh count count-if "
                    "count-if-not ctypecase debug decf declaim declaration declare "
                    "decode-float decode-universal-time defclass defconstant "
                    "defgeneric define-compiler-macro define-condition "
                    "define-method-combination define-modify-macro "
                    "define-setf-expander define-setf-method define-symbol-macro "
                    "defmacro defmethod defpackage defparameter defsetf defstruct "
                    "deftype defun defvar delete delete-duplicates delete-file "
                    "delete-if delete-if-not delete-package denominator "
                    "deposite-field describe describe-object destructuring-bind "
                    "digit-char digit-char-p directory directory-namestring "
                    "disassemble division-by-zero do do* do-all-symbols "
                    "do-external-symbols do-symbols dolist dotimes double-float "
                    "double-float-epsilon double-float-negative-epsilion dpb "
                    "dribble dynamic-extent ecase echo-stream "
                    "echo-stream-input-stream echo-stream-output-stream ed eigth "
                    "elt encode-universal-time end-of-file endp enough-namestring "
                    "ensure-directories-exist ensure-generic-function eq eql equal "
                    "equalp error errset etypecase eval eval-when evalhook evenp "
                    "every exp export expt extend-char fboundp fceiling "
                    "fdefinition fflor fifth file-author file-error "
                    "file-error-pathname file-length file-namestring file-position "
                    "file-stream file-string-length file-write-date fill "
                    "fill-pointer find find-all-symbols find-class find-if "
                    "find-if-not find-method find-package find-restart find-symbol "
                    "finish-output first fixnum flet float float-digits "
                    "float-precision float-radix float-sign floating-point-inexact "
                    "floating-point-invalid-operation floating-point-underflow "
                    "floatp floor fmakunbound force-output format formatter fourth "
                    "fresh-line fround ftruncate ftype funcall function "
                    "function-keywords function-lambda-expression functionp gbitp "
                    "gcd generic-function gensym gentemp get get-decoded-time "
                    "get-dispatched-macro-character get-internal-real-time "
                    "get-internal-run-time get-macro-character "
                    "get-output-stream-string get-properties get-setf-expansion "
                    "get-setf-method get-universial-time getf gethash go "
                    "graphic-char-p handler-bind handler-case hash hash-table "
                    "hash-table-count hash-table-p hash-table-rehash-size "
                    "hash-table-rehash-threshold hash-table-size hash-table-test "
                    "host-namestring identity if if-exists ignorable ignore "
                    "ignore-errors imagpart import in-package incf "
                    "initialize-instance inline input-stream-p inspect int-char "
                    "integer integer-decode-float integer-length integerp "
                    "interactive-stream-p intern internal-time-units-per-second "
                    "intersection invalid-method-error invoke-debugger "
                    "invoke-restart invoke-restart-interactively isqrt keyword "
                    "keywordp l labels lambda lambda-list-keywords "
                    "lambda-parameters-limit last lcm ldb ldb-test ldiff "
                    "least-negative-double-float least-negative-long-float "
                    "least-negative-normalized-double-float "
                    "least-negative-normalized-long-float "
                    "least-negative-normalized-short-font "
                    "least-negative-normalized-single-font "
                    "least-negative-short-font least-negative-single-font "
                    "least-positive-double-float least-positive-long-float "
                    "least-positive-normalized-double-float "
                    "least-positive-normalized-long-float "
                    "least-positive-normalized-short-float "
                    "least-positive-normalized-single-float "
                    "least-positive-short-float least-positive-single-float length "
                    "let let* lisp lisp-implementation-type "
                    "lisp-implementation-version list list* "
                    "list-all-packages list-lenght listen listp load "
                    "load-logical-pathname-translation load-time-value locally "
                    "log logand logandc1 logandc2 logbitp logcount logeqv "
                    "logical-pathname logical-pathname-translations logior lognand "
                    "lognor lognot logorc1 logorc2 logtest logxor long-float "
                    "long-float-epsilon long-float-negative-epsilon long-site-name "
                    "loop loop-finish lower-case-p machine-instance machine-type "
                    "machine-version macro-function macroexpand macroexpand-1 "
                    "macroexpand-l macrolet make make-array make-broadcast-stream "
                    "make-char make-concatenated-stream make-condition "
                    "make-dispatch-macro-character make-echo-stream "
                    "make-hash-table make-instance make-instances-obsolete "
                    "make-list make-load-form make-load-form-saving-slots "
                    "make-method make-package make-pathname make-random-state "
                    "make-sequence make-string make-string-input-stream "
                    "make-string-output-stream make-symbol make-synonym-stream "
                    "make-two-way-stream makunbound map map-into mapc mapcan "
                    "mapcar mapcon maphash mapl maplist mask-field max member "
                    "member-if member-if-not merge merge-pathname merge-pathnames "
                    "method method-combination method-combination-error "
                    "method-qualifiers min minusp mismatch mod "
                    "most-negative-double-float most-negative-fixnum "
                    "most-negative-long-float most-negative-short-float "
                    "most-negative-single-float most-positive-fixnum "
                    "most-positive-long-float most-positive-short-float "
                    "most-positive-single-float muffle-warning "
                    "multiple-value-bind multiple-value-call multiple-value-limit "
                    "multiple-value-list multiple-value-prog1 multiple-value-seteq "
                    "multiple-value-setq name name-char namestring nbutlast nconc "
                    "next-method-p nil nintersection ninth no-applicable-method "
                    "no-next-method not notany notevery notinline nreconc nreverse "
                    "nset-difference nset-exclusive-or nstring nstring-capitalize "
                    "nstring-downcase nstring-upcase nstubst-if-not nsublis nsubst "
                    "nsubst-if nth nth-value nthcdr null number numberp numerator "
                    "nunion oddp open open-stream-p optimize or otherwise "
                    "output-stream-p package package-error package-error-package "
                    "package-name package-nicknames package-shadowing-symbols "
                    "package-use-list package-used-by-list packagep pairlis "
                    "parse-error parse-integer parse-namestring pathname "
                    "pathname-device pathname-directory pathname-host "
                    "pathname-match-p pathname-name pathname-type "
                    "pathname-version pathnamep peek-char phase pi plist plusp pop "
                    "position position-if position-if-not pprint pprint-dispatch "
                    "pprint-exit-if-list-exhausted pprint-fill pprint-indent "
                    "pprint-linear pprint-logical-block pprint-newline pprint-pop "
                    "pprint-tab pprint-tabular prin1 prin1-to-string princ "
                    "princ-to-string print print-not-readable "
                    "print-not-readable-object print-object probe-file proclaim "
                    "prog prog* prog1 prog2 progn program-error progv provide "
                    "psetf psetq push pushnew putprop quote random random-state "
                    "random-state-p rassoc rassoc-if rassoc-if-not ration rational "
                    "rationalize rationalp read read-byte read-car-no-hang "
                    "read-char read-delimited-list read-eval-print "
                    "read-from-string read-line read-preserving-whitespace "
                    "read-squence reader-error readtable readtable-case readtablep "
                    "real realp realpart reduce reinitialize-instance rem remf "
                    "remhash remove remove-duplicates remove-if "
                    "remove-if-not remove-method remprop rename-file "
                    "rename-package replace require rest restart restart-bind "
                    "restart-case restart-name return return-from revappend "
                    "reverse room rotatef round row-major-aref rplaca rplacd "
                    "safety satisfies sbit scale-float schar search second "
                    "sequence serious-condition set set-char-bit set-difference "
                    "set-dispatched-macro-character set-exclusive-or "
                    "set-macro-character set-pprint-dispatch "
                    "set-syntax-from-char setf setq seventh shadow "
                    "shadowing-import shared-initialize shiftf short-float "
                    "short-float-epsilon short-float-negative-epsilon "
                    "short-site-name signal signed-byte signum simple-array "
                    "simple-base-string simple-bit-vector- simple-bit-vector-p "
                    "simple-condition simple-condition-format-arguments "
                    "simple-condition-format-control simple-error simple-string "
                    "simple-string-p simple-type-error simple-vector "
                    "simple-vector-p simple-warning sin single-float "
                    "single-float-epsilon single-float-negative-epsilon sinh "
                    "sixth sleep slot-boundp slot-exists-p slot-makunbound "
                    "slot-missing slot-unbound slot-value software-type "
                    "software-version some sort space special special-form-p "
                    "special-operator-p speed sqrt stable-sort standard "
                    "standard-char standard-char-p standard-class "
                    "standard-generic-function standard-method standard-object "
                    "step storage-condition store-value stream stream-element-type "
                    "stream-error stream-error-stream stream-external-format "
                    "streamp streamup string string-capitalize string-char "
                    "string-char-p string-downcase string-equal string-greaterp "
                    "string-left-trim string-lessp string-not-equal "
                    "string-not-greaterp string-not-lessp string-right-strim "
                    "string-right-trim string-stream string-trim string-upcase "
                    "string/= string< string<= string= string> string>= stringp "
                    "structure structure-class structure-object style-warning "
                    "sublim sublis subseq subsetp subst subst-if subst-if-not "
                    "substitute substitute-if substitute-if-not subtypep svref "
                    "sxhash symbol symbol-function symbol-macrolet symbol-name "
                    "symbol-package symbol-plist symbol-value symbolp "
                    "synonym-stream synonym-stream-symbol sys system t tagbody "
                    "tailp tan tanh tenth terpri the third throw time trace "
                    "translate-logical-pathname translate-pathname tree-equal "
                    "truename truncase truncate two-way-stream "
                    "two-way-stream-input-stream two-way-stream-output-stream "
                    "type type-error type-error-datnum type-error-expected-type "
                    "type-of typecase typep unbound-slot unbound-slot-instance "
                    "unbound-variable undefined-function unexport unintern union "
                    "unless unread unread-char unsigned-byte untrace unuse-package "
                    "unwind-protect update-instance-for-different-class "
                    "update-instance-for-redefined-class "
                    "upgraded-array-element-type upgraded-complex-part-type "
                    "upper-case-p use-package use-value user user-homedir-pathname "
                    "value value-list values vector vector-pop vector-push "
                    "vector-push-extend vectorp warn warning when "
                    "wild-pathname-p with-accessors with-compilation-unit "
                    "with-condition-restarts with-hash-table-iterator "
                    "with-input-from-string with-open-file with-open-stream "
                    "with-output-to-string with-package-iterator "
                    "with-simple-restart with-slots with-standard-io-syntax write "
                    "write-byte write-char write-line write-sequence" )
        self.SetKeyWords(1, ":abort :adjustable :append :array :base :case :circle "
                        ":conc-name :constructor :copier :count :create :default "
                        ":device :directory :displaced-index-offset :displaced-to "
                        ":element-type :end :end1 :end2 :error :escape :external "
                        ":from-end :gensym :host :include :if-does-not-exist "
                        ":if-exists :index :inherited :internal :initial-contents "
                        ":initial-element :initial-offset :initial-value :input "
                        ":io :junk-allowed :key :length :level :name :named "
                        ":new-version :nicknames :output :ouput=file :overwrite "
                        ":predicate :preserve-whitespace :pretty :print "
                        ":print-function :probe :radix :read-only :rehash-size "
                        ":rehash-threshold :rename :size :rename-and-delete :start "
                        ":start1 :start2 :stream :supersede :test :test-not :use "
                        ":verbose :version")
        self.SetLexer(stc.STC_LEX_LISP)
        self.StyleSetSpec(stc.STC_LISP_COMMENT, "fore:#007F00,face:%(other)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_DEFAULT, "fore:#808080,face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_IDENTIFIER, "fore:#007F7F,bold,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_KEYWORD, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_KEYWORD_KW, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_MULTI_COMMENT, "fore:#7F7F7F,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_OPERATOR, "bold,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_SPECIAL, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_STRING, "fore:#7F0000,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_STRINGEOL, "fore:#0000FF,bold,underline,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_LISP_SYMBOL, "fore:#00007F,bold,size:%(size)d" % faces)

    def __Perl__(self):
        self.SetLexer(stc.STC_LEX_PERL)
        pass

    def __Preview__(self):
        pass

TODO: What kind of syntax is handled in the Preview "language" type? Raw? docstring for StyledTextCtrl # Non-namespace method # Raw code? # self.SetBufferedDraw(False) # self.SetViewEOL(True) # self.SetEOLMode(stc.STC_EOL_CRLF) # self.SetUseAntiAliasing(True) # Setup a margin to hold fold markers # self.SetFoldFlags(16)  ###  WHAT IS THIS VALUE?  WHAT ARE THE OTHER FLAGS?  DOES IT MATTER? # Arrow pointing right for contracted folders, arrow pointing down for expanded # Plus for contracted folders, minus for expanded # Like a flattened tree control using circular headers and curved joins # Like a flattened tree control using square headers #self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI) #self.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick) #self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed) # Make some styles,  The lexer defines what each style is used for, we # just have to define what each style looks like.  This set is adapted from # Scintilla sample property files. # Global default styles for all languages # Reset all to be like the default # Global default styles for all languages #C0C0C0,face:%(helv)s,size:%(size2)d" % faces) #FFFFFF,back:#0000FF,bold") #000000,back:#FF0000,bold") # Python styles # Default #000000,face:%(helv)s,size:%(size)d" % faces) # Comments #007F00,face:%(other)s,size:%(size)d" % faces) # Number #007F7F,size:%(size)d" % faces) # String #7F007F,face:%(helv)s,size:%(size)d" % faces) # Single quoted string #7F007F,face:%(helv)s,size:%(size)d" % faces) # Keyword #00007F,bold,size:%(size)d" % faces) # Triple quotes #7F0000,size:%(size)d" % faces) # Triple double quotes #7F0000,size:%(size)d" % faces) # Class name definition #0000FF,bold,underline,size:%(size)d" % faces) # Function or method name definition #007F7F,bold,size:%(size)d" % faces) # Operators # Identifiers #000000,face:%(helv)s,size:%(size)d" % faces) # Comment-blocks #7F7F7F,size:%(size)d" % faces) # End of line where string is not closed #000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % faces) #408060,size:%(size)d' % faces) #408060,size:%(size)d' % faces) #408060,size:%(size)d' % faces) #0076AE,size:%(size)d' % faces) #800056,size:%(size)d' % faces) #2a00ff,size:%(size)d' % faces) #800056,size:%(size)d' % faces) #FFD5FF,size:%(size)d' % faces) #007F00,face:%(other)s,size:%(size)d" % faces) #808080,face:%(helv)s,size:%(size)d" % faces) #007F7F,bold,size:%(size)d" % faces) #7F007F,face:%(helv)s,size:%(size)d" % faces) #7F007F,face:%(helv)s,size:%(size)d" % faces) #7F7F7F,size:%(size)d" % faces) #007F7F,size:%(size)d" % faces) #000000,face:%(helv)s,size:%(size)d" % faces) #7F0000,size:%(size)d" % faces) #0000FF,bold,underline,size:%(size)d" % faces) #00007F,bold,size:%(size)d" % faces)