def handleAtCommandNode (self,p): '''Handle @command name [@key[=]shortcut].''' c = self.c ; k = c.keyHandler ; h = p.headString() if not h.strip(): return #@ << get the commandName and optional shortcut >> #@+node:ekr.20060328125248.11:<< get the commandName and optional shortcut >> tag = '@command' ; shortcut = None i = h.find('@key') if i > -1: commandName = h[len(tag):i].strip() j = g.skip_ws(h,i+len('@key')) if g.match(h,j,'='): # Make the equal sign optional. j += 1 shortcut = h[j:].strip() else: commandName = h[len(tag):].strip() #@nonl #@-node:ekr.20060328125248.11:<< get the commandName and optional shortcut >> #@nl def atCommandCallback (event=None,c=c,p=p.copy()): # The 'end-of-script command messes up tabs. c.executeScript(p=p,silent=True) k.registerCommand(commandName,shortcut,atCommandCallback,verbose=True)
def createMinibufferCommand (self,p): '''Register a minibuffer command. p.headString has the form @command name [@key=shortcut].''' c = self.c ; k = c.keyHandler ; h = p.headString() if not h.strip(): return #@ << get the commandName and optional shortcut >> #@+node:ekr.20060328125248.11:<< get the commandName and optional shortcut >> tag = '@command' ; shortcut = None i = h.find('@key') if i > -1: commandName = h[len(tag):i].strip() j = g.skip_ws(h,i+len('@key')) if g.match(h,j,'='): shortcut = h[j+1:].strip() else: commandName = h[len(tag):].strip() # g.trace(commandName,'shortcut',shortcut) #@nonl #@-node:ekr.20060328125248.11:<< get the commandName and optional shortcut >> #@nl def atCommandCallback (event=None,c=c,p=p.copy()): # The 'end-of-script command messes up tabs. c.executeScript(p=p,silent=True) k.registerCommand(commandName,shortcut,atCommandCallback)
def doStartLine (self): before = self.s[0:self.scol] i = g.skip_ws(before,0) self.ws = self.s[0:i] if self.ws: self.array.append(self.ws)
def isLeoHeader(self, s): tag = "@+leo" j = string.find(s, tag) if j > 0: i = g.skip_ws(s, 0) if i < j: return s[i:j] else: return None else: return None
def isLeoHeader (self,s): tag = "@+leo" j = string.find(s,tag) if j > 0: i = g.skip_ws(s,0) if i < j: return s[i:j] else: return None else: return None
def doOp (self): val = self.val outer = self.lineParenLevel <= 0 or (self.parenLevel == 0 and self.squareBracketLevel == 0) # New in Python 2.4: '@' is an operator, not an error token. if self.val == '@': self.array.append(self.val) # Preserve whitespace after @. i = g.skip_ws(self.s,self.scol+1) ws = self.s[self.scol+1:i] if ws: self.array.append(ws) elif val == '(': # Nothing added; strip leading blank before function calls but not before Python keywords. strip = self.lastName=='name' and not keyword.iskeyword(self.prevName) self.put('(',strip=strip) self.parenLevel += 1 ; self.lineParenLevel += 1 elif val in ('=','==','+=','-=','!=','<=','>=','<','>','<>','*','**','+','&','|','/','//'): # Add leading and trailing blank in outer mode. s = g.choose(outer,' %s ','%s') self.put(s % val) elif val in ('^','~','{','['): # Add leading blank in outer mode. s = g.choose(outer,' %s','%s') self.put(s % val) if val == '[': self.squareBracketLevel += 1 elif val in (',',':','}',']',')'): # Add trailing blank in outer mode. s = g.choose(outer,'%s ','%s') self.put(s % val) if val == ']': self.squareBracketLevel -= 1 if val == ')': self.parenLevel -= 1 ; self.lineParenLevel -= 1 # ----- no difference between outer and inner modes --- elif val in (';','%'): # Add leading and trailing blank. self.put(' %s ' % val) elif val == '>>': # Add leading blank. self.put(' %s' % val) elif val == '<<': # Add trailing blank. self.put('%s ' % val) elif val in ('-'): # Could be binary or unary. Or could be a hyphen in a section name. # Add preceding blank only for non-id's. if outer: if self.array: prev = self.array[-1].rstrip() if prev and prev[-1] not in string.digits + string.letters: self.put(' %s' % val) else: self.put(val) else: self.put(val) # Try to leave whitespace unchanged. else: self.put(val) else: self.put(val)
def doErrorToken (self): self.array.append(self.val) if self.val == '@': # Preserve whitespace after @. i = g.skip_ws(self.s,self.scol+1) ws = self.s[self.scol+1:i] if ws: self.array.append(ws)
def compare_lines(self, s1, s2): if self.ignoreLeadingWhitespace: s1 = string.lstrip(s1) s2 = string.lstrip(s2) if self.ignoreInteriorWhitespace: k1 = g.skip_ws(s1, 0) k2 = g.skip_ws(s2, 0) ws1 = s1[:k1] ws2 = s2[:k2] tail1 = s1[k1:] tail2 = s2[k2:] tail1 = string.replace(tail1, " ", "") tail1 = string.replace(tail1, "\t", "") tail2 = string.replace(tail2, " ", "") tail2 = string.replace(tail2, "\t", "") s1 = ws1 + tail1 s2 = ws2 + tail2 return s1 == s2
def compare_lines (self,s1,s2): if self.ignoreLeadingWhitespace: s1 = string.lstrip(s1) s2 = string.lstrip(s2) if self.ignoreInteriorWhitespace: k1 = g.skip_ws(s1,0) k2 = g.skip_ws(s2,0) ws1 = s1[:k1] ws2 = s2[:k2] tail1 = s1[k1:] tail2 = s2[k2:] tail1 = string.replace(tail1," ","") tail1 = string.replace(tail1,"\t","") tail2 = string.replace(tail2," ","") tail2 = string.replace(tail2,"\t","") s1 = ws1 + tail1 s2 = ws2 + tail2 return s1 == s2
def getShortcut(self,h): '''Returns the keyboard shortcut from the given headline string''' shortcut = None i = h.find('@key') if i > -1: j = g.skip_ws(h,i+len('@key')) if g.match(h,j,'='): shortcut = h[j+1:].strip() return shortcut
def scanPluginDirectives (tag, keywords): """Add a tuple (d,v,s,k) to list for every directive d found""" global directives keys = ("c","v","s","old_dict","dict","pluginsList") c,v,s,old_dict,dict,pluginsList = [keywords.get(key) for key in keys] for d in directives: if not old_dict.has_key(d) and dict.has_key(d): # Point k at whatever follows the directive. k = dict[d] k += 1 + len(d) # Skip @directive k = g.skip_ws(s,k) # Skip whitespace # g.trace(`d`,`k`) pluginsList.append((d,v,s,k),)
def isSentinel(self, s, sentinelComment): i = g.skip_ws(s, 0) return g.match(s, i, sentinelComment)
def isSentinel (self,s,sentinelComment): i = g.skip_ws(s,0) return g.match(s,i,sentinelComment)