Skip to content

Commit

Permalink
new image file name is the last in the directory plus one
Browse files Browse the repository at this point in the history
  • Loading branch information
BB committed Nov 4, 2019
1 parent 453bba8 commit bf5195c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ described above.
* If `plt.show()` is detected in code block, it will be replaced with
`plt.savefig(..)` command and a `\includegraphics` LaTeX command will
be added in the TeX buffer, same for Markdown. How do we determine
which image file name to generate? All previous code in buffer is
scanned for `plt.savefig(..)` commands, say there were 5 of them, in
this case `show()` will be replaced with
`plt.savefig('[file]_6.png')`,
which image file name to generate? All previous image files with png
extension are searched, e.g. if `test_01.png`, `test_02.png` exist,
the new file will be the last one in the list plus 1, so in this case
`show()` will be replaced with `plt.savefig('test_03.png')`,

* After entering any expression, hit F-5 or call
`'ipython-tex-complete-py`, and emacs-ipython will show a list of
Expand Down
8 changes: 5 additions & 3 deletions ipython-md.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ def run_py_code():

# generate savefig for execution code (no output in emacs yet)
bc = lisp.buffer_string()
#plt_count_before = len(re.findall('plt\.savefig\(',bc))
#base = os.path.splitext(lisp.buffer_name())[0]
base = lisp.buffer_name()[:-4]
plt_count_before = len(glob.glob(base + "*.png"))
fs = glob.glob(base + '*.png')
if len(fs)==0:
plt_count_before = 0
else:
plt_count_before =int(fs[-1][-6:-4])
f = '%s_%s.png' % (base, two_digit(plt_count_before+1))
rpl = "plt.savefig('%s')" % f
show_replaced = True if "plt.show()" in content else False
Expand Down
7 changes: 6 additions & 1 deletion ipython-tex.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ def run_py_code():
#plt_count_before = len(re.findall('plt\.savefig\(',bc))
#base = os.path.splitext(lisp.buffer_name())[0]
base = lisp.buffer_name()[:-4]
plt_count_before = len(glob.glob(base + "*.png"))
##plt_count_before = len(glob.glob(base + "*.png"))
fs = glob.glob(base + '*.png')
if len(fs)==0:
plt_count_before = 0
else:
plt_count_before =int(fs[-1][-6:-4])
f = '%s_%s.png' % (base, two_digit(plt_count_before+1))
rpl = "plt.savefig('%s')" % f
show_replaced = True if "plt.show()" in content else False
Expand Down

0 comments on commit bf5195c

Please sign in to comment.