From 20c095b6c638346afcf9b8727597220b66fe14e7 Mon Sep 17 00:00:00 2001 From: Erik Osheim Date: Mon, 19 Apr 2010 22:58:27 -0400 Subject: [PATCH] slightly improve tab support (as well as adding an *Exception* buffer for app exception) --HG-- branch : pmacs2 --- application.py | 3 ++- method/__init__.py | 17 ++++++++++++++--- mode/__init__.py | 13 ++++++++++--- mode/c.py | 9 +++++---- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/application.py b/application.py index 940a94b..f05ece5 100755 --- a/application.py +++ b/application.py @@ -318,7 +318,8 @@ class Application(object): lines = list(candidates) data = '\n'.join(lines) - b = self.data_buffer("*Completions*", data, switch_to=False) + b = self.data_buffer("*Completions*", data, switch_to=False) + b._completion = s b._opened = opened b._previous = previous diff --git a/method/__init__.py b/method/__init__.py index ef564ad..5cf7153 100644 --- a/method/__init__.py +++ b/method/__init__.py @@ -490,14 +490,25 @@ class InsertTab(Method): # if no lvl, insert a literal tab if lvl is None: - w.insert_string_at_cursor(' ' * w.mode.tabwidth) + #w.insert_string_at_cursor(' ' * w.mode.tabwidth) + if w.buffer.usetabs: + # see HACK in buffer + w.insert_string_at_cursor('\t \t') + else: + w.insert_string_at_cursor(' ' * w.mode.tabwidth) return # insert the correct amount of whitespace - ws = w.buffer.count_leading_whitespace(y) + ws = w.buffer.count_leading_whitespace(y) if lvl != ws: w.delete(Point(0, y), Point(ws, y)) - w.insert_string(Point(0, y), ' ' * lvl) + if w.buffer.usetabs: + nt = lvl // w.mode.tabwidth + ns = lvl % w.mode.tabwidth + s = ('\t \t' * nt) + (' ' * ns) + else: + s = ' ' * lvl + w.insert_string(Point(0, y), s) x2 = max(x, lvl) if w.logical_cursor().x < x2: w.goto(Point(x2, y)) diff --git a/mode/__init__.py b/mode/__init__.py index aa5ea23..17d11c1 100644 --- a/mode/__init__.py +++ b/mode/__init__.py @@ -1,5 +1,9 @@ +import math +import os +import string +import sys +import traceback from util import defaultdict -import math, os, string import color, method from lex import Lexer from point import Point @@ -458,8 +462,11 @@ class Fundamental(Handler): except Exception, e: if DEBUG: raise - else: - self.window.set_error(str(e)) + exc_type, exc_value, exc_traceback = sys.exc_info() + data = ''.join(traceback.format_tb(exc_traceback)) + self.window.application.data_buffer("*Exception*", data, + switch_to=False) + self.window.set_error(str(e)) def region_added(self, p, newlines): if self.lexer is not None: diff --git a/mode/c.py b/mode/c.py index ee6fff1..92a99e4 100644 --- a/mode/c.py +++ b/mode/c.py @@ -17,9 +17,10 @@ class ErrorGrammar(Grammar): PatternRule('continuation', r'\\\n$'), ] -chr1 = '[a-zA-Z_]' -chr2 = '[a-zA-Z0-9_]' -word = chr1 + chr2 + '*' +chr1 = '[a-zA-Z_]' +chr2 = '[a-zA-Z0-9_]' +word = chr1 + chr2 + '*' +spaces = r'[\t ]+' class MacroGrammar(Grammar): rules = [ @@ -36,7 +37,7 @@ class MacroGrammar(Grammar): class CGrammar(Grammar): rules = [ - PatternRule('spaces', r' +'), + PatternRule('spaces', spaces), PatternMatchRule('x', r'(\()( *)(' + word + r')(\**)( *)(\))( *)(?=[a-zA-Z0-9_\(])', 'delimiter', 'spaces', 'c.type', 'c.operator',