some fixes and improvements

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-03-21 01:58:30 +00:00
parent 596ca72324
commit d49e69691c
7 changed files with 101 additions and 52 deletions

6
IDEAS
View File

@ -22,10 +22,6 @@ buffer, rather than storing all this junk piecemeal.
2007/07/19: 2007/07/19:
Convert all classes to subclass object.
2007/07/19:
The minibuffer should be able to expand to become multi-line if the The minibuffer should be able to expand to become multi-line if the
prompt/input string becomes too long. prompt/input string becomes too long.
@ -34,6 +30,8 @@ prompt/input string becomes too long.
It would be nice to be able to toggle various lexing rules on/off, so that for It would be nice to be able to toggle various lexing rules on/off, so that for
instance text mode could make spell checking optional, or optionally highlight instance text mode could make spell checking optional, or optionally highlight
URLs/emails/etc. URLs/emails/etc.
AMENDED (2008/03/20): in the case of spell-checking and other non-standard
rules, we can do this with state variables in the mode.
2007/07/15: 2007/07/15:

View File

@ -41,6 +41,7 @@ class Application(object):
# initialize some basic stuff # initialize some basic stuff
# each highlighted_range contains three things: (window, start_p, end_p) # each highlighted_range contains three things: (window, start_p, end_p)
self.config = {}
self.highlighted_ranges = [] self.highlighted_ranges = []
self.mini_active = False self.mini_active = False
self.mini_buffer = None self.mini_buffer = None
@ -184,6 +185,7 @@ class Application(object):
method.DATATYPES['buffer'] = completer.BufferCompleter(self) method.DATATYPES['buffer'] = completer.BufferCompleter(self)
method.DATATYPES['command'] = completer.CommandCompleter() method.DATATYPES['command'] = completer.CommandCompleter()
method.DATATYPES['shell'] = completer.ShellCompleter() method.DATATYPES['shell'] = completer.ShellCompleter()
method.DATATYPES['config'] = completer.ConfigCompleter()
method.DATATYPES['method'] = completer.MethodCompleter() method.DATATYPES['method'] = completer.MethodCompleter()
method.DATATYPES['register'] = completer.RegisterCompleter() method.DATATYPES['register'] = completer.RegisterCompleter()
method.DATATYPES['mode'] = completer.ModeCompleter() method.DATATYPES['mode'] = completer.ModeCompleter()

View File

@ -94,6 +94,10 @@ class MethodCompleter(Completer):
def get_candidates(self, s, w=None): def get_candidates(self, s, w=None):
return [n for n in w.application.methods if n.startswith(s)] return [n for n in w.application.methods if n.startswith(s)]
class ConfigCompleter(Completer):
def get_candidates(self, s, w=None):
return [n for n in w.application.config if n.startswith(s)]
class RegisterCompleter(Completer): class RegisterCompleter(Completer):
def get_candidates(self, s, w=None): def get_candidates(self, s, w=None):
return [n for n in w.application.registers if n.startswith(s)] return [n for n in w.application.registers if n.startswith(s)]

View File

@ -7,6 +7,7 @@ from point import Point
DATATYPES = { DATATYPES = {
"path": None, "path": None,
"buffer": None, "buffer": None,
"config": None,
"method": None, "method": None,
"register": None, "register": None,
"command": None, "command": None,
@ -909,3 +910,36 @@ class RegisterRestore(Method):
if len(name) > self.MAX_REG: if len(name) > self.MAX_REG:
name = name[0:self.MAX_REG] + '...' name = name[0:self.MAX_REG] + '...'
w.set_error('Restored %r from register %r' % (text, name)) w.set_error('Restored %r from register %r' % (text, name))
class GetConfigVariable(Method):
args = [arg('name', dt='config', p="Variable name: ",
h='Name of the configuration parameter')]
def _execute(self, w, **vargs):
name = vargs['name']
if name in w.application.config:
value = w.application.config[name]
w.set_error("param %s set to %r" % (name, value))
else:
w.set_error("param %s is not set" % (name,))
class ViewConfigVariables(Method):
def _execute(self, w, **vargs):
lines = ["APPLICATION CONFIGURATION VARIABLES\n"]
for name in w.application.config:
lines.append(" %-20s %r\n" % (name, w.application.config[name]))
data = ''.join(lines)
w.application.data_buffer('*Config*', data, switch_to=True)
class SetConfigVariable(Method):
args = [arg('name', dt='config', p="Variable name: ",
h='Name of the configuration parameter'),
arg('value', t=type(''), p="Variable value: ",
h='Configuration parameter value to use')]
def _execute(self, w, **vargs):
name, value = vargs['name'], vargs['value']
found = name in w.application.config
w.application.config[name] = value
if found:
w.set_error("param %s set to %r" % (name, value))
else:
w.set_error("previously unset param %s set to %r" % (name, value))

View File

@ -8,20 +8,38 @@ from method import DATATYPES, Method, Argument
class Exec(Method): class Exec(Method):
'''Execute a command in a shell and put the output in a new buffer''' '''Execute a command in a shell and put the output in a new buffer'''
show_success = True
args = [Argument('cmd', prompt="Exec: ", datatype='shell')] args = [Argument('cmd', prompt="Exec: ", datatype='shell')]
def _doit(self, w, path, cmd): def _doit(self, w, path, cmd, cmdname=None, bufname=None):
if path: if path:
try: try:
cmd = cmd % {'path': path} cmd = cmd % {'path': path}
except: except:
pass pass
(status, output) = commands.getstatusoutput(cmd)
self._display(w, output, status, cmd)
def _display(self, w, data, status, cmd): if bufname is None:
bufname = '*%s*' % self.name.title() bufname = '*%s*' % self.name.title()
w.application.data_buffer(bufname, data, switch_to=True) if cmdname is None:
w.set_error("Shell exited with %d" % status) cmdname = cmd.split(None, 1)[0]
p = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT)
output = p.stdout.read()
result = p.wait()
status = os.WEXITSTATUS(result)
if not os.WIFEXITED(result):
err = True
errmsg = "%s: killed by signal %r" % (cmdname, os.WTERMSIG(result))
elif status != 0:
err = True
errmsg = "%s: failed with status %r" % (cmdname, status)
else:
err = False
errmsg = "%s: ok" % (cmdname,)
if output:
switch_to = err or self.show_success
w.application.data_buffer(bufname, output, switch_to=switch_to)
w.set_error(errmsg)
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
if w.buffer.btype == 'dir': if w.buffer.btype == 'dir':

View File

@ -74,18 +74,19 @@ class Handler(object):
class Fundamental(Handler): class Fundamental(Handler):
'''This is the default mode''' '''This is the default mode'''
modename = "Fundamental" modename = "Fundamental"
paths = [] paths = []
basenames = [] basenames = []
extensions = [] extensions = []
detection = [] detection = []
savetabs = False savetabs = False
tabwidth = 4 tabwidth = 4
tabbercls = None tabbercls = None
grammar = None grammar = None
lexer = None lexer = None
tabber = None tabber = None
colors = {} colors = {}
config = {}
def install(cls, app): def install(cls, app):
app.setmode(cls.modename.lower(), cls, paths=cls.paths, app.setmode(cls.modename.lower(), cls, paths=cls.paths,
@ -97,6 +98,8 @@ class Fundamental(Handler):
raise Exception, s raise Exception, s
else: else:
app.token_colors[key] = val app.token_colors[key] = val
for (key, val) in cls.config.iteritems():
app.config[key] = val
install = classmethod(install) install = classmethod(install)
def __init__(self, w): def __init__(self, w):

View File

@ -1,6 +1,6 @@
import os, re import os, re
from subprocess import Popen, PIPE, STDOUT from subprocess import Popen, PIPE, STDOUT
import color, default, method, mode, tab import color, default, method, method.shell, mode, tab
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule from lex import Grammar, PatternRule, RegionRule, OverridePatternRule
from mode.python import StringGrammar from mode.python import StringGrammar
@ -208,42 +208,32 @@ class C(mode.Fundamental):
'structname': ('yellow', 'default'), 'structname': ('yellow', 'default'),
'enumname': ('yellow', 'default'), 'enumname': ('yellow', 'default'),
} }
config = {
'c.syntaxcmd': "gcc -x c -fsyntax-only %(path)s",
'c.makecmd': "make",
}
def __init__(self, w): def __init__(self, w):
mode.Fundamental.__init__(self, w) mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',)) self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',)) self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',)) self.add_bindings('close-bracket', (']',))
self.add_action_and_bindings(CCheckSyntax(), ('C-c s',))
self.add_action_and_bindings(CMake(), ('C-c C-c',)) self.add_action_and_bindings(CMake(), ('C-c C-c',))
self.add_action_and_bindings(CSetMake(), ('C-c M-m',))
self.makecmd = "make"
class CSetMake(method.Method): class CCheckSyntax(method.shell.Exec):
'''Set the path(s) to find perl modules''' '''Build this C program (using the mode's make cmd)'''
args = [method.Argument("cmd", type=type(""), prompt="Make Cmd: ", show_success = False
default=default.build_constant("make"))] args = []
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
w.mode.makecmd = vargs['cmd'] self._doit(w, w.buffer.path, w.application.config['c.syntaxcmd'],
cmdname='c-check-syntax')
class CMake(method.Method): class CMake(method.shell.Exec):
'''Check the syntax of the current python file''' '''Build this C program (using the mode's make cmd)'''
show_success = False
args = []
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
p = Popen(w.mode.makecmd, stdout=PIPE) self._doit(w, w.buffer.path, w.application.config['c.makecmd'],
output = p.stdout.read() cmdname='c-make')
result = p.wait()
status = os.WEXITSTATUS(result)
if not os.WIFEXITED(result):
err = True
errmsg = "make: killed by signal %r" % os.WTERMSIG(result)
elif status != 0:
err = True
errmsg = "make: failed with status %r" % status
else:
err = False
errmsg = "make: OK (output in *CMake*)"
w.application.data_buffer("*CMake*", output, switch_to=err)
w.set_error(errmsg)
install = C.install install = C.install