From 5390ded5d0bf191689abaffa666797cc8ae44de6 Mon Sep 17 00:00:00 2001 From: moculus Date: Thu, 5 Feb 2009 15:47:20 +0000 Subject: [PATCH] --HG-- branch : pmacs2 --- IDEAS | 5 +++++ application.py | 9 +++++---- code_examples/example.xml | 4 +--- mode/__init__.py | 38 +++++++++++++++++++++++++++++++++++++- mode/python.py | 8 ++++++++ 5 files changed, 56 insertions(+), 8 deletions(-) diff --git a/IDEAS b/IDEAS index a8fdb95..d64446b 100644 --- a/IDEAS +++ b/IDEAS @@ -1,3 +1,8 @@ +2009/02/05: + +Create some more rules for lexing that will help things like XML be more +efficient. + 2009/01/28: Move modes into buffers and out of windows. This should reduce the memory diff --git a/application.py b/application.py index e6929bb..1396ae4 100755 --- a/application.py +++ b/application.py @@ -783,10 +783,11 @@ class Application(object): modename = w.mode.name() # draw the header - rstrs = w.mode.get_header() - assert len(rstrs) >= w.mode.header - for j in range(0, w.mode.header): - rstrs[j].draw(self.win, slot.y_offset + j, slot.x_offset, slot.width) + if w.mode.header: + rstrs = w.mode.get_header() + assert len(rstrs) >= w.mode.header + for j in range(0, w.mode.header): + rstrs[j].draw(self.win, slot.y_offset + j, slot.x_offset, slot.width) # draw the actual slot self._draw_slot(i) diff --git a/code_examples/example.xml b/code_examples/example.xml index 522850b..d07d2cf 100644 --- a/code_examples/example.xml +++ b/code_examples/example.xml @@ -1,6 +1,4 @@ - + fjjgg diff --git a/mode/__init__.py b/mode/__init__.py index 288c53b..6244d18 100644 --- a/mode/__init__.py +++ b/mode/__init__.py @@ -313,9 +313,45 @@ class Fundamental(Handler): self.lmargin = 0 # headers and margins + #def get_header(self): + # fg, bg = "default", "red" + # return [RenderString(s='header', attrs=color.build(fg, bg))] def get_header(self): fg, bg = "default", "red" - return [RenderString(s='header', attrs=color.build(fg, bg))] + + if self.tabber is None: + s = "Header support is not available for this mode" + hs = [RenderString(s=s, attrs=color.build(fg, bg))] + while len(hs) < 3: + hs.insert(0, RenderString(s='', attrs=color.build(fg, bg))) + return hs + + w = self.window + y = self.window.first.y + if self.window.first.x > 0: + y += 1 + lvl = self.tabber.get_level(y) + markers = self.tabber.record[y] + if w.buffer.is_whitespace(y): + ws = None + else: + ws = w.buffer.count_leading_whitespace(y) + + hs = [] + i = len(markers) - 1 + while i >= 0 and len(hs) < 3: + marker = markers[i] + i -= 1 + if marker.y == y: + continue + if ws and marker.level > ws: + continue + s = w.buffer.lines[marker.y][:w.width - 1] + hs.insert(0, RenderString(s=s, attrs=color.build(fg, bg))) + while len(hs) < 3: + hs.insert(0, RenderString(s='', attrs=color.build(fg, bg))) + return hs + def get_footer(self): fg, bg = "default", "red" return [RenderString(s='footer', attrs=color.build(fg, bg))] diff --git a/mode/python.py b/mode/python.py index 099cce1..d1a88aa 100644 --- a/mode/python.py +++ b/mode/python.py @@ -583,6 +583,14 @@ class Python(mode.Fundamental): self.header = 0 def get_header(self): fg, bg = "default", "red" + + if self.tabber is None: + s = "Header support is not available for this mode" + hs = [RenderString(s=s, attrs=color.build(fg, bg))] + while len(hs) < 3: + hs.insert(0, RenderString(s='', attrs=color.build(fg, bg))) + return hs + w = self.window y = self.window.first.y if self.window.first.x > 0: