1

It would be really useful if emacs could detect the cursor is currently inside a code-block in my markdown-file and compiles the fragment automatically.

I am editing a large markdown file with a lot of code sections in it. Most code sections begin with #!cpp filename=somefile.cpp test=output, which means: *The code is a real and complete code fragment that is compileable, runnable (ie, contains main) and contains its own test data (in //= commented lines).

Here is an example:

You can *initialize* a `vector`:

%%heading: It is empty.

    #!cpp filename=41vector-init-default.cpp test=output.cpp
    #include <vector>
    #include <iostream>
    using std::vector; using std::cout;
    int main() {
       vector<int> dataA;
       vector<int> dataB{};
       vector<int> dataC = {};
       cout << dataA.size() << ' ' dataB.size() << ' ' << dataC.size() << '\n';
       //= 0 0 0
    }

You can *copy* it:

%%heading: Copy the thing

    #!cpp filename=41vector-init-copy.cpp test=output
    #include <vector>
    #include <iostream>
    using std::vector; using std::cout;
    int main() {
        vector<int> input{1,2,3};
        vector<int> output(input);
        cout << output.size() << '\n';
        //= 3
    }

There you go.

It would be really useful if emacs could detect the cursor us currently inside a #!cpp-Block and execute my python-script ly-compile.py on it that compiles, executes and checks it. Maybe each time I move the cursor inside such a section or change text inside of it. The result of the python script should be shown in a separate buffer/window, on-the-fly.

The python-script takes filename to compile and a bunch of command-line arguments taken form the #!cpp-line. I could adjust it so it reals all it needs from stdin.

How can I plug the different things together that emacs already can do or tweak them so it works on-the-fly? flymake seems to be a candidate, but how?

towi
  • 111
  • 4

0 Answers0