From de8920d5e076528a00c31c9849392cb77a297fdd Mon Sep 17 00:00:00 2001 From: moculus Date: Fri, 21 Mar 2008 05:32:03 +0000 Subject: [PATCH] more improvements for C mode, config variables --HG-- branch : pmacs2 --- method/__init__.py | 14 +++++++++----- method/shell.py | 4 +++- mode/c.py | 24 ++++++++++++++++++------ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/method/__init__.py b/method/__init__.py index 337b08c..add9c9e 100644 --- a/method/__init__.py +++ b/method/__init__.py @@ -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)) diff --git a/method/shell.py b/method/shell.py index 1d508e5..853bf3d 100644 --- a/method/shell.py +++ b/method/shell.py @@ -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} diff --git a/mode/c.py b/mode/c.py index 0dbe5a9..7c1ad05 100644 --- a/mode/c.py +++ b/mode/c.py @@ -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,15 +227,25 @@ 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'], - cmdname='c-check-syntax') + 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): '''Build this C program (using the mode's make cmd)''' show_success = False args = [] def _execute(self, w, **vargs): - self._doit(w, w.buffer.path, w.application.config['c.makecmd'], - cmdname='c-make') + 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