full name - 2018-09-13

Made a simple script that colors the text on the fly, i use it mainly on one time notes so i dont have to define a new language on every other document. This script is currently killed by double click event, feel free to modify :)

import re

color = {}
sc = 1 

def getColor(line):
  global sc
  global color
  l = editor.getLine(line)
  if re.search('^[a-zA-Z0-9_]* := 0x[0-9a-fA-F]{6}',l) is not None:
    c = re.split('[ \n]',l)
    n = int(c[2],16)
    if n >= 0 and n <= 0xffffff:
      if c[0] in color:
        editor.styleSetFore(color[c[0]], ((n & 0xff0000) >> (4*4),(n & 0xff00) >> (2*4),n & 0xff))
      else:
        color[c[0]]=sc
        editor.styleSetFore(sc, ((n & 0xff0000) >> (4*4),(n & 0xff00) >> (2*4),n & 0xff))
        sc += 1
      for i in range(editor.getLineCount()):
        processLine(i)

def processLine(line):
  global color
  l = editor.getLine(line)
  w = re.split('[ ()\[\]\{\}\-\+=]',l)

  p = editor.positionFromLine(line)
  for ow in w:
    if ow in color:
      editor.startStyling(p, 0xff)
      editor.setStyling(len(ow), color[ow])
    p += len(ow) + 1
    if w[-1] == ow:
      p -= 1

def dosm(args):
  line = editor.lineFromPosition(editor.getCurrentPos())
  getColor(line)
  processLine(line)

def readAll(args = 0):
  editor.setLexer(LEXER.CONTAINER)
  global color 
  color = {}
  global sc 
  sc = 1 
  for i in range(editor.getLineCount()):
    getColor(i)
    processLine(i)

def kill(args):
  console.write("killed\n")
  editor.clearCallbacks(dosm, [SCINTILLANOTIFICATION.CHARADDED])
  editor.clearCallbacks(kill, [SCINTILLANOTIFICATION.DOUBLECLICK])
  return 0

readAll()

def bc(args):
  console.write("buffer changed\n")

editor.callback(dosm, [SCINTILLANOTIFICATION.CHARADDED])

notepad.callback(readAll, [NOTIFICATION.BUFFERACTIVATED])

editor.callback(kill, [SCINTILLANOTIFICATION.DOUBLECLICK])