Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0613b7b

Browse files
Use tmp file for evaluating
1 parent 1e7f231 commit 0613b7b

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

‎emacs_ob_sagemath.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# -*- coding: utf-8; mode: sage -*-
22
from __future__ import print_function
33

4-
from sage.repl.rich_output.output_catalog import OutputImagePng
4+
import sage.misc.latex
5+
from emacs_sage_shell import read_file_and_run_cell as ss_read_file_and_run_cell
6+
from emacs_sage_shell import ip
7+
from sage.repl.rich_output import get_display_manager
58
from sage.repl.rich_output.backend_ipython import BackendIPythonCommandline
69
from sage.repl.rich_output.output_basic import OutputLatex
7-
from sage.repl.rich_output import get_display_manager
10+
from sage.repl.rich_output.output_catalog import OutputImagePng
811
from sage.repl.rich_output.preferences import DisplayPreferences
9-
import sage.misc.latex
10-
from emacs_sage_shell import ip
1112

1213

1314
class LastState(object):
@@ -67,22 +68,29 @@ def displayhook(self, plain_text, rich_output):
6768
gdm = get_display_manager()
6869

6970

70-
def run_cell_babel(code, filename=None, latex=None, latex_formatter=None):
71+
def run_cell_babel_base(run_cell_func,
72+
filename=None, latex=None, latex_formatter=None):
7173
last_state.filename = filename
7274
last_state.result = None
7375
last_state.latex = latex
7476
last_state.latex_formatter = latex_formatter
7577

7678
backend_ob_sage = BackendEmacsBabel(last_state)
7779
with sagebackend(backend_ob_sage):
78-
res = ip.run_cell(code)
80+
res = run_cell_func()
7981
if res.success:
8082
last_state.result = res.result
8183
print(1)
8284
else:
8385
print(0)
8486

8587

88+
def read_file_and_run_cell(tmp_file, **kwargs):
89+
def run_cel_func():
90+
return ss_read_file_and_run_cell(tmp_file)
91+
run_cell_babel_base(run_cel_func, **kwargs)
92+
93+
8694
class WithBackEnd(object):
8795

8896
def __init__(self, back_end):

‎ob-sagemath.el

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,17 @@ buffer."
348348
(replace-regexp-in-string (rx "\n") "\\n" raw-code nil t))
349349

350350
(defun ob-sagemath--code (raw-code params buf)
351-
(let ((code (ob-sagemath--escape-code raw-code)))
351+
"Return code for evaluatation."
352+
(let ((tmp-file (sage-shell-edit:temp-file "sage")))
353+
(with-temp-buffer
354+
(insert raw-code)
355+
(sage-shell-edit:write-region-to-file
356+
(point-min)
357+
(point-max)
358+
tmp-file))
352359
(format "%s(\"%s\", filename=%s, latex=%s, latex_formatter=%s)"
353-
(ob-sagemath--python-name "run_cell_babel")
354-
code
360+
(ob-sagemath--python-name "read_file_and_run_cell")
361+
tmp-file
355362
(ob-sagemath--result-file-name params buf)
356363
(ob-sagemath--latex-arg params)
357364
(ob-sagemath--latex-fmttr params))))
@@ -375,6 +382,7 @@ buffer."
375382
(t "None"))))
376383

377384
(defun ob-sagemath--result-file-name (params buf)
385+
"Return png file name."
378386
(sage-shell:aif (assoc-default :file params)
379387
(format "\"%s\""
380388
(with-current-buffer buf

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /