Loading ...
Sorry, an error occurred while loading the content.

1736Sending buffer to a shell and then getting results

Expand Messages
  • Jeremy Cowgar
    Dec 5, 2005
      I'm a bit confused, I've been through the docs and I cannot quite get a handle
      on how to accomplish this.

      I want to create a macro that sends the buffer contents to a shell command and
      then have the macro parse the results from the shell command. I do not wish
      to have the output of the shell command be echoed back to the current buffer.

      I do not care if I have to use another temporary buffer to work in, but I am
      confused on how do I get the contents of the buffer? I have written a few
      modes, a few simple macros (search/replace) but have never had to get the
      buffer contents or work with external commands.

      What this macro does is check's the syntax of a python file live. It's an idea
      I got from a NEdit macro that I stumbled across, A simple syntaxCheck.py file
      sends the contents passed to it to the python compile() command, compile will
      return any errors or nothing if no errors occurred.

      I will then parse the results of the errors (which I control the output of via
      the syntaxCheck.py file) and hopefully hilight any errors that syntaxCheck.py
      finds with my current python buffer.

      syntaxCheck.py is very simple:

      #!/usr/bin/env python

      import sys, os
      f = "%s\n" % "".join(sys.stdin) # file without ending \n otherwise pukes
      compile(f, "", "exec")
      except Exception, e:
      print "%s\n%d\n%d\n%s\n" % (e.msg, e.lineno, e.offset, e.text)

      I want to work with the buffer so I don't have to save all the time to do a
      check, and then have to read in syntaxCheck.py the file, etc... Seems a lot
      simpler to just pass buffer contents.

      Thanks for any help!

      Jeremy Cowgar