Commits

Ronny Pfannschmidt committed aee8747

moved buffer to own module

  • Participants
  • Parent commits 76803fd

Comments (0)

Files changed (4)

File tests/conftest.py

-
-from vimish.engine import Engine, Buffer
+from vimish.engine import Engine
+from vimish.buffer import Buffer
 
 
 class ConftestPlugin:

File tests/test_engine.py

-from vimish.engine import Buffer
+from vimish.buffer import Buffer
 
 def test_engine_buffer_id(engine):
 

File vimish/buffer.py

+from gtk import TextBuffer
+
+
+class Buffer(object):
+    def __init__(self, engine):
+        self.engine = engine
+        self.text_buffer = TextBuffer()
+        self.bufnr = engine.add(self)
+
+    @property
+    def text(self):
+        return self.text_buffer.get_text(
+                self.text_buffer.get_start_iter(),
+                self.text_buffer.get_end_iter()
+                )
+
+    @text.setter
+    def text(self, text):
+        self.text_buffer.set_text(text)
+
+    def append(self, text):
+        self.text_buffer.insert(
+                self.text_buffer.get_end_iter(),
+                text)
+
+    def __len__(self):
+        return self.text_buffer.get_line_count()
+
+    def __getitem__(self, item):
+        if isinstance(item, int):
+            start = self.text_buffer.get_iter_at_line(item)
+            # the last line doesnt end with \n
+            if item+1 < len(self):
+                end = self.text_buffer.get_iter_at_line(item +1)
+            else:
+                end = self.text_buffer.get_end_iter()
+            return self.text_buffer.get_slice(start, end)
+        else:
+            if item.start is None:
+                start = self.text_buffer.get_start_iter()
+            else:
+                start = self.text_buffer.get_iter_at_line(item.start)
+
+            if item.stop is None or item.stop >= len(self):
+                end = self.text_buffer.get_end_iter()
+            else:
+                end = self.text_buffer.get_iter_at_line(item.stop)
+
+            slice = self.text_buffer.get_slice(start, end)
+            return slice.splitlines(True)
+
+
+    def __setitem__(self, item, value):
+        if isinstance(value, list):
+            #XXX: smarter?
+            value = ''.join(value)
+
+
+        if isinstance(item, int):
+            start = self.text_buffer.get_iter_at_line(item)
+            end = self.text_buffer.get_iter_at_line(item +1)
+        else:
+            if item.start is None:
+                start = self.text_buffer.get_start_iter()
+
+            end = self.text_buffer.get_iter_at_line(item.stop)
+
+        self.text_buffer.select_range(start, end)
+        self.text_buffer.delete_selection(False, False)
+
+        if isinstance(item, int):
+            start = self.text_buffer.get_iter_at_line(item)
+        elif item.start is None:
+            start = self.text_buffer.get_start_iter()
+        else:
+            start = self.text_buffer.get_iter_at_line(item.start)
+        self.text_buffer.insert(start, value)

File vimish/engine.py

 from gtk import TextBuffer
 
 
-class Buffer(object):
-    def __init__(self, engine):
-        self.engine = engine
-        self.text_buffer = TextBuffer()
-        self.bufnr = engine.add(self)
-
-    @property
-    def text(self):
-        return self.text_buffer.get_text(
-                self.text_buffer.get_start_iter(),
-                self.text_buffer.get_end_iter()
-                )
-
-    @text.setter
-    def text(self, text):
-        self.text_buffer.set_text(text)
-
-    def append(self, text):
-        self.text_buffer.insert(
-                self.text_buffer.get_end_iter(),
-                text)
-
-    def __len__(self):
-        return self.text_buffer.get_line_count()
-
-    def __getitem__(self, item):
-        if isinstance(item, int):
-            start = self.text_buffer.get_iter_at_line(item)
-            # the last line doesnt end with \n
-            if item+1 < len(self):
-                end = self.text_buffer.get_iter_at_line(item +1)
-            else:
-                end = self.text_buffer.get_end_iter()
-            return self.text_buffer.get_slice(start, end)
-        else:
-            if item.start is None:
-                start = self.text_buffer.get_start_iter()
-            else:
-                start = self.text_buffer.get_iter_at_line(item.start)
-
-            if item.stop is None or item.stop >= len(self):
-                end = self.text_buffer.get_end_iter()
-            else:
-                end = self.text_buffer.get_iter_at_line(item.stop)
-
-            slice = self.text_buffer.get_slice(start, end)
-            return slice.splitlines(True)
-
-
-    def __setitem__(self, item, value):
-        if isinstance(value, list):
-            #XXX: smarter?
-            value = ''.join(value)
-
-
-        if isinstance(item, int):
-            start = self.text_buffer.get_iter_at_line(item)
-            end = self.text_buffer.get_iter_at_line(item +1)
-        else:
-            if item.start is None:
-                start = self.text_buffer.get_start_iter()
-
-            end = self.text_buffer.get_iter_at_line(item.stop)
-
-        self.text_buffer.select_range(start, end)
-        self.text_buffer.delete_selection(False, False)
-
-        if isinstance(item, int):
-            start = self.text_buffer.get_iter_at_line(item)
-        elif item.start is None:
-            start = self.text_buffer.get_start_iter()
-        else:
-            start = self.text_buffer.get_iter_at_line(item.start)
-        self.text_buffer.insert(start, value)
-
-
 class Engine(object):
 
     def __init__(self):