def GetAutoCompList(self, command): """Returns the list of possible completions for a command string. If namespace is not specified the lookup is based on the locals namespace @param command: commadn lookup is done on @keyword namespace: namespace to do lookup in """ if command in [None, u'']: return list() buff = self.GetBuffer() cpos = buff.GetCurrentPos() # Check if we are in a php region or not if buff.GetStyleAt(cpos) not in HTML_AREA: return list() cline = buff.GetCurrentLine() tmp = buff.GetLine(cline).rstrip() # Check if we are completing an open tag if tmp.endswith('<'): if buff.GetLexer() == wx.stc.STC_LEX_XML: taglst = _FindXmlTags(buff.GetText()) else: taglst = TAGS return completer.CreateSymbols(taglst, completer.TYPE_ELEMENT) tmp = tmp.rstrip('>').rstrip() if len(tmp) and (tmp[-1] in '"\' \t' or tmp[-1].isalpha()): for line in range(cline, -1, -1): txt = buff.GetLine(line) if line == cline: txt = txt[:buff.GetColumn(cpos)] idx = txt.rfind('<') if idx != -1: parts = txt[idx:].lstrip('<').strip().split() if len(parts): tag = parts[0].rstrip('>') if len(tag) and \ tag not in ('img', 'br', '?php', '?xml', '?') and \ not tag[0] in ('!', '/'): rtag = u"</" + tag + u">" if tag in NLINE_TAGS: buff.BeginUndoAction() buff.AutoIndent() buff.BackTab() buff.EndUndoAction() if not parts[-1].endswith('>'): rtag = u">" + rtag return [ completer.Symbol(rtag, completer.TYPE_ELEMENT) ] break return list()
def GetAutoCompList(self, command): """Returns the list of possible completions for a command string. If namespace is not specified the lookup is based on the locals namespace @param command: command lookup is done on @keyword namespace: namespace to do lookup in """ buff = self.GetBuffer() keywords = buff.GetKeywords() if command in [None, u'']: return completer.CreateSymbols(keywords, completer.TYPE_UNKNOWN) cpos = buff.GetCurrentPos() cline = buff.GetCurrentLine() lstart = buff.PositionFromLine(cline) tmp = buff.GetTextRange(lstart, cpos).rstrip() # Check for the case of a pseudo class if IsPsuedoClass(command, tmp): return PSUEDO_SYMBOLS # Give some help on some common properties if tmp.endswith(u':'): word = GetWordLeft(tmp.rstrip().rstrip(u':')) comps = PROP_OPTS.get(word, list()) comps = list(set(comps)) comps.sort() return completer.CreateSymbols(comps, completer.TYPE_PROPERTY) # Look for if we are completing a tag class if tmp.endswith(u'.'): classes = list() if not buff.IsString(cpos): txt = buff.GetText() txt = RE_CSS_COMMENT.sub(u'', txt) txt = RE_CSS_BLOCK.sub(u' ', txt) for token in txt.split(): if u'.' in token: classes.append(token.split(u'.', 1)[-1]) classes = list(set(classes)) classes.sort() return completer.CreateSymbols(classes, completer.TYPE_CLASS) return completer.CreateSymbols(keywords, completer.TYPE_UNKNOWN)
def GetAutoCompList(self, command): """Returns the list of possible completions for a command string. @param command: command lookup is done on """ if command in [None, u'']: return list() buff = self.GetBuffer() cpos = buff.GetCurrentPos() # Check if we are in a php region or not if buff.GetStyleAt(cpos) not in HTML_AREA: return list() # Get current context cline = buff.GetCurrentLine() ccol = buff.GetColumn(cpos) tmp = buff.GetLine(cline).rstrip() if ccol < len(tmp): tmp = tmp[:ccol].rstrip() # Check if we are completing an open tag (i.e < was typed) if tmp.endswith('<'): if buff.GetLexer() == wx.stc.STC_LEX_XML: taglst = _FindXmlTags(buff.GetText()) else: taglst = TAGS return completer.CreateSymbols(taglst, completer.TYPE_ELEMENT) # Check for a self closing tag (i.e />) endchk = tmp.strip().replace(u" ", u"").replace(u"\t", u"") if endchk.endswith(u"/>"): return list() # Try to autocomplete a closing tag (if necessary) tmp = tmp.rstrip('>').rstrip() if len(tmp) and (tmp[-1] in '"\' \t' or tmp[-1].isalpha()): # Walk backwards from the current line for line in range(cline, -1, -1): txt = buff.GetLine(line) if line == cline: txt = txt[:buff.GetColumn(cpos)] idx = txt.rfind('<') if idx != -1: parts = txt[idx:].lstrip('<').strip().split() if len(parts): tag = parts[0].rstrip('>') if len(tag) and \ tag not in ('img', 'br', '?php', '?xml', '?') and \ not tag[0] in ('!', '/'): rtag = u"</" + tag + u">" if not parts[-1].endswith('>'): rtag = u">" + rtag return [ completer.Symbol(rtag, completer.TYPE_ELEMENT) ] break return list()
# Imports import re import wx import wx.stc # Local Imports import completer #--------------------------------------------------------------------------# # Regular Expressions RE_LINK_PSEUDO = re.compile("a:(link|visited|active|hover|focus)*") RE_CSS_COMMENT = re.compile("\/\*[^*]*\*+([^/][^*]*\*+)*\/") RE_CSS_BLOCK = re.compile("\{[^}]*\}") PSUEDO_SYMBOLS = completer.CreateSymbols( [u'active', u'focus', u'hover', u'link', u'visited'], ) #--------------------------------------------------------------------------# class Completer(completer.BaseCompleter): """CSS Code completion provider""" def __init__(self, stc_buffer): super(Completer, self).__init__(stc_buffer) # Setup self.SetAutoCompKeys([ord(':'), ord('.')]) self.SetAutoCompStops(' {}#') self.SetAutoCompFillups('') self.SetCallTipKeys([ ord('('),