vgvassilev / cling

The interactive C++ interpreter Cling
https://rawgit.com/vgvassilev/cling/master/www/index.html
Other
1.77k stars 102 forks source link

Paste multi-line clipboard content in cling interpreter #186

Open tgy opened 6 years ago

tgy commented 6 years ago

I like the workflow of

  1. having my code opened with Vim on a tmux pane on the left
  2. having the intepreter opened on a tmux pane on the right
  3. editing some code in Vim
  4. pasting it with the awesome vim-slime plugin to the interpreter

I can do this with ipython but I'm currently unable to reproduce this with cling for multi-line pastes.

When I paste some multi-line code to cling, each line is executed individually.

So, of course, the following c++ code

#include <iostream>
using namespace std;
for (int i = 0; i < 10; ++i)
{
  cout << "hello" << endl;
}

when pasted to cling does not work:

[cling]$ #include <utility>
[cling]$ #include <iostream>
[cling]$ using namespace std;
for (int i = 0; i < 10; ++i)
{
  cout << "hello" << endl;
}
[cling]$ for (int i = 0; i < 10; ++i)
{
  cout << "hello" << endl;
}
[cling]$ {
[cling]$ ?     cout << "hello" << endl;
}
[cling]$ ?   }
hello

Is there an already existing solution to this?

jarmitage commented 5 years ago

Multi-line commands work via

{
? #include <iostream>
? using namespace std;
? for (int i = 0; i < 10; ++i)
? {
?   cout << "hello" << endl;
? }
}

So you could probably make a macro to do this?

See https://root.cern.ch/root/htmldoc/guides/users-guide/Cling.html