How to use the leo.core.leoGlobals.match_word 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 / core / leoRst.py View on Github external
if line.startswith('@doc'):
                s = line[4:].lstrip()
            elif line.startswith('@'):
                s = line[1:].lstrip()
            else:
                s = ''
            # New in Leo 4.4.4: remove these special tags.
            for tag in ('@rst-options', '@rst-option', '@rst-markup'):
                if g.match_word(s, 0, tag):
                    s = s[len(tag) :].strip()
            if s.strip():
                result.append(s)
        #@-<< Append whatever follows @doc or @space to result >>
        while n < len(lines):
            s = lines[n]; n += 1
            if g.match_word(s, 0, '@code') or g.match_word(s, 0, '@c'):
                break
            result.append(s)
        return n, result
    #@+node:ekr.20090502071837.81: *6* rst.handleSpecialDocParts
github leo-editor / leo-editor / leo / plugins / rst3.py View on Github external
elif line.startswith('@'):
                s = line[1:].lstrip()
            else:
                s = ''

            # New in Leo 4.4.4: remove these special tags.
            for tag in ('@rst-options','@rst-option','@rst-markup'):
                if g.match_word(s,0,tag):
                    s = s[len(tag):].strip()

            if s.strip():
                result.append(s)
        #@-<< Append whatever follows @doc or @space to result >>
        while n < len(lines):
            s = lines [n] ; n += 1
            if g.match_word(s,0,'@code') or g.match_word(s,0,'@c'):
                break
            result.append(s)
        return n, result
    #@+node:ekr.20050811102607: *4* skip_literal_block
github leo-editor / leo-editor / leo / core / leoImport.py View on Github external
def copyPart(self, s, i, result):

        lb = "@<" if self.webType == "cweb" else "<<"
        rb = "@>" if self.webType == "cweb" else ">>"
        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"):
github leo-editor / leo-editor / leo / commands / editFileCommands.py View on Github external
def cleanAtCleanFiles(self, event):
        """Adjust whitespace in all @clean files."""
        c = self.c
        undoType = 'clean-@clean-files'
        c.undoer.beforeChangeGroup(c.p, undoType, verboseUndoGroup=True)
        total = 0
        for p in c.all_unique_positions():
            if g.match_word(p.h, 0, '@clean') and p.h.rstrip().endswith('.py'):
                n = 0
                for p2 in p.subtree():
                    bunch2 = c.undoer.beforeChangeNodeContents(p2, oldBody=p2.b)
                    if self.cleanAtCleanNode(p2, undoType):
                        n += 1
                        total += 1
                        c.undoer.afterChangeNodeContents(p2, undoType, bunch2)
                g.es_print(f"{n} node{g.plural(n)} {p.h}")
        if total > 0:
            c.undoer.afterChangeGroup(c.p, undoType)
        g.es_print(f"{total} total node{g.plural(total)}")
    #@+node:ekr.20170806094319.8: *4* efc.cleanAtCleanNode
github leo-editor / leo-editor / leo / plugins / importers / basescanner.py View on Github external
def skipBlock(self, s, i, delim1=None, delim2=None):
        '''Skip from the opening delim to *past* the matching closing delim.

        If no matching is found i is set to len(s)'''
        trace = False and not g.unitTesting
        verbose = False
        if delim1 is None: delim1 = self.blockDelim1
        if delim2 is None: delim2 = self.blockDelim2
        match1 = g.match if len(delim1) == 1 else g.match_word
        match2 = g.match if len(delim2) == 1 else g.match_word
        assert match1(s, i, delim1)
        level, start, startIndent = 0, i, self.startSigIndent
        if trace and verbose:
            g.trace('***', 'startIndent', startIndent)
        while i < len(s):
            progress = i
            if g.is_nl(s, i):
                backslashNewline = i > 0 and g.match(s, i - 1, '\\\n')
                i = g.skip_nl(s, i)
                if not backslashNewline and not g.is_nl(s, i):
                    j, indent = g.skip_leading_ws_with_indent(s, i, self.tab_width)
                    line = g.get_line(s, j)
                    if trace and verbose: g.trace('indent', indent, line)
                    if indent < startIndent and line.strip():
                        # An non-empty underindented line.
github leo-editor / leo-editor / leo / core / leoMarkup.py View on Github external
def filename(self, p):
        """Return the filename of the @adoc, @pandoc or @sphinx node, or None."""
        kind = self.kind
        h = p.h.rstrip()
        if kind == 'adoc':
            m = self.adoc_pattern.match(h)
            if m:
                prefix = m.group(1)
                return h[1+len(prefix):].strip()
            return None
        if kind in ('pandoc', 'sphinx'):
            prefix = f"@{kind}"
            if g.match_word(h, 0, prefix):
                return h[len(prefix):].strip()
            return None
        g.trace('BAD KIND', kind)
        return None
    #@+node:ekr.20191007053522.1: *4* markup.compute_opath
github leo-editor / leo-editor / leo / core / format-code.py View on Github external
after = s[n:].strip()
                part_lines = g.choose(after,[after],[])
            elif s.startswith('@ @rst-option'):
                if part_lines: parts.append((kind,part_lines[:]),)
                kind,part_lines = '@rst-option',[s] # part_lines will be ignored.
            elif s.startswith('@ ') or s.startswith('@\n') or s.startswith('@doc'):
                if showDocsAsParagraphs:
                    if part_lines: parts.append((kind,part_lines[:]),)
                    kind = '@doc'
                    # Put only what follows @ or @doc
                    n = g.choose(s.startswith('@doc'),4,1)
                    after = s[n:].lstrip()
                    part_lines = g.choose(after,[after],[])
                else:
                    part_lines.append(s) # still in code mode.
            elif g.match_word(s,0,'@c') and kind != 'code':
                if kind == '@doc' and not showDocsAsParagraphs:
                        part_lines.append(s) # Show the @c as code.
                parts.append((kind,part_lines[:]),)
                kind,part_lines = 'code',[]
            else:
                part_lines.append(s)

        if part_lines:
            parts.append((kind,part_lines[:]),)

        return parts
    #@+node:ekr.20100811091636.6004: *5* write_code_block
github leo-editor / leo-editor / leo / plugins / screenshots.py View on Github external
def get_callouts(self, p):
        '''Return the list of callouts from the
        direct children that are @callout nodes.'''
        sc = self
        aList = []
        for child in p.children():
            if g.match_word(child.h, 0, '@callout'):
                callout = sc.get_callout(child)
                if callout: aList.append(callout)
        return aList
    #@+node:ekr.20100909121239.6096: *6* get_callout
github leo-editor / leo-editor / leo / core / leoConfig.py View on Github external
def doPopupItems(self, p, aList):
        p = p.copy(); after = p.nodeAfterTree()
        p.moveToThreadNext()
        while p and p != after:
            h = p.h
            for tag in ('@menu', '@item'):
                if g.match_word(h, 0, tag):
                    itemName = h[len(tag) :].strip()
                    if itemName:
                        if tag == '@menu':
                            aList2 = []
                            kind = f"{itemName}"
                            body = p.b
                            self.doPopupItems(p, aList2)
                            aList.append((kind + '\n' + body, aList2),)
                            p.moveToNodeAfterTree()
                            break
                        else:
                            kind = tag
                            head = itemName
                            body = p.b
                            aList.append((head, body),)
                            p.moveToThreadNext()
github leo-editor / leo-editor / leo / plugins / rClick.py View on Github external
def doPopupItems (self,p,aList):

        p = p.copy() ; after = p.nodeAfterTree()
        p.moveToThreadNext()
        while p and p != after:
            h = p.h
            for tag in ('@menu','@item'):
                if g.match_word(h,0,tag):
                    itemName = h[len(tag):].strip()
                    if itemName:
                        if tag == '@menu':
                            aList2 = []
                            kind = '%s' % itemName
                            body = p.b
                            self.doPopupItems(p,aList2)
                            aList.append((kind + '\n' + body, aList2),)
                            p.moveToNodeAfterTree()
                            break
                        else:
                            kind = tag
                            head = itemName
                            body = p.b
                            aList.append((head,body),)
                            p.moveToThreadNext()