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']
if name in w.application.config:
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:
w.set_error("param %s is not set" % (name,))
w.set_error("param %r is not set" % (name,))
class ViewConfigVariables(Method):
def _execute(self, w, **vargs):
@ -936,10 +936,14 @@ class SetConfigVariable(Method):
arg('value', t=type(''), p="Variable value: ",
h='Configuration parameter value to use')]
def _execute(self, w, **vargs):
name, value = vargs['name'], vargs['value']
name = vargs['name']
found = name in w.application.config
try:
value = eval(vargs['value'])
except:
value = vargs['value']
w.application.config[name] = value
if found:
w.set_error("param %s set to %r" % (name, value))
w.set_error("param %r set to %r" % (name, value))
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'''
show_success = True
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:
try:
cmd = cmd % {'path': path}

View File

@ -209,8 +209,10 @@ class C(mode.Fundamental):
'enumname': ('yellow', 'default'),
}
config = {
'c.syntaxcmd': "gcc -x c -fsyntax-only %(path)s",
'c.makecmd': "make",
'c.syntax-cmd': "gcc -x c -fsyntax-only %(path)s",
'c.syntax-rel-dir': False,
'c.make-cmd': "make",
'c.make-rel-dir': True,
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
@ -225,7 +227,12 @@ class CCheckSyntax(method.shell.Exec):
show_success = False
args = []
def _execute(self, w, **vargs):
self._doit(w, w.buffer.path, w.application.config['c.syntaxcmd'],
if w.application.config['c.syntax-rel-dir']:
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):
@ -233,7 +240,12 @@ class CMake(method.shell.Exec):
show_success = False
args = []
def _execute(self, w, **vargs):
self._doit(w, w.buffer.path, w.application.config['c.makecmd'],
if w.application.config['c.make-rel-dir']:
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