From 3a731e6e2983ebb5240b3ea92c98c107d6e6c137 Mon Sep 17 00:00:00 2001 From: moculus Date: Wed, 17 Oct 2007 21:39:26 +0000 Subject: [PATCH] make --HG-- branch : pmacs2 --- mode/c.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/mode/c.py b/mode/c.py index c024875..adefab3 100644 --- a/mode/c.py +++ b/mode/c.py @@ -1,5 +1,5 @@ -import re -import color, mode2, tab2 +import popen2, re +import color, method, mode2, tab2 from lex3 import Grammar, PatternRule, RegionRule from mode.python import StringGrammar @@ -237,5 +237,35 @@ class C(mode2.Fundamental): self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) + self.add_action_and_bindings(CMake(), ('C-c C-c',)) + self.add_action_and_bindings(CSetMake(), ('C-c C-m',)) + self.makecmd = "make" def name(self): return "C" + +class CSetMake(method.Method): + '''Set the path(s) to find perl modules''' + args = [method.Argument("cmd", type=type(""), prompt="Make Cmd: ", + default=default.build_constant("make"))] + def _execute(self, w, **vargs): + w.mode.makecmd = vargs['cmd'] + +class CMake(method.Method): + '''Check the syntax of the current python file''' + def _execute(self, w, **vargs): + p = popen2.Popen4(w.makecmd) + p.tochild.close() + output = p.fromchild.read() + result = p.wait() + + if not os.WIFEXITED(result): + sig = os.WTERMSIG(result) + w.application.data_buffer("*CMake*", output, switch_to=True) + w.set_error("make: killed by signal %r" % sig) + else: + status = os.WEXITSTATUS(result) + if status == 0: + w.set_error("make: OK") + else: + w.application.data_buffer("*CMake*", output, switch_to=True) + w.set_error("make: failed with status %r" % status)