From c104583d90ad6e46a3d7d511c84cfda298b24223 Mon Sep 17 00:00:00 2001 From: moculus Date: Wed, 27 Jun 2007 22:53:02 +0000 Subject: [PATCH] some updates/bugfixes/etc --HG-- branch : pmacs2 --- README | 14 +++++++++----- ctag_python.py | 8 ++++---- ctags.py | 8 ++++---- mode_perl.py | 2 +- mode_python.py | 40 +++++++++++++++++++++++++++------------- tab2.py | 2 +- 6 files changed, 46 insertions(+), 28 deletions(-) diff --git a/README b/README index 904d11a..eda8c22 100644 --- a/README +++ b/README @@ -2,14 +2,18 @@ Pmacs version 0.1 Released june 27, 2007 by Erik Osheim -Explanation paragraph goes here. +Pmacs is an Emacs-like editor written entirely in Python. It is designed to have +maximally correct and powerful support for syntax highlighting, indenting, etc. +and to be extensible in python. Requirements: ============= 1. python 2.3 or higher 2. ncurses - 3. ispell (optional, for spell-as-you-type) - 4. perl (optional, for perl-mode) - 5. etc, etc, etc... -Basic usage stuff should go here. +Optional Dependencies: +====================== + 1. ispell + 2. aespipe + 3. perl + 4. ctags diff --git a/ctag_python.py b/ctag_python.py index 9b9a4c6..6c46667 100755 --- a/ctag_python.py +++ b/ctag_python.py @@ -5,13 +5,13 @@ import os, re, sets, sys # regular expressions -class_re = re.compile('^(.*?)\t(.*?)\t(.*?)\tc$') +class_re = re.compile('^(.*?)\t(.*?)\t(.*?)\tc$') function_re = re.compile('^(.*?)\t(.*?)\t(.*?)\tf$') -method_re = re.compile('^([^\t]+)\t([^\t]+)\t([^\t]+)\tm\tclass:([^\t]+)(?:\t.*)?$') +method_re = re.compile('^([^\t]+)\t([^\t]+)\t([^\t]+)\tm\tclass:([^\t]+)(?:\t.*)?$') class_supers_re = re.compile('^\/\^ *class +[_A-Za-z][_A-Za-z0-9]* *\((.*?)\) *: *\$\/;\"$') -def_args_re = re.compile('^\/\^ *def +[_A-Za-z][_A-Za-z0-9]* *\((.*?)\) *: *\$\/;\"$') -find_args_re = re.compile('[\*_a-zA-Z][\*_a-zA-Z0-9]*(?:=(?:[^,\'" ]+|"(?:\\.|[^\\"])*"|\'(?:\\.|[^\\"])*\'))?') +def_args_re = re.compile('^\/\^ *def +[_A-Za-z][_A-Za-z0-9]* *\((.*?)\) *: *\$\/;\"$') +find_args_re = re.compile('[\*_a-zA-Z][\*_a-zA-Z0-9]*(?:=(?:[^,\'" ]+|"(?:\\.|[^\\"])*"|\'(?:\\.|[^\\"])*\'))?') # set of base python objects which can be assumed to exist base_objects = sets.Set(['object', 'list', 'dict']) diff --git a/ctags.py b/ctags.py index 0909bd5..4ba2e9a 100755 --- a/ctags.py +++ b/ctags.py @@ -9,13 +9,13 @@ packages = {} classes = {} class_methods = {} -class_re = re.compile('^(.*?)\t(.*?)\t(.*?)\tc$') +class_re = re.compile('^(.*?)\t(.*?)\t(.*?)\tc$') function_re = re.compile('^(.*?)\t(.*?)\t(.*?)\tf$') -method_re = re.compile('^([^\t]+)\t([^\t]+)\t([^\t]+)\tm\tclass:([^\t]+)(?:\t.*)?$') +method_re = re.compile('^([^\t]+)\t([^\t]+)\t([^\t]+)\tm\tclass:([^\t]+)(?:\t.*)?$') class_supers_re = re.compile('^\/\^ *class +[_A-Za-z][_A-Za-z0-9]* *\((.*?)\) *: *\$\/;\"$') -def_args_re = re.compile('^\/\^ *def +[_A-Za-z][_A-Za-z0-9]* *\((.*?)\) *: *\$\/;\"$') -find_args_re = re.compile('[\*_a-zA-Z][\*_a-zA-Z0-9]*(?:=(?:[^,\'" ]+|"(?:\\.|[^\\"])*"|\'(?:\\.|[^\\"])*\'))?') +def_args_re = re.compile('^\/\^ *def +[_A-Za-z][_A-Za-z0-9]* *\((.*?)\) *: *\$\/;\"$') +find_args_re = re.compile('[\*_a-zA-Z][\*_a-zA-Z0-9]*(?:=(?:[^,\'" ]+|"(?:\\.|[^\\"])*"|\'(?:\\.|[^\\"])*\'))?') base_objects = sets.Set(['object', 'list', 'dict']) diff --git a/mode_perl.py b/mode_perl.py index 4a6a951..2ec8cfb 100644 --- a/mode_perl.py +++ b/mode_perl.py @@ -365,7 +365,7 @@ class PerlViewWordPerldoc(method.Method): # then try it as a function data = self._try(w, word, asfunc=True) if data: - self._show(w, data, parts[0]) + self._show(w, data, word) else: w.application.set_error('nothing found for %r' % word) diff --git a/mode_python.py b/mode_python.py index f5617f5..70ad183 100644 --- a/mode_python.py +++ b/mode_python.py @@ -71,12 +71,14 @@ class PythonTabber(tab2.StackTabber): y -= 1 # ok, so clear out our stack and then loop over each line + self.popped = False self.markers = [] while y <= target: - self.continued = False - self.popped = False - tokens = self.get_tokens(y) - currlvl = self.get_curr_level() + self.continued = False + self.last_popped = self.popped + self.popped = False + tokens = self.get_tokens(y) + currlvl = self.get_curr_level() # if we were continuing, let's pop that previous continuation token # and note that we're continuing if self.markers and self.markers[-1].name == 'cont': @@ -101,6 +103,12 @@ class PythonTabber(tab2.StackTabber): self.record[y] = tuple(self.markers) y += 1 + def _handle_close_token(self, currlvl, y, i): + try: + return tab2.StackTabber._handle_close_token(self, currlvl, y, i) + except: + return currlvl + def _handle_other_token(self, currlvl, y, i): token = self.get_token(y, i) fqname = token.fqname() @@ -131,24 +139,26 @@ class PythonTabber(tab2.StackTabber): if token.string in self.endlevel_names: # we know we'll unindent at least once self._pop() + self.popped = True elif token.string in self.startlevel_names and self.is_leftmost_token(y, i): # we know we will indent exactly once self._append(token.string, currlvl + 4) elif token.string in ('elif', 'else') and self.is_leftmost_token(y, i): # we know we'll unindent at least to the first if/elif - if not self.popped: + if not self.popped and not self.last_popped: + raise Exception, "junka" self._pop_until('if', 'elif') currlvl = self.get_curr_level() self._append(token.string, currlvl + 4) elif token.string == 'except' and self.is_leftmost_token(y, i): # we know we'll unindent at least to the first try - if not self.popped: + if not self.popped and not self.last_popped: self._pop_until('try') currlvl = self.get_curr_level() self._append(token.string, currlvl + 4) elif token.string == 'finally' and self.is_leftmost_token(y, i): # we know we'll unindent at least to the first try/except - if not self.popped: + if not self.popped and not self.last_popped: self._pop_until('try', 'except') currlvl = self.get_curr_level() self._append(token.string, currlvl + 4) @@ -192,19 +202,23 @@ class Python(mode2.Fundamental): 'continuation': color.build('red', 'default'), 'system_identifier': color.build('cyan', 'default'), } + self.pythonlib = "." def name(self): return "Python" -class PythonCheckSyntax(method.Method): - '''Check the syntax of the current python file''' +class PythonSetLib(method.Method): + '''Set the path(s) to find perl modules''' def _args(self): return [method.Argument("lib", type=type(""), prompt="Python Path: ", - datatype='path', default=default.build_constant("."))] def _execute(self, w, **vargs): - a = vargs['lib'] + w.mode.pythonlib = vargs['lib'] + +class PythonCheckSyntax(method.Method): + '''Check the syntax of the current python file''' + def _execute(self, w, **vargs): mod = os.path.splitext(os.path.basename(w.buffer.path))[0] - cmd = "PYTHONPATH=%s python -c 'import %s'" % (a, mod) + cmd = "PYTHONPATH=%s python -c 'import %s'" % (w.mode.pythonlib, mod) (status, output) = commands.getstatusoutput(cmd) if status == 0: w.application.set_error("Syntax OK") @@ -362,4 +376,4 @@ class PythonDictCleanup(method.Method): start_p = Point(0, start) end_p = Point(0, end + 1) w.kill(start_p, end_p) - w.insert(start_p, data) + w.insert_string(start_p, data) diff --git a/tab2.py b/tab2.py index f8d567a..850bb98 100644 --- a/tab2.py +++ b/tab2.py @@ -145,7 +145,7 @@ class StackTabber(Tabber): if not self.markers: raise Exception, "unmatched closing token %r" % s1 s2 = self.markers[-1].name - if s1 == self.mode.opentags[s2]: + if self.mode.closetags[s1] == s2: self._pop() if self.is_leftmost_token(y, i): currlvl = self.get_curr_level()