python.el: Cleanup temp files even with eval errors.
* lisp/progmodes/python.el (python-shell-send-file): Make file-name mandatory. Fix temp file removal in the majority of cases.
This commit is contained in:
parent
ed65b91571
commit
800260c4eb
2 changed files with 22 additions and 17 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2014-12-27 Fabián Ezequiel Gallina <fgallina@gnu.org>
|
||||||
|
|
||||||
|
python.el: Cleanup temp files even with eval errors.
|
||||||
|
|
||||||
|
* progmodes/python.el (python-shell-send-file): Make file-name
|
||||||
|
mandatory. Fix temp file removal in the majority of cases.
|
||||||
|
|
||||||
2014-12-27 Fabián Ezequiel Gallina <fgallina@gnu.org>
|
2014-12-27 Fabián Ezequiel Gallina <fgallina@gnu.org>
|
||||||
|
|
||||||
python.el: Handle file encoding for shell.
|
python.el: Handle file encoding for shell.
|
||||||
|
|
|
@ -2620,35 +2620,33 @@ When argument ARG is non-nil do not include decorators."
|
||||||
delete)
|
delete)
|
||||||
"Send FILE-NAME to inferior Python PROCESS.
|
"Send FILE-NAME to inferior Python PROCESS.
|
||||||
If TEMP-FILE-NAME is passed then that file is used for processing
|
If TEMP-FILE-NAME is passed then that file is used for processing
|
||||||
instead, while internally the shell will continue to use FILE-NAME.
|
instead, while internally the shell will continue to use
|
||||||
If DELETE is non-nil, delete the file afterwards."
|
FILE-NAME. If TEMP-FILE-NAME and DELETE are non-nil, then
|
||||||
|
TEMP-FILE-NAME is deleted after evaluation is performed."
|
||||||
(interactive "fFile to send: ")
|
(interactive "fFile to send: ")
|
||||||
(let* ((process (or process (python-shell-get-or-create-process)))
|
(let* ((process (or process (python-shell-get-or-create-process)))
|
||||||
(encoding (with-temp-buffer
|
(encoding (with-temp-buffer
|
||||||
(insert-file-contents
|
(insert-file-contents
|
||||||
(or temp-file-name file-name))
|
(or temp-file-name file-name))
|
||||||
(python-info-encoding)))
|
(python-info-encoding)))
|
||||||
|
(file-name (expand-file-name
|
||||||
|
(or (file-remote-p file-name 'localname)
|
||||||
|
file-name)))
|
||||||
(temp-file-name (when temp-file-name
|
(temp-file-name (when temp-file-name
|
||||||
(expand-file-name
|
(expand-file-name
|
||||||
(or (file-remote-p temp-file-name 'localname)
|
(or (file-remote-p temp-file-name 'localname)
|
||||||
temp-file-name))))
|
temp-file-name)))))
|
||||||
(file-name (or (when file-name
|
|
||||||
(expand-file-name
|
|
||||||
(or (file-remote-p file-name 'localname)
|
|
||||||
file-name)))
|
|
||||||
temp-file-name)))
|
|
||||||
(when (not file-name)
|
|
||||||
(error "If FILE-NAME is nil then TEMP-FILE-NAME must be non-nil"))
|
|
||||||
(python-shell-send-string
|
(python-shell-send-string
|
||||||
(format
|
(format
|
||||||
(concat
|
(concat
|
||||||
"import codecs; __pyfile = codecs.open('''%s''', encoding='''%s''');"
|
"import codecs, os;"
|
||||||
"exec(compile(__pyfile.read().encode('''%s'''), '''%s''', 'exec'));"
|
"__pyfile = codecs.open('''%s''', encoding='''%s''');"
|
||||||
"__pyfile.close()%s")
|
"__code = __pyfile.read().encode('''%s''');"
|
||||||
(or temp-file-name file-name) encoding encoding file-name
|
"__pyfile.close();"
|
||||||
(if delete (format "; import os; os.remove('''%s''')"
|
(when (and delete temp-file-name)
|
||||||
(or temp-file-name file-name))
|
(format "os.remove('''%s''');" temp-file-name))
|
||||||
""))
|
"exec(compile(__code, '''%s''', 'exec'));")
|
||||||
|
(or temp-file-name file-name) encoding encoding file-name)
|
||||||
process)))
|
process)))
|
||||||
|
|
||||||
(defun python-shell-switch-to-shell ()
|
(defun python-shell-switch-to-shell ()
|
||||||
|
|
Loading…
Add table
Reference in a new issue