more improvements for C mode, config variables

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-03-21 05:32:03 +00:00
parent d49e69691c
commit de8920d5e0
3 changed files with 30 additions and 12 deletions

View File

@ -918,9 +918,9 @@ class GetConfigVariable(Method):
name = vargs['name'] name = vargs['name']
if name in w.application.config: if name in w.application.config:
value = w.application.config[name] value = w.application.config[name]
w.set_error("param %s set to %r" % (name, value)) w.set_error("param %r set to %r" % (name, value))
else: else:
w.set_error("param %s is not set" % (name,)) w.set_error("param %r is not set" % (name,))
class ViewConfigVariables(Method): class ViewConfigVariables(Method):
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
@ -936,10 +936,14 @@ class SetConfigVariable(Method):
arg('value', t=type(''), p="Variable value: ", arg('value', t=type(''), p="Variable value: ",
h='Configuration parameter value to use')] h='Configuration parameter value to use')]
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
name, value = vargs['name'], vargs['value'] name = vargs['name']
found = name in w.application.config found = name in w.application.config
try:
value = eval(vargs['value'])
except:
value = vargs['value']
w.application.config[name] = value w.application.config[name] = value
if found: if found:
w.set_error("param %s set to %r" % (name, value)) w.set_error("param %r set to %r" % (name, value))
else: else:
w.set_error("previously unset param %s set to %r" % (name, value)) w.set_error("previously unset param %r set to %r" % (name, value))

View File

@ -10,7 +10,9 @@ 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 show_success = True
args = [Argument('cmd', prompt="Exec: ", datatype='shell')] args = [Argument('cmd', prompt="Exec: ", datatype='shell')]
def _doit(self, w, path, cmd, cmdname=None, bufname=None): def _doit(self, w, path, cmd, cmdname=None, bufname=None, cmddir=None):
if cmddir:
cmd = "cd %r && %s" % (cmddir, cmd)
if path: if path:
try: try:
cmd = cmd % {'path': path} cmd = cmd % {'path': path}

View File

@ -209,8 +209,10 @@ class C(mode.Fundamental):
'enumname': ('yellow', 'default'), 'enumname': ('yellow', 'default'),
} }
config = { config = {
'c.syntaxcmd': "gcc -x c -fsyntax-only %(path)s", 'c.syntax-cmd': "gcc -x c -fsyntax-only %(path)s",
'c.makecmd': "make", 'c.syntax-rel-dir': False,
'c.make-cmd': "make",
'c.make-rel-dir': True,
} }
def __init__(self, w): def __init__(self, w):
mode.Fundamental.__init__(self, w) mode.Fundamental.__init__(self, w)
@ -225,15 +227,25 @@ class CCheckSyntax(method.shell.Exec):
show_success = False show_success = False
args = [] args = []
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
self._doit(w, w.buffer.path, w.application.config['c.syntaxcmd'], if w.application.config['c.syntax-rel-dir']:
cmdname='c-check-syntax') d = os.path.dirname(w.buffer.path)
self._doit(w, w.buffer.path, w.application.config['c.syntax-cmd'],
cmdname='c-check-syntax', cmddir=d)
else:
self._doit(w, w.buffer.path, w.application.config['c.syntax-cmd'],
cmdname='c-check-syntax')
class CMake(method.shell.Exec): class CMake(method.shell.Exec):
'''Build this C program (using the mode's make cmd)''' '''Build this C program (using the mode's make cmd)'''
show_success = False show_success = False
args = [] args = []
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
self._doit(w, w.buffer.path, w.application.config['c.makecmd'], if w.application.config['c.make-rel-dir']:
cmdname='c-make') d = os.path.dirname(w.buffer.path)
self._doit(w, w.buffer.path, w.application.config['c.make-cmd'],
cmdname='c-make', cmddir=d)
else:
self._doit(w, w.buffer.path, w.application.config['c.make-cmd'],
cmdname='c-make')
install = C.install install = C.install