sagemath / sage-shell-mode

Emacs front end for SageMath
GNU General Public License v3.0
102 stars 16 forks source link

Using %cython directive #27

Open johanrosenkilde opened 7 years ago

johanrosenkilde commented 7 years ago

I can't get sage-shell-mode to accept %cython magic markers. The same code that copy-paste works in the IPython Sage shell gives the following error when C-c C-r'ing the code inside Emacs:

sage: load('/tmp/sage_shell_mode14470ZZ2/sage_shell_mode_temp.sage')
  File "<string>", line 2
    %%cython
    ^
SyntaxError: invalid syntax

Is there any way to make %%cython work?

stakemori commented 7 years ago

Thanks for report. I think it is possible to implement such a command for any magic function.

stakemori commented 7 years ago

You can now use %%cython when evaluating regions or buffers. But it seems that %%cython must be at the top line of the region or the buffer. Otherwise it will raise an error. It may be a bug of get_ipython().run_cell or %%cython. For example, evaluating the following code with C-c C-c raises an error. Without the first statement, it works fine.

    a = 1
    %%cython
    def f(double x):
        return x * x + x

The following also works fine.

    %%cython
    def f(double x):
        return x * x + x

    a = 1

By the way, you can also use other magic functions.

johanrosenkilde commented 7 years ago

This is a great addition - thanks!