refactor mode.name() to mode.name

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-03-17 19:24:10 +00:00
parent c95ae0fd2f
commit 5eff1a2875
69 changed files with 179 additions and 189 deletions

2
MODES
View File

@ -8,7 +8,7 @@ the buffer should be highlighted, how the buffer should be indented, and any
other per-buffer configuration. The default mode ("Fundamental") provides the
base functionality which all other modes inherit. The idea of modes is taken
from Emacs (although the distinction between major and minor modes does not
exist in Pmacs).
exist in Pmacs--there are no minor modes).
2. Where do they come from?

View File

@ -787,7 +787,6 @@ class Application(object):
if slot.window is None:
return
w = slot.window
modename = w.mode.name()
# draw the header
if w.mode.header:
@ -844,8 +843,7 @@ class Application(object):
lines = w.buffer.lines
count = w.mode.header
swidth = slot.width - lm - rm
modename = w.mode.name()
lit = w.mode.name() in w.buffer.highlights
lit = w.mode.name in w.buffer.highlights
ended = False
# figure out which "physical line" is the first to be shown. note that

View File

@ -160,7 +160,7 @@ class Buffer(object):
def add_window(self, w):
if w not in self.windows:
self.windows.append(w)
modename = w.mode.name()
modename = w.mode.name
if modename not in self.highlights and w.mode.lexer is not None:
self.highlights[modename] = highlight.Highlighter(w.mode.lexer)
self.highlights[modename].highlight(self.lines)
@ -170,12 +170,12 @@ class Buffer(object):
def remove_window(self, w):
if w in self.windows:
self.windows.remove(w)
modename = w.mode.name()
if modename in self.highlights:
modename = w.mode.name
if w.mode.name in self.highlights:
for w2 in self.windows:
if w2.mode.name() == modename:
if w2.mode.name == w.mode.name:
return
del self.highlights[modename]
del self.highlights[w.mode.name]
def _region_add(self, p1, p2, lines, act):
move = DelMove(self, p1, p2)
self.add_to_stack(move, act)

View File

@ -896,7 +896,7 @@ class CloseTag(Method):
w.insert_string_at_cursor(self.mytag)
app = w.application
buffer = w.buffer
highlighter = buffer.highlights[w.mode.name()]
highlighter = buffer.highlights[w.mode.name]
tokens = highlighter.tokens
# REFACTOR: we have methods in window to do this now

View File

@ -15,7 +15,7 @@ class ShowMode(Method):
m = w.mode
f = Fundamental(w)
lines = ['%s mode' % m.modename, '']
lines = ['%s mode' % m.name, '']
seen = set()
triples = []
@ -53,7 +53,7 @@ class ShowBindingsBuffer(Method):
'''Dump all keybindings for current mode into a new buffer'''
def _execute(self, w, **vargs):
lines = []
mode_name = w.mode.name()
mode_name = w.mode.name
lines.append('Key bindings for mode %r:' % (mode_name))
lines.append('')

View File

@ -49,10 +49,9 @@ class DumpMarkers(Method):
class DumpTokens(Method):
'''Dump all lexical tokens (syntax highlighting debugging)'''
def _execute(self, w, **vargs):
modename = w.mode.name()
lines = []
if modename in w.buffer.highlights:
tokens = w.buffer.highlights[modename].tokens
if w.mode.name in w.buffer.highlights:
tokens = w.buffer.highlights[w.mode.name].tokens
for i in range(0, len(tokens)):
lines.append("LINE %d" % (i + 1))
group = tokens[i]
@ -77,10 +76,9 @@ class DumpTokens(Method):
class DumpAggregateTokenData(Method):
'''Dump all lexical tokens into an aggregated format'''
def _execute(self, w, **vargs):
name = w.mode.name()
lines = []
if name in w.buffer.highlights:
tokens = w.buffer.highlights[name].tokens
if w.mode.name in w.buffer.highlights:
tokens = w.buffer.highlights[w.mode.name].tokens
for group in tokens:
for token in group:
s1 = token.name

View File

@ -119,18 +119,20 @@ class SvnStatus(Method):
c = data[0]
status = self.column.get(c, 'Error (%s)' % c)
fields = data[6:].split()
try:
(rrev, lrev, lauthor, filename) = fields
except:
raise Exception, '%r %r' % (fields, data[6:])
if len(fields) == 4:
rrev, lrev, lauthor, filename = fields
w.buffer.metadata['svn-filename'] = filename
w.buffer.metadata['svn-status'] = status
w.buffer.metadata['svn-lrev'] = lrev
w.buffer.metadata['svn-rrev'] = rrev
w.buffer.metadata['svn-author'] = lauthor
w.buffer.metadata['vc-info'] = '[svn:%s/%s]' % (lrev, rrev)
w.set_error('%s %s %s/%s [%s]' % (filename, status, rrev, lrev, lauthor))
else:
w.buffer.metadata['svn-filename'] = path
w.buffer.metadata['svn-status'] = status
w.buffer.metadata['vc-info'] = '[svn:%s]' % status.lower()
w.set_error('%s %s' % (path, status))
class SvnLog(Method):
'''display the SVN log for the current file'''

View File

@ -77,7 +77,7 @@ class Handler(object):
class Fundamental(Handler):
'''This is the default mode'''
modename = "Fundamental"
name = "Fundamental"
paths = []
basenames = []
extensions = []
@ -102,7 +102,6 @@ class Fundamental(Handler):
actions = []
_bindings = {}
completers = {}
#format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s"
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s %(perc)s %(vc-info)s"
header_size = 3
@ -124,12 +123,12 @@ class Fundamental(Handler):
rmargin = property(_get_rmargin, _set_rmargin)
def install(cls, app):
app.setmode(cls.modename.lower(), cls, paths=cls.paths,
app.setmode(cls.name.lower(), cls, paths=cls.paths,
bases=cls.basenames, exts=cls.extensions,
detection=cls.detection)
for (key, val) in cls.colors.iteritems():
if key in app.token_colors:
s = 'token_colors: name %r conflict in %r' % (key, cls.modename)
s = 'token_colors: name %r conflict in %r' % (key, cls.name)
raise Exception, s
else:
app.token_colors[key] = val
@ -290,14 +289,14 @@ class Fundamental(Handler):
# buffer settings
def get_setting(self, name):
self.window.buffer.settings.setdefault(self.modename, {})
return self.window.buffer.settings[self.modename].get(name)
self.window.buffer.settings.setdefault(self.name, {})
return self.window.buffer.settings[self.name].get(name)
def init_setting(self, name, value):
self.window.buffer.settings.setdefault(self.modename, {})
self.window.buffer.settings[self.modename].setdefault(name, value)
self.window.buffer.settings.setdefault(self.name, {})
self.window.buffer.settings[self.name].setdefault(name, value)
def set_setting(self, name, value):
self.window.buffer.settings.setdefault(self.modename, {})
self.window.buffer.settings[self.modename][name] = value
self.window.buffer.settings.setdefault(self.name, {})
self.window.buffer.settings[self.name][name] = value
# header
def showing_header(self):
@ -384,10 +383,6 @@ class Fundamental(Handler):
s = ' ' * lm
return [RenderString(s=s, attrs=color.build('default', 'default', 'bold'))]
# get mode name
def name(self):
return self.modename
def _get_flag(self):
b = self.window.buffer
if b.readonly():
@ -427,7 +422,7 @@ class Fundamental(Handler):
d = defaultdict(str)
d2 = {
'bname': w.buffer.name(),
'mname': self.name(),
'mname': self.name,
'flag': self._get_flag(),
'perc': self._get_perc(),
'indent': self._get_indent(),
@ -465,11 +460,11 @@ class Fundamental(Handler):
if DEBUG:
raise
else:
err = "%s in mode '%s'" % (e, self.name())
err = "%s in mode '%s'" % (e, self.name)
self.window.set_error(err)
def region_added(self, p, newlines):
mname = self.name()
mname = self.name
if self.lexer is not None:
ydelta = len(newlines) - 1
xdelta = len(newlines[-1])

View File

@ -131,8 +131,8 @@ class AwkFilterInput(Method):
w.set_error("awk exited with status %d" % status)
class Awk(mode.Fundamental):
name = 'awk'
tabbercls = AwkTabber
modename = 'awk'
extensions = ['.awk']
grammar = AwkGrammar
opentokens = ('delimiter',)

View File

@ -23,7 +23,7 @@ class BDSGrammar(Grammar):
]
class BDS(mode.Fundamental):
modename = 'bds'
name = 'bds'
extensions = ['.bds']
grammar = BDSGrammar
colors = {

View File

@ -15,7 +15,7 @@ class BlameGrammar(Grammar):
]
class Blame(mode.Fundamental):
modename = 'Blame'
name = 'Blame'
grammar = BlameGrammar
colors = {
'metadata.start': ('blue', 'default', 'bold'),

View File

@ -133,7 +133,7 @@ def _end(w):
assert not w.application.mini_active
class Brm(mode.Fundamental):
modename = 'Bicycle-Repairman'
name = 'Bicycle-Repairman'
actions = [ReplaceAll, ReplaceDone, ReplaceOne, SkipReplace, BrmCancel]
def __init__(self, w):
mode.Fundamental.__init__(self, w)

View File

@ -156,7 +156,7 @@ class CMake(method.shell.Exec):
cmdname='c-make')
class C(mode.Fundamental):
modename = 'C'
name = 'C'
extensions = ['.c', '.h', '.cpp']
tabbercls = CTabber2
grammar = CGrammar

View File

@ -33,7 +33,7 @@ class TemplateGrammar(Grammar):
]
class Template(mode.Fundamental):
modename = 'Cheetah'
name = 'Cheetah'
extensions = ['.tmpl']
grammar = TemplateGrammar
commentc = '##'

View File

@ -1,6 +1,6 @@
import mode
class Colortext(mode.Fundamental):
modename = 'Colortext'
name = 'Colortext'
install = Colortext.install

View File

@ -11,7 +11,7 @@ class ConfGrammar(Grammar):
]
class Conf(mode.Fundamental):
modename = 'conf'
name = 'conf'
extensions = ['.conf', '.cfg', '.cnf', '.config']
grammar = ConfGrammar
colors = {}

View File

@ -3,6 +3,6 @@ from lex import Grammar, PatternRule, RegionRule
from mode.python import StringGrammar1, StringGrammar2, PythonGrammar
class Console(mode.Fundamental):
modename = 'Console'
name = 'Console'
install = Console.install

View File

@ -214,7 +214,7 @@ class ConsoleGotoEnd(ConsoleBaseMethod):
subcls = method.move.GotoEnd
class ConsoleMini(mode.Fundamental):
modename = 'ConsoleMini'
name = 'ConsoleMini'
grammar = PythonGrammar
actions = [ConsoleExec, ConsoleClear, ConsoleCancel, ConsoleHistoryPrev,
ConsoleHistoryNext, ConsoleTab,

View File

@ -53,7 +53,7 @@ class CSSGrammar(Grammar):
]
class CSS(mode.Fundamental):
modename = 'CSS'
name = 'CSS'
extensions = ['.css']
grammar = CSSGrammar
opentokens = ('delimiter',)

View File

@ -12,7 +12,7 @@ class DiffGrammar(Grammar):
]
class Diff(mode.Fundamental):
modename = 'diff'
name = 'diff'
extensions = ['.patch', '.diff']
grammar = DiffGrammar()
colors = {

View File

@ -163,7 +163,7 @@ class RemovePath(Method):
w.set_error("failed to delete %r" % path)
class Dir(mode.Fundamental):
modename = 'Dir'
name = 'Dir'
grammar = DirGrammar()
colors = {
'dir_blk.start': ('cyan', 'default', 'bold'),

View File

@ -29,7 +29,7 @@ class ELispGrammar(Grammar):
]
class ELisp(mode.Fundamental):
modename = 'ELisp'
name = 'ELisp'
tabwidth = 2
basenames = ['.emacs']
extensions = ['.el']

View File

@ -84,7 +84,7 @@ class ErlangTabber(tab.StackTabber):
# Interact._execute(self, w, bname='*Erl*', cmd='erl')
class Erlang(mode.Fundamental):
modename = 'Erlang'
name = 'Erlang'
extensions = ['.erl']
tabwidth = 4
tabbercls = ErlangTabber

View File

@ -40,7 +40,7 @@ class ErrorGotoLine(Method):
w.set_error(errline)
class Error(mode.Fundamental):
modename = 'Error'
name = 'Error'
actions = [ErrorGotoLine]
def __init__(self, w):
mode.Fundamental.__init__(self, w)

View File

@ -119,7 +119,7 @@ class ForthTabber(tab.StackTabber2):
self.curr_level = 0
class Forth(Fundamental):
modename = 'FORTH'
name = 'FORTH'
extensions = ['.fs', '.fi', '.fb']
grammar = ForthGrammar
commentc = '\\ '

View File

@ -15,7 +15,7 @@ class FstabGrammar(Grammar):
]
class Fstab(mode.Fundamental):
modename = 'fstab'
name = 'fstab'
basenames = ['fstab']
grammar = FstabGrammar
colors = {

View File

@ -57,7 +57,7 @@ class HaskellTabber(tab.Tabber):
pass
class Haskell(mode.Fundamental):
modename = 'Haskell'
name = 'Haskell'
extensions = ['.hs']
tabwidth = 4
commentc = '--'

View File

@ -215,7 +215,7 @@ class ShowAddress(Method):
w.set_error("Cursor's address is 0x%08x" % addr)
class Hex(mode.Fundamental):
modename = 'Hex'
name = 'Hex'
config = {
'hex.disinst': 'disinst',
}

View File

@ -73,7 +73,7 @@ class HtmlCheckSpelling(method.Method):
w.buffer.reload()
class HTML(mode.Fundamental):
modename = 'HTML'
name = 'HTML'
extensions = ['.html', '.htm', '.shtml', '.shtm', '.xhtml']
grammar = HTMLGrammar
colors = {

View File

@ -25,7 +25,7 @@ class MiniInsertCancel(method.Method):
w.application.close_mini_buffer()
class InsertMini(mode.Fundamental):
modename = 'InsertMini'
name = 'InsertMini'
actions = [MiniInsertLine, MiniInsertComplete, MiniInsertCancel,
MiniInsertTab]
def __init__(self, w):

View File

@ -10,7 +10,7 @@ class IperlGrammar(Grammar):
PatternRule(r'iperl_reserved', r'undef'),
]
class Iperl(mode.Fundamental):
modename = 'IPerl'
name = 'IPerl'
grammar = IperlGrammar()
colors = {
'iperl_input.start': ('red', 'default', 'bold'),

View File

@ -91,7 +91,7 @@ class IperlGotoEnd(mode.consolemini.ConsoleGotoEnd):
subbuf = '*IPerl*'
class IperlMini(mode.Fundamental):
modename = 'IperlMini'
name = 'IperlMini'
actions = [IperlExec, IperlTab, IperlStart, IperlPathStart,
IperlPageUp, IperlPageDown, IperlGotoBeginning, IperlGotoEnd]
readre = re.compile('^([A-Z]+):(.*)\n$')

View File

@ -11,7 +11,7 @@ class IpythonGrammar(Grammar):
PatternRule(r'ipython_reserved', r'undef'),
]
class Ipython(mode.Fundamental):
modename = 'IPython'
name = 'IPython'
grammar = IpythonGrammar()
colors = {
'ipython_input.start': ('red', 'default', 'bold'),

View File

@ -88,7 +88,7 @@ class IpythonGotoEnd(mode.consolemini.ConsoleGotoEnd):
subbuf = '*IPython*'
class IpythonMini(mode.Fundamental):
modename = 'IpythonMini'
name = 'IpythonMini'
actions = [IpythonExec, IpythonTab, IpythonStart, IpythonPathStart,
IpythonPageUp, IpythonPageDown, IpythonGotoBeginning, IpythonGotoEnd]
def get_ipython(self):

View File

@ -117,7 +117,7 @@ class JavaContext(context.Context):
i += 1
class Java(mode.Fundamental):
modename = 'Java'
name = 'Java'
extensions = ['.java']
tabbercls = JavaTabber2
grammar = JavaGrammar

View File

@ -75,7 +75,7 @@ class JavascriptTabber2(tab.StackTabber2):
def is_base(self, y):
if y == 0:
return True
highlighter = self.mode.window.buffer.highlights[self.mode.name()]
highlighter = self.mode.window.buffer.highlights[self.mode.name]
if not highlighter.tokens[y]:
return False
t = highlighter.tokens[y][0]
@ -87,7 +87,7 @@ class JavascriptTabber2(tab.StackTabber2):
'comment.data', 'comment.null', 'comment.end')
class Javascript(mode.Fundamental):
modename = 'Javascript'
name = 'Javascript'
extensions = ['.js']
grammar = JavascriptGrammar
tabbercls = JavascriptTabber2

View File

@ -114,7 +114,7 @@ class LatexCheckSpelling(method.Method):
w.buffer.reload()
class Latex(mode.Fundamental):
modename = 'Latex'
name = 'Latex'
extensions = ['.latex', '.tex']
commentc = '%'
grammar = LatexGrammar

View File

@ -52,7 +52,7 @@ class LilyTabber(tab.StackTabber):
st = ('spaces', 'null',)
class Lily(mode.Fundamental):
modename = 'lily'
name = 'lily'
extensions = ['.ly']
tabwidth = 2
tabbercls = LilyTabber

View File

@ -36,7 +36,7 @@ class LispTabber(tab.StackTabber):
return currlvl
class Lisp(mode.Fundamental):
modename = 'Lisp'
name = 'Lisp'
tabwidth = 2
tabbercls = LispTabber
grammar = LispGrammar

View File

@ -38,7 +38,7 @@ class LuaCheckSyntax(method.Method):
app.data_buffer("*Lua-Check-Syntax*", output)
class Lua(mode.Fundamental):
modename = 'Lua'
name = 'Lua'
extensions = ['.lua']
#tabbercls = mode.lisp.LispTabber
grammar = LuaGrammar

View File

@ -33,7 +33,7 @@ class MakeGrammar(Grammar):
]
class Make(mode.Fundamental):
modename = 'Make'
name = 'Make'
basenames = ['Makefile']
grammar = MakeGrammar
commentc = '#'

View File

@ -210,7 +210,7 @@ class MailListGrammar(Grammar):
]
class MboxMsg(mode.Fundamental):
modename = 'MboxMsg'
name = 'MboxMsg'
colors = {
'mail_pgp': ('red', 'default', 'bold'),
'mail_signature.start': ('red', 'default', 'bold'),
@ -230,7 +230,7 @@ class MboxMsg(mode.Fundamental):
mode.Fundamental.__init__(self, w)
class Mbox(mode.Fundamental):
modename = 'Mbox'
name = 'Mbox'
grammar = MailListGrammar
actions = [MboxRefresh, MboxOpenPath, MboxReadMsg]
colors = {

View File

@ -38,7 +38,7 @@ class MiniTabComplete(method.Method):
use_completion_window(app, s2, candidates)
class Mini(mode.Fundamental):
modename = 'Mini'
name = 'Mini'
actions = [MiniCallback, MiniTabComplete]
def __init__(self, w):
mode.Fundamental.__init__(self, w)

View File

@ -122,7 +122,7 @@ class Mp3OpenPath(Method):
w.application.switch_buffer(b)
class Mp3(mode.Fundamental):
modename = 'Mp3'
name = 'Mp3'
grammar = Mp3Grammar
actions = [Mp3Refresh, Mp3OpenPath]
colors = {

View File

@ -24,7 +24,7 @@ class MuttInsertSpace(mode.text.TextInsertSpace):
wrapper = MuttWrapParagraph
class Mutt(mode.Fundamental):
modename = 'Mutt'
name = 'Mutt'
grammar = MuttGrammar()
colors = {
'mutt_header': ('green', 'default', 'bold'),

View File

@ -26,7 +26,7 @@ class NasmGrammar(Grammar):
]
class Nasm(mode.Fundamental):
modename = 'nasm'
name = 'nasm'
extensions = ['.s']
grammar = NasmGrammar
commentc = ';'

View File

@ -48,7 +48,7 @@ class OcamlGrammar(Grammar):
]
class Ocaml(mode.Fundamental):
modename = 'ocaml'
name = 'ocaml'
extensions = ['.mli', '.ml']
grammar = OcamlGrammar
opentokens = ('delimiter',)

View File

@ -420,7 +420,7 @@ class PerlWrapParagraph(method.WrapParagraph):
return t.name == 'spaces'
def _detect_line_type(self, w, y):
h = w.buffer.highlights[w.mode.name()]
h = w.buffer.highlights[w.mode.name]
ltype = None
for t in h.tokens[y]:
fqname = t.fqname()
@ -442,7 +442,7 @@ class PerlWrapParagraph(method.WrapParagraph):
return ltype
def _fix_comments(self, c, w):
h = w.buffer.highlights[w.mode.name()]
h = w.buffer.highlights[w.mode.name]
y1 = c.y
y2 = c.y
while y2 < len(w.buffer.lines) - 1:
@ -621,7 +621,7 @@ class PerlContext(context.Context):
i += 1
class Perl(mode.Fundamental):
modename = 'Perl'
name = 'Perl'
extensions = ['.pl', '.pm', '.pod']
detection = ['perl']
tabbercls = PerlTabber2

View File

@ -40,7 +40,7 @@ class PHPGrammar(Grammar):
# if y == 0:
# return True
#
# highlighter = self.mode.window.buffer.highlights[self.mode.name()]
# highlighter = self.mode.window.buffer.highlights[self.mode.name]
# if not highlighter.tokens[y]:
# return False
#
@ -161,7 +161,7 @@ class PHPGrammar(Grammar):
# return currlvl
class PHP(mode.Fundamental):
modename = 'PHP'
name = 'PHP'
extensions = ['.php']
#tabbercls = JavaTabber
grammar = PHPGrammar

View File

@ -19,7 +19,7 @@ class PipeInsertEsc(PipeInsertChr):
self.string = chr(27) + chr(i)
class Pipe(Fundamental):
modename = 'pipe'
name = 'pipe'
def __init__(self, w):
Fundamental.__init__(self, w)

View File

@ -541,7 +541,7 @@ class PythonContext(context.Context):
self.namelines[k] = (curr, None)
class Python(mode.Fundamental):
modename = 'Python'
name = 'Python'
extensions = ['.py']
detection = ['python']
tabbercls = PythonTabber
@ -580,7 +580,7 @@ class Python(mode.Fundamental):
"pythonclass": PythonClassCompleter(None),
}
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(name)s]"
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(name)s] %(vc-info)s"
header_size = 3
def get_status_names(self):
@ -592,7 +592,7 @@ class Python(mode.Fundamental):
# xyz
def get_header(self):
fg, bg = "default", "red"
fg, bg = "default", "blue"
if self.tabber is None:
s = "Header support is not available for this mode"

View File

@ -133,7 +133,7 @@ def _end(w):
assert not w.application.mini_active
class Replace(mode.Fundamental):
modename = 'Replace'
name = 'Replace'
actions = [ReplaceAll, ReplaceDone, ReplaceOne, SkipReplace, CancelReplace]
def __init__(self, w):
mode.Fundamental.__init__(self, w)

View File

@ -54,7 +54,7 @@ class RstBuild(Method):
pass
class RST(mode.Fundamental):
modename = 'RST'
name = 'RST'
extensions = ['.rst']
grammar = RSTGrammar
colors = {

View File

@ -51,7 +51,7 @@ class GuileLoadFile(method.shell.Interact):
b.pipe_write('(load "%s")\n' % path)
class Scheme(mode.Fundamental):
modename = 'Scheme'
name = 'Scheme'
extensions = ['.scm']
tabwidth = 2
tabbercls = mode.lisp.LispTabber

View File

@ -116,7 +116,7 @@ def _end(w):
w.application.last_search = w.buffer.make_string()
class Search(mode.Fundamental):
modename = 'Search'
name = 'Search'
actions = [SearchNext, SearchPrevious, EndSearch, CancelSearch,
SearchDeleteLeft, SearchDeleteLeftWord]
def __init__(self, w):

View File

@ -129,7 +129,7 @@ class ShTabber(tab.StackTabber):
def is_base(self, y):
if y == 0:
return True
highlighter = self.mode.window.buffer.highlights[self.mode.name()]
highlighter = self.mode.window.buffer.highlights[self.mode.name]
if not highlighter.tokens[y]:
return False
t = highlighter.tokens[y][0]
@ -166,7 +166,7 @@ class ShCheckSyntax(Method):
app.data_buffer("*Sh-Check-Syntax*", output)
class Sh(mode.Fundamental):
modename = 'sh'
name = 'sh'
paths = ['/etc/profile']
basenames = ['.bashrc', '.bash_profile', '.profile']
extensions = ['.bash', '.sh']

View File

@ -8,7 +8,7 @@ class ShellGrammar(Grammar):
PatternRule(r'shell_mesg', r'^===.*$'),
]
class Shell(mode.Fundamental):
modename = 'Shell'
name = 'Shell'
grammar = ShellGrammar()
colors = {
'shell_mesg': ('green', 'default', 'bold'),

View File

@ -130,7 +130,7 @@ class OpenShell(OpenShellRaw):
w.application.open_mini_buffer('>>> ', f, self, None, 'shellmini')
class ShellMini(mode.Fundamental):
modename = 'ShellMini'
name = 'ShellMini'
actions = [ShellExec, ShellClear, ShellCancel,
ShellHistoryPrev, ShellHistoryNext,
ShellTab,

View File

@ -73,7 +73,7 @@ class SqlTabber(tab.StackTabber):
def is_base(self, y):
if y == 0:
return True
highlighter = self.mode.window.buffer.highlights[self.mode.name()]
highlighter = self.mode.window.buffer.highlights[self.mode.name]
if not highlighter.tokens[y]:
return False
t = highlighter.tokens[y][0]
@ -113,7 +113,7 @@ class SqlTabber(tab.StackTabber):
return currlvl
class Sql(mode.Fundamental):
modename = 'Sql'
name = 'Sql'
extensions = ['.sql']
grammar = SqlGrammar
tabbercls = SqlTabber

View File

@ -54,7 +54,7 @@ class LearnWord(method.Method):
cursor = w.logical_cursor()
word = None
for token in w.buffer.highlights[w.mode.name()].tokens[cursor.y]:
for token in w.buffer.highlights[w.mode.name].tokens[cursor.y]:
if (token.x <= cursor.x and
token.end_x() > cursor.x and
token.name == 'misspelled'):
@ -72,8 +72,8 @@ class LearnWord(method.Method):
w.left_delete()
class Text(mode.Fundamental):
modename = 'Text'
extensions=['.txt']
name = 'Text'
extensions = ['.txt']
grammar = TextGrammar
actions = [LearnWord, TextInsertSpace, TextWrapParagraph]
config = {

View File

@ -13,7 +13,7 @@ class Text2Grammar(Grammar):
]
class Text2(mode.text.Text):
modename = 'Text2'
name = 'Text2'
grammar = Text2Grammar
extensions = ['.txt']
extensions = []

View File

@ -30,7 +30,7 @@ class TemplateGrammar(Grammar):
]
class Template(mode.Fundamental):
modename = 'Template'
name = 'Template'
extensions = ['.tt']
grammar = TemplateGrammar
colors = {

View File

@ -2,7 +2,7 @@ import color, method, mode
from point import Point
class Which(mode.Fundamental):
modename = 'Which'
name = 'Which'
def __init__(self, w):
mode.Fundamental.__init__(self, w)
old_mode = w.buffer.method.old_window.mode
@ -22,7 +22,7 @@ class Which(mode.Fundamental):
if mode.DEBUG:
raise
else:
err = "%s in mode '%s'" % (e, self.name())
err = "%s in mode '%s'" % (e, self.name)
self.window.application.set_error(err)
self._end()
def _end(self):

View File

@ -113,7 +113,7 @@ class XmlCreateCdata(method.Method):
w.goto(p)
class XML(mode.Fundamental):
modename = 'XML'
name = 'XML'
extensions = ['.xml', '.xml.in', '.xsl', '.xsd']
grammar = XMLGrammar
colors = {

View File

@ -42,7 +42,7 @@ class YaccTabber(CTabber2):
end_free_tokens = {'string.end': 'string.start'}
class Yacc(mode.Fundamental):
modename = 'yacc'
name = 'yacc'
extensions = ['.y']
grammar = YaccGrammar
tabbercls = YaccTabber

8
tab.py
View File

@ -19,11 +19,11 @@ class Tabber(object):
self.lines = {}
def get_highlighter(self):
return self.mode.window.buffer.highlights[self.mode.name()]
return self.mode.window.buffer.highlights[self.mode.name]
def get_tokens(self, y):
return self.mode.window.buffer.highlights[self.mode.name()].tokens[y]
return self.mode.window.buffer.highlights[self.mode.name].tokens[y]
def get_token(self, y, i):
return self.mode.window.buffer.highlights[self.mode.name()].tokens[y][i]
return self.mode.window.buffer.highlights[self.mode.name].tokens[y][i]
def token_is_whitespace(self, y, i):
token = self.get_token(y, i)
@ -256,7 +256,7 @@ class StackTabber2(Tabber):
fixed_indent = False
def __init__(self, m):
self.mode = m
self.name = m.name()
self.name = m.name
self.lines = {}
self._reset()
def region_added(self, p, newlines):

View File

@ -54,14 +54,14 @@ def dump(x):
return '%s: %r' % (x, d)
def get_margin_limit(w, def_limit=80):
lname = '%s.margin' % w.mode.name().lower()
lname = '%s.margin' % w.mode.name.lower()
if lname in w.application.config:
return w.application.config[lname]
else:
return w.application.config.get('margin', def_limit)
def get_margin_color(w, def_color='blue'):
lname = '%s.margin_color' % w.mode.name().lower()
lname = '%s.margin_color' % w.mode.name.lower()
if lname in w.application.config:
return w.application.config[lname]
else:

View File

@ -83,17 +83,16 @@ class Window(object):
# mode stuff
def set_mode(self, m):
self.mode = m
modename = m.name()
if modename not in self.buffer.highlights and m.lexer is not None:
self.buffer.highlights[modename] = highlight.Highlighter(m.lexer)
self.buffer.highlights[modename].highlight(self.buffer.lines)
if m.name not in self.buffer.highlights and m.lexer is not None:
self.buffer.highlights[m.name] = highlight.Highlighter(m.lexer)
self.buffer.highlights[m.name].highlight(self.buffer.lines)
#self.redraw()
def get_highlighter(self):
if self.mode.lexer is None:
return None
else:
return self.buffer.highlights[self.mode.name()]
return self.buffer.highlights[self.mode.name]
# this is used to temporarily draw the user's attention to another point
def set_active_point(self, p, msg='marking on line %(y)d, char %(x)d'):
@ -721,8 +720,7 @@ class Window(object):
# render methods return a list of lists of RenderString objects
# (i.e. multiple physical lines containing multiple areas to be drawn)
def render_line(self, y, width):
modename = self.mode.name()
if modename in self.buffer.highlights:
if self.mode.name in self.buffer.highlights:
return self.render_line_lit(y, width)
else:
return self.render_line_raw(y, width)
@ -749,8 +747,7 @@ class Window(object):
r = RenderString(s='~', attrs=color.build('red', 'default'))
return [(r,)]
modename = self.mode.name()
highlighter = self.buffer.highlights[modename]
highlighter = self.buffer.highlights[self.mode.name]
line = []
lines = []