Skip to content

Commit

Permalink
i.check now forgive problems with trailing whitespace in the last lin…
Browse files Browse the repository at this point in the history
…e. All tests pass.

Rev 655473b removed similar code.  Don't know why. The new code clearly is reasonable.

Leo build: 20170122162717
  • Loading branch information
edreamleo committed Jan 22, 2017
1 parent cfa58cd commit 440b5a5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 51 deletions.
4 changes: 2 additions & 2 deletions leo/core/commit_timestamp.json
@@ -1,4 +1,4 @@
{
"asctime": "Sun Jan 22 16:20:13 CST 2017",
"timestamp": "20170122162013"
"asctime": "Sun Jan 22 16:27:17 CST 2017",
"timestamp": "20170122162717"
}
103 changes: 54 additions & 49 deletions leo/plugins/importers/linescanner.py
Expand Up @@ -585,16 +585,12 @@ def gen_lines(self, s, parent):
p = tail_p or top.p
self.add_line(p, line)
prev_state = new_state
#@+node:ekr.20161108160409.7: *5* i.create_child_node
def create_child_node(self, parent, body, headline):
'''Create a child node of parent.'''
child = parent.insertAsLastChild()
self.inject_lines_ivar(child)
if body:
self.add_line(child, body)
assert g.isString(headline), repr(headline)
child.h = headline.strip()
return child
#@+node:ekr.20161127102339.1: *5* i.ends_block
def ends_block(self, line, new_state, prev_state, stack):
'''True if line ends the block.'''
# Comparing new_state against prev_state does not work for python.
top = stack[-1]
return new_state.level() < top.state.level()
#@+node:ekr.20161119130337.1: *5* i.cut_stack
def cut_stack(self, new_state, stack):
'''Cut back the stack until stack[-1] matches new_state.'''
Expand Down Expand Up @@ -633,45 +629,6 @@ def end_block(self, line, new_state, stack):
self.cut_stack(new_state, stack)
tail_p = None if self.gen_refs else p
return tail_p
#@+node:ekr.20161127102339.1: *5* i.ends_block
def ends_block(self, line, new_state, prev_state, stack):
'''True if line ends the block.'''
# Comparing new_state against prev_state does not work for python.
top = stack[-1]
return new_state.level() < top.state.level()
#@+node:ekr.20161108160409.8: *5* i.gen_ref
def gen_ref(self, line, parent, target):
'''
Generate the ref line and a flag telling this method whether a previous
#@+others
#@-others
'''
trace = False and g.unitTesting
indent_ws = self.get_str_lws(line)
h = self.clean_headline(line)
if self.is_rst and not self.atAuto:
return None, None
elif self.gen_refs:
headline = g.angleBrackets(' %s ' % h)
ref = '%s%s\n' % (
indent_ws,
g.angleBrackets(' %s ' % h))
else:
if target.ref_flag:
ref = None
else:
ref = '%s@others\n' % indent_ws
target.at_others_flag = True
target.ref_flag = True
# Don't generate another @others in this target.
headline = h
if ref:
if trace:
g.trace('%s indent_ws: %r line: %r parent: %s' % (
'*' * 20, indent_ws, line, parent.h))
g.printList(self.get_lines(parent))
self.add_line(parent,ref)
return headline
#@+node:ekr.20161110041440.1: *5* i.inject_lines_ivar
def inject_lines_ivar(self, p):
'''Inject _import_lines into p.v.'''
Expand Down Expand Up @@ -710,6 +667,49 @@ def trace_status(self, line, new_state, prev_state, stack, top):
print('prev_state: %s' % prev_state)
# print(' top.state: %s' % top.state)
g.printList(stack)
#@+node:ekr.20161108160409.7: *5* i.create_child_node
def create_child_node(self, parent, body, headline):
'''Create a child node of parent.'''
child = parent.insertAsLastChild()
self.inject_lines_ivar(child)
if body:
self.add_line(child, body)
assert g.isString(headline), repr(headline)
child.h = headline.strip()
return child
#@+node:ekr.20161108160409.8: *5* i.gen_ref
def gen_ref(self, line, parent, target):
'''
Generate the ref line and a flag telling this method whether a previous
#@+others
#@-others
'''
trace = False and g.unitTesting
indent_ws = self.get_str_lws(line)
h = self.clean_headline(line)
if self.is_rst and not self.atAuto:
return None, None
elif self.gen_refs:
headline = g.angleBrackets(' %s ' % h)
ref = '%s%s\n' % (
indent_ws,
g.angleBrackets(' %s ' % h))
else:
if target.ref_flag:
ref = None
else:
ref = '%s@others\n' % indent_ws
target.at_others_flag = True
target.ref_flag = True
# Don't generate another @others in this target.
headline = h
if ref:
if trace:
g.trace('%s indent_ws: %r line: %r parent: %s' % (
'*' * 20, indent_ws, line, parent.h))
g.printList(self.get_lines(parent))
self.add_line(parent,ref)
return headline
#@+node:ekr.20161108131153.13: *4* Stage 2: i.post_pass & helpers
def post_pass(self, parent):
'''
Expand Down Expand Up @@ -888,6 +888,11 @@ def check(self, unused_s, parent):
# Importing may regularize whitespace, and that's good.
lines1 = self.strip_all(lines1)
lines2 = self.strip_all(lines2)
# Forgive trailing whitespace problems in the last line.
# This is not the same as clean_last_lines.
if lines1 and lines2 and lines1 != lines2:
lines1[-1] = lines1[-1].rstrip()+'\n'
lines2[-1] = lines2[-1].rstrip()+'\n'
if trace and trace_all:
g.trace('===== entry')
self.trace_lines(lines1, lines2, parent)
Expand Down

0 comments on commit 440b5a5

Please sign in to comment.