parent
563bf266a3
commit
c104583d90
14
README
14
README
|
@ -2,14 +2,18 @@ Pmacs version 0.1
|
||||||
|
|
||||||
Released june 27, 2007 by Erik Osheim <erik@osheim.org>
|
Released june 27, 2007 by Erik Osheim <erik@osheim.org>
|
||||||
|
|
||||||
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:
|
Requirements:
|
||||||
=============
|
=============
|
||||||
1. python 2.3 or higher
|
1. python 2.3 or higher
|
||||||
2. ncurses
|
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
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
import os, re, sets, sys
|
import os, re, sets, sys
|
||||||
|
|
||||||
# regular expressions
|
# regular expressions
|
||||||
class_re = re.compile('^(.*?)\t(.*?)\t(.*?)\tc$')
|
class_re = re.compile('^(.*?)\t(.*?)\t(.*?)\tc$')
|
||||||
function_re = re.compile('^(.*?)\t(.*?)\t(.*?)\tf$')
|
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]* *\((.*?)\) *: *\$\/;\"$')
|
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]* *\((.*?)\) *: *\$\/;\"$')
|
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]*(?:=(?:[^,\'" ]+|"(?:\\.|[^\\"])*"|\'(?:\\.|[^\\"])*\'))?')
|
find_args_re = re.compile('[\*_a-zA-Z][\*_a-zA-Z0-9]*(?:=(?:[^,\'" ]+|"(?:\\.|[^\\"])*"|\'(?:\\.|[^\\"])*\'))?')
|
||||||
|
|
||||||
# set of base python objects which can be assumed to exist
|
# set of base python objects which can be assumed to exist
|
||||||
base_objects = sets.Set(['object', 'list', 'dict'])
|
base_objects = sets.Set(['object', 'list', 'dict'])
|
||||||
|
|
8
ctags.py
8
ctags.py
|
@ -9,13 +9,13 @@ packages = {}
|
||||||
classes = {}
|
classes = {}
|
||||||
class_methods = {}
|
class_methods = {}
|
||||||
|
|
||||||
class_re = re.compile('^(.*?)\t(.*?)\t(.*?)\tc$')
|
class_re = re.compile('^(.*?)\t(.*?)\t(.*?)\tc$')
|
||||||
function_re = re.compile('^(.*?)\t(.*?)\t(.*?)\tf$')
|
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]* *\((.*?)\) *: *\$\/;\"$')
|
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]* *\((.*?)\) *: *\$\/;\"$')
|
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]*(?:=(?:[^,\'" ]+|"(?:\\.|[^\\"])*"|\'(?:\\.|[^\\"])*\'))?')
|
find_args_re = re.compile('[\*_a-zA-Z][\*_a-zA-Z0-9]*(?:=(?:[^,\'" ]+|"(?:\\.|[^\\"])*"|\'(?:\\.|[^\\"])*\'))?')
|
||||||
|
|
||||||
base_objects = sets.Set(['object', 'list', 'dict'])
|
base_objects = sets.Set(['object', 'list', 'dict'])
|
||||||
|
|
||||||
|
|
|
@ -365,7 +365,7 @@ class PerlViewWordPerldoc(method.Method):
|
||||||
# then try it as a function
|
# then try it as a function
|
||||||
data = self._try(w, word, asfunc=True)
|
data = self._try(w, word, asfunc=True)
|
||||||
if data:
|
if data:
|
||||||
self._show(w, data, parts[0])
|
self._show(w, data, word)
|
||||||
else:
|
else:
|
||||||
w.application.set_error('nothing found for %r' % word)
|
w.application.set_error('nothing found for %r' % word)
|
||||||
|
|
||||||
|
|
|
@ -71,12 +71,14 @@ class PythonTabber(tab2.StackTabber):
|
||||||
y -= 1
|
y -= 1
|
||||||
|
|
||||||
# ok, so clear out our stack and then loop over each line
|
# ok, so clear out our stack and then loop over each line
|
||||||
|
self.popped = False
|
||||||
self.markers = []
|
self.markers = []
|
||||||
while y <= target:
|
while y <= target:
|
||||||
self.continued = False
|
self.continued = False
|
||||||
self.popped = False
|
self.last_popped = self.popped
|
||||||
tokens = self.get_tokens(y)
|
self.popped = False
|
||||||
currlvl = self.get_curr_level()
|
tokens = self.get_tokens(y)
|
||||||
|
currlvl = self.get_curr_level()
|
||||||
# if we were continuing, let's pop that previous continuation token
|
# if we were continuing, let's pop that previous continuation token
|
||||||
# and note that we're continuing
|
# and note that we're continuing
|
||||||
if self.markers and self.markers[-1].name == 'cont':
|
if self.markers and self.markers[-1].name == 'cont':
|
||||||
|
@ -101,6 +103,12 @@ class PythonTabber(tab2.StackTabber):
|
||||||
self.record[y] = tuple(self.markers)
|
self.record[y] = tuple(self.markers)
|
||||||
y += 1
|
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):
|
def _handle_other_token(self, currlvl, y, i):
|
||||||
token = self.get_token(y, i)
|
token = self.get_token(y, i)
|
||||||
fqname = token.fqname()
|
fqname = token.fqname()
|
||||||
|
@ -131,24 +139,26 @@ class PythonTabber(tab2.StackTabber):
|
||||||
if token.string in self.endlevel_names:
|
if token.string in self.endlevel_names:
|
||||||
# we know we'll unindent at least once
|
# we know we'll unindent at least once
|
||||||
self._pop()
|
self._pop()
|
||||||
|
self.popped = True
|
||||||
elif token.string in self.startlevel_names and self.is_leftmost_token(y, i):
|
elif token.string in self.startlevel_names and self.is_leftmost_token(y, i):
|
||||||
# we know we will indent exactly once
|
# we know we will indent exactly once
|
||||||
self._append(token.string, currlvl + 4)
|
self._append(token.string, currlvl + 4)
|
||||||
elif token.string in ('elif', 'else') and self.is_leftmost_token(y, i):
|
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
|
# 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')
|
self._pop_until('if', 'elif')
|
||||||
currlvl = self.get_curr_level()
|
currlvl = self.get_curr_level()
|
||||||
self._append(token.string, currlvl + 4)
|
self._append(token.string, currlvl + 4)
|
||||||
elif token.string == 'except' and self.is_leftmost_token(y, i):
|
elif token.string == 'except' and self.is_leftmost_token(y, i):
|
||||||
# we know we'll unindent at least to the first try
|
# 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')
|
self._pop_until('try')
|
||||||
currlvl = self.get_curr_level()
|
currlvl = self.get_curr_level()
|
||||||
self._append(token.string, currlvl + 4)
|
self._append(token.string, currlvl + 4)
|
||||||
elif token.string == 'finally' and self.is_leftmost_token(y, i):
|
elif token.string == 'finally' and self.is_leftmost_token(y, i):
|
||||||
# we know we'll unindent at least to the first try/except
|
# 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')
|
self._pop_until('try', 'except')
|
||||||
currlvl = self.get_curr_level()
|
currlvl = self.get_curr_level()
|
||||||
self._append(token.string, currlvl + 4)
|
self._append(token.string, currlvl + 4)
|
||||||
|
@ -192,19 +202,23 @@ class Python(mode2.Fundamental):
|
||||||
'continuation': color.build('red', 'default'),
|
'continuation': color.build('red', 'default'),
|
||||||
'system_identifier': color.build('cyan', 'default'),
|
'system_identifier': color.build('cyan', 'default'),
|
||||||
}
|
}
|
||||||
|
self.pythonlib = "."
|
||||||
def name(self):
|
def name(self):
|
||||||
return "Python"
|
return "Python"
|
||||||
|
|
||||||
class PythonCheckSyntax(method.Method):
|
class PythonSetLib(method.Method):
|
||||||
'''Check the syntax of the current python file'''
|
'''Set the path(s) to find perl modules'''
|
||||||
def _args(self):
|
def _args(self):
|
||||||
return [method.Argument("lib", type=type(""), prompt="Python Path: ",
|
return [method.Argument("lib", type=type(""), prompt="Python Path: ",
|
||||||
datatype='path',
|
|
||||||
default=default.build_constant("."))]
|
default=default.build_constant("."))]
|
||||||
def _execute(self, w, **vargs):
|
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]
|
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)
|
(status, output) = commands.getstatusoutput(cmd)
|
||||||
if status == 0:
|
if status == 0:
|
||||||
w.application.set_error("Syntax OK")
|
w.application.set_error("Syntax OK")
|
||||||
|
@ -362,4 +376,4 @@ class PythonDictCleanup(method.Method):
|
||||||
start_p = Point(0, start)
|
start_p = Point(0, start)
|
||||||
end_p = Point(0, end + 1)
|
end_p = Point(0, end + 1)
|
||||||
w.kill(start_p, end_p)
|
w.kill(start_p, end_p)
|
||||||
w.insert(start_p, data)
|
w.insert_string(start_p, data)
|
||||||
|
|
2
tab2.py
2
tab2.py
|
@ -145,7 +145,7 @@ class StackTabber(Tabber):
|
||||||
if not self.markers:
|
if not self.markers:
|
||||||
raise Exception, "unmatched closing token %r" % s1
|
raise Exception, "unmatched closing token %r" % s1
|
||||||
s2 = self.markers[-1].name
|
s2 = self.markers[-1].name
|
||||||
if s1 == self.mode.opentags[s2]:
|
if self.mode.closetags[s1] == s2:
|
||||||
self._pop()
|
self._pop()
|
||||||
if self.is_leftmost_token(y, i):
|
if self.is_leftmost_token(y, i):
|
||||||
currlvl = self.get_curr_level()
|
currlvl = self.get_curr_level()
|
||||||
|
|
Loading…
Reference in New Issue