Ejemplo n.º 1
0
 def toAtEdit(self, p):
     '''Convert p from @auto to @edit.'''
     c = self.c
     w = c.frame.body.wrapper
     p.h = '@edit' + p.h[5:]
     # Compute the position of the present line within the *selected* node c.p
     ins = w.getInsertPoint()
     row, col = g.convertPythonIndexToRowCol(c.p.b, ins)
     # Ignore directive lines.
     directives = [z for z in g.splitLines(c.p.b)[:row] if g.isDirective(z)]
     row -= len(directives)
     row = max(0, row)
     # Count preceding lines from p to c.p, again ignoring directives.
     for p2 in p.self_and_subtree():
         if p2 == c.p:
             break
         lines = [z for z in g.splitLines(p2.b) if not g.isDirective(z)]
         row += len(lines)
     # Reload the file into a single node.
     c.selectPosition(p, enableRedrawFlag=False)
     c.refreshFromDisk()
     # Restore the line in the proper node.
     ins = g.convertRowColToPythonIndex(p.b, row+1, 0)
     w.setInsertPoint(ins)
     p.setDirty()
     c.setChanged()
     c.redraw()
     c.bodyWantsFocus()
Ejemplo n.º 2
0
 def toAtEdit(self, p):
     """Convert p from @auto to @edit."""
     c = self.c
     w = c.frame.body.wrapper
     p.h = '@edit' + p.h[5:]
     # Compute the position of the present line within the *selected* node c.p
     ins = w.getInsertPoint()
     row, col = g.convertPythonIndexToRowCol(c.p.b, ins)
     # Ignore directive lines.
     directives = [z for z in g.splitLines(c.p.b)[:row] if g.isDirective(z)]
     row -= len(directives)
     row = max(0, row)
     # Count preceding lines from p to c.p, again ignoring directives.
     for p2 in p.self_and_subtree(copy=False):
         if p2 == c.p:
             break
         lines = [z for z in g.splitLines(p2.b) if not g.isDirective(z)]
         row += len(lines)
     # Reload the file into a single node.
     c.selectPosition(p)
     c.refreshFromDisk()
     # Restore the line in the proper node.
     ins = g.convertRowColToPythonIndex(p.b, row + 1, 0)
     w.setInsertPoint(ins)
     p.setDirty()
     c.setChanged()
     c.redraw()
     c.bodyWantsFocus()
Ejemplo n.º 3
0
 def put_source(self, p, type_):
     '''Put the 'source' key for p.'''
     lines = [z for z in g.splitLines(p.b) if not g.isDirective(z)]
     # skip blank lines.
     i = 0
     while i < len(lines) and not lines[i].strip():
         i += 1
     lines = lines[i:]
     # skip trailing lines:
     i = len(lines)-1
     while i > 0 and not lines[i].strip():
         i -= 1
     lines = lines[:i+1]
     has_header = any([self.header_re.search(z) for z in lines])
     if lines and lines[-1].endswith('\n'):
         s_last = lines.pop()
         lines.append(s_last.rstrip())
     s = ''.join(lines)
     # Auto add headlines.
     if type_ == 'markdown' and not has_header:
         if 1: # Just put the headline.
             heading = p.h.strip()+'\n'
         else:
             # Not needed now that the import code sets headlines.
             n = min(6, self.level(p))
             heading = '<h%(level)s>%(headline)s</h%(level)s>\n' % {
                 'level': n,
                 'headline': p.h,
             }
         s = heading + s
         # Not completely accurate, but good for now.
     self.put_list('source', s or '# no code!')
Ejemplo n.º 4
0
 def put_source(self, p, type_):
     '''Put the 'source' key for p.'''
     lines = [z for z in g.splitLines(p.b) if not g.isDirective(z)]
     # skip blank lines.
     i = 0
     while i < len(lines) and not lines[i].strip():
         i += 1
     lines = lines[i:]
     # skip trailing lines:
     i = len(lines) - 1
     while i > 0 and not lines[i].strip():
         i -= 1
     lines = lines[:i + 1]
     has_header = any([self.header_re.search(z) for z in lines])
     if lines and lines[-1].endswith('\n'):
         s_last = lines.pop()
         lines.append(s_last.rstrip())
     s = ''.join(lines)
     # Auto add headlines.
     if type_ == 'markdown' and not has_header:
         if 1:  # Just put the headline.
             heading = p.h.strip() + '\n'
         else:
             # Not needed now that the import code sets headlines.
             n = min(6, self.level(p))
             heading = '<h%(level)s>%(headline)s</h%(level)s>\n' % {
                 'level': n,
                 'headline': p.h,
             }
         s = heading + s
         # Not completely accurate, but good for now.
     self.put_list('source', s or '# no code!')
Ejemplo n.º 5
0
 def check_line(p, line, st):
     # every child node ends with return
     #@+others
     #@+node:vitalije.20170726193840.1: *4* verbatim lines
     if is_verbatim(line):
         return 1, 2
     #@+node:vitalije.20170726193927.1: *4* others
     m = others_pat.match(line)
     if m:
         n = inc(st)
         for p1 in others_iterator(p):
             n = numerate_node(p1, n)
         n = inc(n)
         return (0, n - st) if delim_st else (0, n - st)
     #@+node:vitalije.20170726193858.1: *4* directives in clean
     if not delim_st and g.isDirective(line):
         return 0, 0
     #@+node:vitalije.20170726193908.1: *4* all
     if line.strip() == '@all':
         n = st + 1
         for p1 in p.subtree():
             n += 1
             if vlines(p1):
                 flines = []
                 for x in vlines(p1):
                     n += 1
                     if is_verbatim(x):
                         n += 1
                     flines.append(n)
                 flines.append(n + 1)
             else:
                 flines = [n]
             flines_data[pkey(p1)] = tuple(flines), n
         return 1, n - st
     #@+node:vitalije.20170726193920.1: *4* section reference
     m = section_pat.match(line)
     if m:
         p1 = g.findReference(m.group(2), p)
         if not p1:
             g.warning('unresolved section reference %s' % m.group(2))
             if delim_st:
                 return 0, 2
             return 0, 0
         n = inc(st)
         n = numerate_node(p1, n)
         n = inc(n)
         return (0, n - st) if delim_st else (0, n - st)
     #@+node:vitalije.20170726193933.1: *4* doc part
     if doc_pattern.match(line):
         if delim_st:
             return 0, 1
         return 0, 0
     #@+node:vitalije.20170726193941.1: *4* code part
     if code_pattern.match(line):
         if delim_st:
             return 0, 1
         return 0, 0
     #@-others
     # if we get here it is an ordinary line
     return 0, 1
Ejemplo n.º 6
0
 def check_line(p, line, st):
     # every child node ends with return
     #@+others
     #@+node:vitalije.20170726193840.1: *4* verbatim lines
     if is_verbatim(line):
         return 1, 2
     #@+node:vitalije.20170726193927.1: *4* others
     m = others_pat.match(line)
     if m:
         n = inc(st)
         for p1 in others_iterator(p):
             n = numerate_node(p1, n)
         n = inc(n)
         return (0, n-st) if delim_st else (0, n-st)
     #@+node:vitalije.20170726193858.1: *4* directives in clean
     if not delim_st and g.isDirective(line):
         return 0, 0
     #@+node:vitalije.20170726193908.1: *4* all
     if line.strip() == '@all':
         n = st + 1
         for p1 in p.subtree():
             n += 1
             if vlines(p1):
                 flines = []
                 for x in vlines(p1):
                     n += 1
                     if is_verbatim(x): n+=1
                     flines.append(n)
                 flines.append(n+1)
             else:
                 flines = [n]
             flines_data[pkey(p1)] = tuple(flines), n
         return 1, n - st
     #@+node:vitalije.20170726193920.1: *4* section reference
     m = section_pat.match(line)
     if m:
         p1 = g.findReference(m.group(2), p)
         if not p1:
             g.warning('unresolved section reference %s'%m.group(2))
             if delim_st:
                 return 0,2
             return 0,0
         n = inc(st)
         n = numerate_node(p1, n)
         n = inc(n)
         return (0, n-st) if delim_st else (0, n-st)
     #@+node:vitalije.20170726193933.1: *4* doc part
     if doc_pattern.match(line):
         if delim_en: return 0, 2
         return 1,1
     #@+node:vitalije.20170726193941.1: *4* code part
     if code_pattern.match(line):
         if delim_en: return 1, 2
         if delim_st: return 0, 1
         return 0, 0
     #@-others
     # if we get here it is an ordinary line
     return 0,1
Ejemplo n.º 7
0
 def write(self, root):
     """Write all the *descendants* of an .dart node."""
     root_level = root.level()
     for p in root.subtree():
         indent = p.level() - root_level
         self.put('%s %s' % ('*' * indent, p.h))
         for s in p.b.splitlines(False):
             if not g.isDirective(s):
                 self.put(s)
     root.setVisited()
     return True
Ejemplo n.º 8
0
 def write (self,root):
     """Write all the *descendants* of an .dart node."""
     root_level = root.level()
     for p in root.subtree():
         indent = p.level()-root_level
         self.put('%s %s' % ('*'*indent,p.h))
         for s in p.b.splitlines(False):
             if not g.isDirective(s):
                 self.put(s)
     root.setVisited()
     return True
Ejemplo n.º 9
0
 def write(self, root, forceSentinels=False):
     """Write all the *descendants* of an @auto-markdown node."""
     # Fix bug 66: errors inhibited read @auto foo.md.
     # New in Leo 5.5: headlines indicate markup
     self.root = root
     for p in root.subtree():
         if forceSentinels:
             self.put_node_sentinel(p, '<!--', delim2='-->')
         self.write_headline(p)
         for s in self.split_lines(p.b):
             if not g.isDirective(s):
                 self.put(s)
     root.setVisited()
     return True
Ejemplo n.º 10
0
 def write(self, root, forceSentinels=False):
     """Write all the *descendants* of an @auto-markdown node."""
     # Fix bug 66: errors inhibited read @auto foo.md.
     # New in Leo 5.5: headlines indicate markup
     self.root = root
     for p in root.subtree():
         if forceSentinels:
             self.put_node_sentinel(p, '<!--', delim2='-->')
         self.write_headline(p)
         for s in self.split_lines(p.b):
             if not g.isDirective(s):
                 self.put(s)
     root.setVisited()
     return True
Ejemplo n.º 11
0
 def write(self, root, forceSentinels=False):
     """Write all the *descendants* of an @auto-markdown node."""
     # Fix bug 66: errors inhibited read @auto foo.md.
     # New in Leo 5.5: Skip !headlines. Convert all others to '#' sections.
     self.root = root
     for p in root.subtree():
         if forceSentinels:
             self.put_node_sentinel(p, '<!--', delim2='-->')
         self.write_headline(p)
         # Ensure that every section ends with exactly two newlines.
         s = p.b.rstrip() + '\n\n'
         lines = s.splitlines(False)
         for s in lines:
             if not g.isDirective(s):
                 self.put(s)
     root.setVisited()
     return True
Ejemplo n.º 12
0
 def write(self, root):
     """Write the entire @auto tree."""
     self.put("<Treepad version 3.0>")
     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('<node>')
         self.put(h)
         self.put(str(indent))
         for s in g.splitLines(p.b):
             if not g.isDirective(s):
                 self.put(s)
         self.put('<end node> 5P9i0s8y19Z')
     root.setVisited()
     return True
Ejemplo n.º 13
0
 def write(self, root):
     """Write the entire @auto tree."""
     self.put("<Treepad version 3.0>")
     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('<node>')
         self.put(h)
         self.put(str(indent))
         for s in g.splitLines(p.b):
             if not g.isDirective(s):
                 self.put(s)
         self.put('<end node> 5P9i0s8y19Z')
     root.setVisited()
     return True
Ejemplo n.º 14
0
 def write(self, root):
     """Write all the *descendants* of an @auto-markdown node."""
     # Fix bug 66: errors inhibited read @auto foo.md.
     # New in Leo 5.5: Skip !headlines. Convert all others to '#' sections.
     self.root = root
     for p in root.subtree():
         if hasattr(self.at, 'force_sentinels'):
             self.put_node_sentinel(p, '<!--', delim2='-->')
         self.write_headline(p)
         # Ensure that every section ends with exactly two newlines.
         s = p.b.rstrip() + '\n\n'
         lines = s.splitlines(False)
         for s in lines:
             if not g.isDirective(s):
                 self.put(s)
     root.setVisited()
     return True
Ejemplo n.º 15
0
 def write (self,root):
     """Write all the *descendants* of an @auto-markdown node."""
     # Fix bug 66: errors inhibited read @auto foo.md.
     # Get the underline dict from the importer.
     self.trace = False
     self.root = root
     d = root.v.u.get('markdown-import',{})
     self.underlineDict = d.get('underline_dict',{})
     for p in root.subtree():
         self.write_headline(p)
         # Fix bug 66: use rstrip, **not** strip.
         for s in p.b.rstrip().splitlines(False):
             if not g.isDirective(s):
                 if self.trace: g.trace(s)
                 self.put(s)
         # Always end with a newline.
         self.put('\n')
     root.setVisited()
     return True
Ejemplo n.º 16
0
 def write(self, root, forceSentinels=False):
     """Write all the *descendants* of an @auto-markdown node."""
     # Fix bug 66: errors inhibited read @auto foo.md.
     # Get the underline dict from the importer.
     self.trace = False
     self.root = root
     d = root.v.u.get('markdown-import', {})
     self.underlineDict = d.get('underline_dict', {})
     for p in root.subtree():
         if forceSentinels:
             self.put_node_sentinel(p, '<!--', delim2='-->')
         self.write_headline(p)
         # Fix bug 66: use rstrip, **not** strip.
         for s in p.b.rstrip().splitlines(False):
             if not g.isDirective(s):
                 if self.trace: g.trace(s)
                 self.put(s)
         # Always end with a newline.
         self.put('\n')
     root.setVisited()
     return True
Ejemplo n.º 17
0
 def toAtAuto(self, p):
     """Convert p from @edit to @auto."""
     c = self.c
     # Change the headline.
     p.h = '@auto' + p.h[5:]
     # Compute the position of the present line within the file.
     w = c.frame.body.wrapper
     ins = w.getInsertPoint()
     row, col = g.convertPythonIndexToRowCol(p.b, ins)
     # Ignore *preceding* directive lines.
     directives = [z for z in g.splitLines(c.p.b)[:row] if g.isDirective(z)]
     row -= len(directives)
     row = max(0, row)
     # Reload the file, creating new nodes.
     c.selectPosition(p)
     c.refreshFromDisk()
     # Restore the line in the proper node.
     c.gotoCommands.find_file_line(row + 1)
     p.setDirty()
     c.setChanged()
     c.redraw()
     c.bodyWantsFocus()
Ejemplo n.º 18
0
 def toAtAuto(self, p):
     '''Convert p from @edit to @auto.'''
     c = self.c
     # Change the headline.
     p.h = '@auto' + p.h[5:]
     # Compute the position of the present line within the file.
     w = c.frame.body.wrapper
     ins = w.getInsertPoint()
     row, col = g.convertPythonIndexToRowCol(p.b, ins)
     # Ignore *preceding* directive lines.
     directives = [z for z in g.splitLines(c.p.b)[:row] if g.isDirective(z)]
     row -= len(directives)
     row = max(0, row)
     # Reload the file, creating new nodes.
     c.selectPosition(p, enableRedrawFlag=False)
     c.refreshFromDisk()
     # Restore the line in the proper node.
     c.gotoCommands.find_file_line(row+1)
     p.setDirty()
     c.setChanged()
     c.redraw()
     c.bodyWantsFocus()
Ejemplo n.º 19
0
 def clean(lines):
     lines = [z for z in lines if not g.isDirective(z)]
     s = ''.join(lines).strip() + '\n'
     return g.splitLines(s)
Ejemplo n.º 20
0
 def write_root(self, root):
     '''Write the root @auto-org node.'''
     lines = [z for z in g.splitLines(root.b) if not g.isDirective(z)]
     for s in lines:
         self.put(s)
Ejemplo n.º 21
0
 def write_root(self, root):
     '''Write the root @auto-org node.'''
     lines = [z for z in g.splitLines(root.b) if not g.isDirective(z)]
     for s in lines:
         self.put(s)
Ejemplo n.º 22
0
 def clean(lines):
     lines = [z for z in lines if not g.isDirective(z)]
     s = ''.join(lines).strip() + '\n'
     return g.splitLines(s)