How to use the leo.core.leoGlobals.splitLines 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 / writers / treepad.py View on Github external
def write(self, root):
        """Write the entire @auto tree."""
        self.put("")
        root_level = root.level()
        for p in root.self_and_subtree():
            h = 'Root' if p.v == root.v else p.h
            indent = p.level() - root_level
            self.put('dt=Text')
            self.put('')
            self.put(h)
            self.put(str(indent))
            for s in g.splitLines(p.b):
                if not g.isDirective(s):
                    self.put(s)
            self.put(' 5P9i0s8y19Z')
        root.setVisited()
        return True
    #@-others
github leo-editor / leo-editor / leo / core / leoConfig.py View on Github external
def doData(self, p, kind, name, val):
        # New in Leo 4.11: do not strip lines.
        # New in Leo 4.12.1: strip *nothing* here.
        # New in Leo 4.12.1: allow composition of nodes:
        # - Append all text in descendants in outline order.
        # - Ensure all fragments end with a newline.
        data = g.splitLines(p.b)
        for p2 in p.subtree():
            if p2.b and not p2.h.startswith('@'):
                data.extend(g.splitLines(p2.b))
                if not p2.b.endswith('\n'):
                    data.append('\n')
        self.set(p, kind, name, data)
    #@+node:ekr.20131114051702.16545: *4* pbc.doOutlineData & helper
github leo-editor / leo-editor / leo / core / leoRst.py View on Github external
def expandSectionRefs(self, lines, p, seen):
        """Expand section references in lines."""
        result = []
        for s in lines:
            name = self.isSectionRef(s)
            if name:
                p2 = self.findSectionDef(name, p)
                if p2:
                    g.trace(f"expanding: {name} from {p2.h}")
                    result.append(s)  # Append the section reference line.
                    lines2 = g.splitLines(p2.b)
                    if self.getOption(p, 'expand_noweb_recursively'):
                        if name in seen:
                            pass  # Prevent unbounded recursion
                        else:
                            seen.append(name)
                            result.extend(self.expandSectionRefs(lines2, p, seen))
                    else:
                        result.extend(lines2)
                else:
                    # Undefined reference.
                    result.append(s)
            else:
                result.append(s)
        return result
    #@+node:ekr.20110610144305.6751: *7* rst.findSectionDef
github leo-editor / leo-editor / leo / core / leoRst.py View on Github external
def scanOptions(self, p, s):
        """Return a dictionary containing all the options in s."""
        d = {}
        for line in g.splitLines(s):
            d2 = self.scanOption(p, line)
            if d2: d.update(d2)
        return d
    #@+node:ekr.20090502071837.52: *6* rst.scanOption & helper
github leo-editor / leo-editor / leo / plugins / importers / python.py View on Github external
def gen_lines(self, s, parent):
        '''
        Non-recursively parse all lines of s into parent, creating descendant
        nodes as needed.
        '''
        self.tail_p = None
        prev_state = self.state_class()
        target = PythonTarget(parent, prev_state)
        stack = [target, target]
        self.decorator_lines = []
        self.inject_lines_ivar(parent)
        lines = g.splitLines(s)
        self.skip = 0
        first = True
        for i, line in enumerate(lines):
            new_state = self.scan_line(line, prev_state)
            top = stack[-1]
            if self.skip > 0:
                self.skip -= 1
            elif self.starts_decorator(i, lines, new_state):
                pass # Sets self.skip and self.decorator_lines.
            elif self.starts_block(i, lines, new_state, prev_state, stack):
                first = False
                self.tail_p = None
                self.start_new_block(i, lines, new_state, prev_state, stack)
            elif first:
                if self.is_ws_line(line):
                    p = self.tail_p or top.p
github leo-editor / leo-editor / leo / core / leoFileCommands.py View on Github external
def getPublicLeoFile():
            fc.outputFile = g.FileLikeObject()
            fc.putProlog()
            fc.putHeader()
            fc.putGlobals()
            fc.putPrefs()
            fc.putFindSettings()
            fname = putVnodes2()
            fc.putTnodes()
            fc.putPostlog()
            return fname, fc.outputFile.getvalue()
        #@-others
        c.endEditing()
        for v in c.hiddenRootNode.children:
            if v.h == PRIVAREA:
                fileName = g.splitLines(v.b)[0].strip()
                break
        else:
            fileName = c.mFileName
        # New in 4.2.  Return ok flag so shutdown logic knows if all went well.
        ok = g.doHook("save1", c=c, p=p, fileName=fileName)
        if ok is None:
            fileName, content = getPublicLeoFile()
            fileName = g.os_path_finalize_join(c.openDirectory, fileName)
            with open(fileName, 'w', encoding="utf-8", newline='\n') as out:
                out.write(content)
            g.es('updated reference file:',
                  g.shortFileName(fileName))
        g.doHook("save2", c=c, p=p, fileName=fileName)
        return ok
    #@+node:ekr.20031218072017.3043: *5* fc.saveAs
github leo-editor / leo-editor / leo / core / leoAst.py View on Github external
def __init__(self, s, tokens):
        """Ctor for TokenSync class."""
        assert isinstance(tokens, list)  # Not a generator.
        self.s = s
        self.first_leading_line = None
        self.lines = [z.rstrip() for z in g.splitLines(s)]
        # Order is important from here on...
        self.nl_token = self.make_nl_token()
        self.line_tokens = self.make_line_tokens(tokens)
        self.blank_lines = self.make_blank_lines()
        self.string_tokens = self.make_string_tokens()
        self.ignored_lines = self.make_ignored_lines()
    #@+node:ekr.20160225102931.3: *4* ts.make_blank_lines
github leo-editor / leo-editor / leo / commands / editFileCommands.py View on Github external
def create_compare_node(self, c1, c2, d, kind, rev1, rev2):
        """Create nodes describing the changes."""
        if not d:
            return
        parent = self.file_node.insertAsLastChild()
        parent.setHeadString(kind)
        for key in d:
            if kind.lower() == 'changed':
                v1, v2 = d.get(key)
                # Organizer node: contains diff
                organizer = parent.insertAsLastChild()
                organizer.h = v2.h
                body = list(difflib.unified_diff(
                    g.splitLines(v1.b),
                    g.splitLines(v2.b),
                    rev1 or 'uncommitted',
                    rev2 or 'uncommitted',
                ))
                if ''.join(body).strip():
                    body.insert(0, '@ignore\n@nosearch\n@language patch\n')
                    body.append(f"@language {c2.target_language}\n")
                else:
                    body = ['Only headline has changed']
                organizer.b = ''.join(body)
                # Node 2: Old node
                p2 = organizer.insertAsLastChild()
                p2.h = 'Old:' + v1.h
                p2.b = v1.b
                # Node 3: New node
                assert v1.fileIndex == v2.fileIndex
                p_in_c = self.find_gnx(self.c, v1.fileIndex)
github leo-editor / leo-editor / leo / plugins / tables.py View on Github external
def get_table(self, ch, w):
        '''Return i, lines, if w's insert point is inside a table.'''
        s = w.getAllText()
        lines = g.splitLines(s)
        ins = w.getInsertPoint()
        i_row1, i_col1 = g.convertPythonIndexToRowCol(s, ins)
        s1 = lines[i_row1] if i_row1 < len(lines) else ''
        starts_row1 = ch in ('|', 'return') and not s1[:i_col1].strip()
        if self.enabled and g.isTextWrapper(w):
            i1, i2 = None, None
            for i, s in enumerate(lines):
                is_row = s.strip().startswith('|')
                if i == i_row1:
                    if is_row or starts_row1:
                        if i1 is None:
                            i1 = i2 = i # Selected line starts the table.
                        else:
                            pass # Table head already found.
                    elif i1 is None:
                        return -1, s1, []
github leo-editor / leo-editor / leo / core / leoConfig.py View on Github external
def doEnabledPlugins(self, p, kind, name, val):
        c = self.c
        s = p.b
        # This setting is handled differently from all other settings,
        # because the last setting must be retrieved before any commander exists.
        # 2011/09/04: Remove comments, comment lines and blank lines.
        aList, lines = [], g.splitLines(s)
        for s in lines:
            i = s.find('#')
            if i > -1: s = s[:i] + '\n'  # 2011/09/29: must add newline back in.
            if s.strip(): aList.append(s.lstrip())
        s = ''.join(aList)
        # Set the global config ivars.
        g.app.config.enabledPluginsString = s
        g.app.config.enabledPluginsFileName = c.shortFileName(
            ) if c else ''
    #@+node:ekr.20041120094940.6: *4* pbc.doFloat