How to use the leo.core.leoGlobals.match function in leo

To help you get started, we’ve selected a few leo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github leo-editor / leo-editor / leo / plugins / mod_scripting.py View on Github external
def getArgs(self, p):
        '''Return the list of @args field of p.h.'''
        args = []
        if not p:
            return args
        h, tag = p.h, '@args'
        i = h.find(tag)
        if i > -1:
            j = g.skip_ws(h, i + len(tag))
            # 2011/10/16: Make '=' sign optional.
            if g.match(h, j, '='): j += 1
            if 0:
                s = h[j + 1:].strip()
            else: # new logic 1/3/2014 Jake Peck
                k = h.find('@', j + 1)
                if k == -1: k = len(h)
                s = h[j: k].strip()
            args = s.split(',')
            args = [z.strip() for z in args]
        # if args: g.trace(args)
        return args
    #@+node:ekr.20060328125248.15: *4* sc.getButtonText
github leo-editor / leo-editor / leo / commands / commanderEditCommands.py View on Github external
def rp_wrap_all_lines(c, indents, leading_ws, lines, pageWidth):
    """Compute the result of wrapping all lines."""
    trailingNL = lines and lines[-1].endswith('\n')
    lines = [z[:-1] if z.endswith('\n') else z for z in lines]
    if lines:  # Bug fix: 2013/12/22.
        s = lines[0]
        if startsParagraph(s):
            # Adjust indents[1]
            # Similar to code in startsParagraph(s)
            i = 0
            if s[0].isdigit():
                while i < len(s) and s[i].isdigit():
                    i += 1
                if g.match(s, i, ')') or g.match(s, i, '.'):
                    i += 1
            elif s[0].isalpha():
                if g.match(s, 1, ')') or g.match(s, 1, '.'):
                    i = 2
            elif s[0] == '-':
                i = 1
            # Never decrease indentation.
            i = g.skip_ws(s, i + 1)
            if i > indents[1]:
                indents[1] = i
                leading_ws[1] = ' ' * i
    # Wrap the lines, decreasing the page width by indent.
    result = g.wrap_lines(lines,
        pageWidth - indents[1],
        pageWidth - indents[0])
    # prefix with the leading whitespace, if any
github leo-editor / leo-editor / leo / commands / commanderEditCommands.py View on Github external
def startsParagraph(s):
    """Return True if line s starts a paragraph."""
    if not s.strip():
        val = False
    elif s.strip() in ('"""', "'''"):
        val = True
    elif s[0].isdigit():
        i = 0
        while i < len(s) and s[i].isdigit():
            i += 1
        val = g.match(s, i, ')') or g.match(s, i, '.')
    elif s[0].isalpha():
        # Careful: single characters only.
        # This could cause problems in some situations.
        val = (
            (g.match(s, 1, ')') or g.match(s, 1, '.')) and
            (len(s) < 2 or s[2] in (' \t\n')))
    else:
        val = s.startswith('@') or s.startswith('-')
    return val
#@+node:ekr.20171123135625.12: ** c_ec.show/hide/toggleInvisibles
github leo-editor / leo-editor / leo / plugins / run_nodes.py View on Github external
return

    if path:
        if os.access(path,os.F_OK) == 1:
            WorkDir=os.getcwd()
            os.chdir(path)
        else:
            g.error("@run: invalid path: %s" % (path))
            return
    #@-<< set the working directory or return >>
    #@+<< set the command, removing all args following '#' >>
    #@+node:ekr.20040910100935: *3* << set the command, removing all args following '#' >>
    command = fname

    for arg in args[1:]:
        if g.match(arg,0,'#'):
            break
        else:
            command += ' ' + arg.strip()
    #@-<< set the command, removing all args following '#' >>
    if not command.strip():
        return
    RunNode=p
    args = []
    #@+<< append arguments from child nodes to command >>
    #@+node:ekr.20040910095147: *3* << append arguments from child nodes to command >>
    for child in p.children():
        h = child.h
        if g.match_word(h,0,"@arg"):
            arg = h[4:].strip()
            args.append(arg)
        else:
github leo-editor / leo-editor / leo / core / leoImport.py View on Github external
def headlineLevel(self, s):
        """return the headline level of s,or -1 if the string is not a MORE headline."""
        level = 0; i = 0
        while i < len(s) and s[i] in ' \t':  # 2016/10/06: allow blanks or tabs.
            level += 1
            i += 1
        plusFlag = g.match(s, i, "+")
        if g.match(s, i, "+ ") or g.match(s, i, "- "):
            return level, plusFlag
        return -1, plusFlag
    #@+node:ekr.20031218072017.3223: *3* MORE.check & check_lines
github leo-editor / leo-editor / leo / plugins / mod_scripting.py View on Github external
def getShortcut(self, h):
        '''Return 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, '='): j += 1
            if 0:
                shortcut = h[j:].strip()
            else: # new logic 1/3/2014 Jake Peck
                k = h.find('@', j + 1)
                if k == -1: k = len(h)
                shortcut = h[j: k].strip()
        return shortcut
    #@+node:ekr.20150402042350.1: *4* sc.getScript
github leo-editor / leo-editor / leo / plugins / importers / basescanner.py View on Github external
elif self.hasRegex and self.startsRegex(s, i):
                i = self.skipRegex(s, i)
            elif self.startsClass(s, i): # Sets sigStart,sigEnd & codeEnd ivars.
                putRef = True
                if bodyIndent is None: bodyIndent = self.getIndent(s, i)
                end2 = self.codeEnd # putClass may change codeEnd ivar.
                self.putClass(s, i, self.sigEnd, self.codeEnd, start, parent)
                i = start = end2
            elif self.startsFunction(s, i): # Sets sigStart,sigEnd & codeEnd ivars.
                putRef = True
                if bodyIndent is None: bodyIndent = self.getIndent(s, i)
                self.putFunction(s, self.sigStart, self.codeEnd, start, parent)
                i = start = self.codeEnd
            elif self.startsId(s, i):
                i = self.skipId(s, i)
            elif kind == 'outer' and g.match(s, i, self.outerBlockDelim1): # Do this after testing for classes.
                # i1 = i # for debugging
                i = self.skipBlock(s, i, delim1=self.outerBlockDelim1, delim2=self.outerBlockDelim2)
                # Bug fix: 2007/11/8: do *not* set start: we are just skipping the block.
            else: i += 1
            if progress >= i:
                # g.pdb()
                i = self.skipBlock(s, i, delim1=self.outerBlockDelim1, delim2=self.outerBlockDelim2)
            assert progress < i, 'i: %d, ch: %s' % (i, repr(s[i]))
        return start, putRef, bodyIndent
    #@+node:ekr.20140727075002.18237: *4* BaseScanner.Parser skip methods
github leo-editor / leo-editor / leo / core / leoImport.py View on Github external
theType = self.webType
        while i < len(s):
            progress = j = i  # We should be at the start of a line here.
            i = g.skip_nl(s, i); i = g.skip_ws(s, i)
            if self.isDocStart(s, i):
                return i, result
            if (g.match_word(s, i, "@doc") or
                g.match_word(s, i, "@c") or
                g.match_word(s, i, "@root") or
                g.match_word(s, i, "@code")  # 2/25/03
            ):
                return i, result
             # 2019/09/12
            lt = "<<"
            rt = ">>="
            if g.match(s, i, lt) and g.find_on_line(s, i, rt) > -1:
                return i, result
            # Copy the entire line, escaping '@' and
            # Converting @others to < < @ others > >
            i = g.skip_line(s, j); line = s[j:i]
            if theType == "cweb":
                line = line.replace("@", "@@")
            else:
                j = g.skip_ws(line, 0)
                if g.match(line, j, "@others"):
                    line = line.replace("@others", lb + "@others" + rb)
                elif g.match(line, 0, "@"):
                    # Special case: do not escape @ %defs.
                    k = g.skip_ws(line, 1)
                    if not g.match(line, k, "%defs"):
                        line = "@" + line
            result += line
github leo-editor / leo-editor / leo / plugins / importers / basescanner.py View on Github external
self.errorLines.append(j)
                                self.underindentedLine(line)
            elif s[i] in (' ', '\t',):
                i += 1 # speed up the scan.
            elif self.startsComment(s, i):
                i = self.skipComment(s, i)
            elif self.startsString(s, i):
                i = self.skipString(s, i)
            elif match1(s, i, delim1):
                level += 1; i += len(delim1)
            elif match2(s, i, delim2):
                level -= 1; i += len(delim2)
                # Skip junk following Pascal 'end'
                for z in self.blockDelim2Cruft:
                    i2 = self.skipWs(s, i)
                    if g.match(s, i2, z):
                        i = i2 + len(z)
                        break
                if level <= 0:
                    # 2010/09/20
                    # Skip a single-line comment if it exists.
                    j = self.skipWs(s, i)
                    if (g.match(s, j, self.lineCommentDelim) or
                        g.match(s, j, self.lineCommentDelim2)
                    ):
                        i = g.skip_to_end_of_line(s, i)
                    if trace: g.trace('returns:\n\n%s\n\n' % s[start: i])
                    return i
            else: i += 1
            assert progress < i
        self.error('no block: %s' % self.root.h)
        if 1:
github leo-editor / leo-editor / leo / commands / commanderEditCommands.py View on Github external
i = g.skip_ws(s, 0)
            if g.match(s, i, d1b):
                result.append(s[:i] + s[i + n1b :])
            elif g.match(s, i, d1):
                result.append(s[:i] + s[i + n1 :])
            else:
                result.append(s)
    else:
        # Remove the block comment delimiters from each line.
        n2, n3 = len(d2), len(d3)
        for s in lines:
            i = g.skip_ws(s, 0)
            j = s.find(d3, i + n2)
            if g.match(s, i, d2) and j > -1:
                first = i + n2
                if g.match(s, first, ' '): first += 1
                last = j
                if g.match(s, last - 1, ' '): last -= 1
                result.append(s[:i] + s[first:last] + s[j + n3 :])
            else:
                result.append(s)
    result = ''.join(result)
    c.updateBodyPane(
        head, result, tail, undoType='Delete Comments', oldSel=None, oldYview=oldYview)
#@+node:ekr.20171123135625.54: ** c_ec.editHeadline