From 1e6fc685c562dccf12138689b12427879debd073 Mon Sep 17 00:00:00 2001 From: moculus Date: Thu, 3 Apr 2008 00:17:39 +0000 Subject: [PATCH] 80x24 improvements, buffer improvements, ideas --HG-- branch : pmacs2 --- IDEAS | 5 +++++ buffer.py | 34 +++++++++++++++++++--------------- method/__init__.py | 5 ++++- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/IDEAS b/IDEAS index f14fdbc..6f69ce4 100644 --- a/IDEAS +++ b/IDEAS @@ -1,3 +1,8 @@ +2008/04/02: + +fix read-only warnings to seem less junky (e.g. catch the buffer.ReadOnlyError +exception and write a graceful message everywhere applicable). + 2008/03/18: tie cvs/svn comands into method/shell.py for code reuse diff --git a/buffer.py b/buffer.py index ce0cd96..0c504a2 100644 --- a/buffer.py +++ b/buffer.py @@ -8,6 +8,9 @@ ACT_UNDO = 1 ACT_REDO = 2 STACK_LIMIT = 1024 +class ReadOnlyError(Exception): + pass + # used for multiple text additions/deletions class GroupMove(object): def __init__(self, buffer, p, moves): @@ -260,8 +263,8 @@ class Buffer(object): # raise Exception, "damn" llen = len(lines) assert llen > 0 - if not force: - assert not self.readonly(), "insert_string: buffer is read-only" + if not force and self.readonly(): + raise ReadOnlyError, "buffer is read-only" p2 = p.vadd(len(lines[-1]), llen - 1) if llen > 1: self.lines.insert(p.y + 1, []) @@ -280,8 +283,8 @@ class Buffer(object): # deletion from buffer def delete(self, p1, p2, act=ACT_NORM, force=False): """delete characters from p1 up to p2 from the buffer""" - if not force: - assert not self.readonly(), "delete_string: buffer is read-only" + if not force and self.readonly(): + raise ReadOnlyError, "buffer is read-only" self._validate_point(p1) self._validate_point(p2) if p1 == p2: @@ -466,7 +469,7 @@ class FileBuffer(Buffer): return self.checksum.digest() != m.digest() def save(self, force=False): if self.readonly(): - raise Exception, "can't save a read-only file" + raise ReadOnlyError, "can't save read-only file" if self.checksum is not None and force is False: # the file already existed and we took a checksum so make sure it's @@ -694,23 +697,24 @@ class ColorDataBuffer(DataBuffer): self.highlights['Colortext'].highlight(lines) ABOUT_DATA = ''' -[r:d:*]================================================================================ +[r:d:*]=============================================================================== [y:d:*]************ ********** ****** ****** **** ******** ********* [y:d:*]************** ****************** ************* ********** *********** -[y:d:*]******* ***** ****** ***** **** **** ****** **** **** ***** **** +[y:d:*]******* ***** ****** ***** **** **** ****** **** **** ***** *** [y:d:*] *** *** *** *** *** **** **** **** ******* -[y:d:*] *** *** *** *** *** **** **** **** ******* -[y:d:*] ***** ***** ***** ***** **** **** ****** **** **** **** ***** -[y:d:*] ************ ***** ***** **** ************* ********** *********** -[y:d:*] ********** ***** ***** **** ****** **** ******** ********* +[y:d:*] *** *** *** *** *** **** **** **** ****** +[y:d:*] ***** ***** ***** ***** **** **** ****** **** **** **** **** +[y:d:*] ************ ***** ***** **** ************* ********** ********** +[y:d:*] ********** ***** ***** **** ****** **** ******** ******** [y:d:*] *** -[y:d:*] *** [c:d:*]pmacs[d:d:*] is a python-based text editor by [c:d:*]Erik Osheim[d:d:*], [b:d:*](c) 2005-2008 -[y:d:*]***** [c:d:*]pmacs[d:d:*] is available to you under the [c:d:*]GNU General Public License v2 +[y:d:*] *** [c:d:*]pmacs[d:d:*] is a python-based text editor by [c:d:*]Erik Osheim[d:d:*], [b:d:*](c) 2005-2008 +[y:d:*]***** [c:d:*]pmacs[d:d:*] is available to you under the [c:d:*]GNU General Public License v2 [y:d:*]***** -[y:d:*]***** [d:d:*]to see all available commands use: [c:d:*]C-c M-h [b:d:*](show-bindings-buffer) +[y:d:*]***** [d:d:*]to view available commands use [c:d:*]C-c M-h [b:d:*](show-bindings-buffer) +[d:d:*] [d:d:*]open files with [c:d:*]C-x C-f[d:d:*]; save with [c:d:*]C-x C-s[d:d:*]; quit with [c:d:*]C-x C-c -[r:d:*]================================================================================ +[r:d:*]=============================================================================== ''' class AboutBuffer(ColorDataBuffer): def __init__(self): diff --git a/method/__init__.py b/method/__init__.py index 4a19ac9..645ee8b 100644 --- a/method/__init__.py +++ b/method/__init__.py @@ -172,7 +172,10 @@ class InsertString(Method): self.help = "Insert %r into the current buffer." % s self.string = s def _execute(self, w, **vargs): - w.insert_string_at_cursor(self.string) + try: + w.insert_string_at_cursor(self.string) + except buffer.ReadOnlyError: + w.set_error('Buffer is read-only') class OverwriteChar(Method): _is_method = False def __init__(self, c):