diff options
| author | Fabián Ezequiel Gallina | 2014-12-27 03:38:32 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2014-12-27 03:38:32 -0300 |
| commit | 800260c4eb1e0ce2cc0a9a172c99f17ff47e0a6a (patch) | |
| tree | 7c0a212386404785818125149fedbab761d2b7e9 /lisp/progmodes/python.el | |
| parent | ed65b91571572b73a5c0f8834f94f670390247bd (diff) | |
| download | emacs-800260c4eb1e0ce2cc0a9a172c99f17ff47e0a6a.tar.gz emacs-800260c4eb1e0ce2cc0a9a172c99f17ff47e0a6a.zip | |
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.
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 8bbbd69095c..d9422e5b6c0 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -2620,35 +2620,33 @@ When argument ARG is non-nil do not include decorators." | |||
| 2620 | delete) | 2620 | delete) |
| 2621 | "Send FILE-NAME to inferior Python PROCESS. | 2621 | "Send FILE-NAME to inferior Python PROCESS. |
| 2622 | If TEMP-FILE-NAME is passed then that file is used for processing | 2622 | If TEMP-FILE-NAME is passed then that file is used for processing |
| 2623 | instead, while internally the shell will continue to use FILE-NAME. | 2623 | instead, while internally the shell will continue to use |
| 2624 | If DELETE is non-nil, delete the file afterwards." | 2624 | FILE-NAME. If TEMP-FILE-NAME and DELETE are non-nil, then |
| 2625 | TEMP-FILE-NAME is deleted after evaluation is performed." | ||
| 2625 | (interactive "fFile to send: ") | 2626 | (interactive "fFile to send: ") |
| 2626 | (let* ((process (or process (python-shell-get-or-create-process))) | 2627 | (let* ((process (or process (python-shell-get-or-create-process))) |
| 2627 | (encoding (with-temp-buffer | 2628 | (encoding (with-temp-buffer |
| 2628 | (insert-file-contents | 2629 | (insert-file-contents |
| 2629 | (or temp-file-name file-name)) | 2630 | (or temp-file-name file-name)) |
| 2630 | (python-info-encoding))) | 2631 | (python-info-encoding))) |
| 2632 | (file-name (expand-file-name | ||
| 2633 | (or (file-remote-p file-name 'localname) | ||
| 2634 | file-name))) | ||
| 2631 | (temp-file-name (when temp-file-name | 2635 | (temp-file-name (when temp-file-name |
| 2632 | (expand-file-name | 2636 | (expand-file-name |
| 2633 | (or (file-remote-p temp-file-name 'localname) | 2637 | (or (file-remote-p temp-file-name 'localname) |
| 2634 | temp-file-name)))) | 2638 | temp-file-name))))) |
| 2635 | (file-name (or (when file-name | ||
| 2636 | (expand-file-name | ||
| 2637 | (or (file-remote-p file-name 'localname) | ||
| 2638 | file-name))) | ||
| 2639 | temp-file-name))) | ||
| 2640 | (when (not file-name) | ||
| 2641 | (error "If FILE-NAME is nil then TEMP-FILE-NAME must be non-nil")) | ||
| 2642 | (python-shell-send-string | 2639 | (python-shell-send-string |
| 2643 | (format | 2640 | (format |
| 2644 | (concat | 2641 | (concat |
| 2645 | "import codecs; __pyfile = codecs.open('''%s''', encoding='''%s''');" | 2642 | "import codecs, os;" |
| 2646 | "exec(compile(__pyfile.read().encode('''%s'''), '''%s''', 'exec'));" | 2643 | "__pyfile = codecs.open('''%s''', encoding='''%s''');" |
| 2647 | "__pyfile.close()%s") | 2644 | "__code = __pyfile.read().encode('''%s''');" |
| 2648 | (or temp-file-name file-name) encoding encoding file-name | 2645 | "__pyfile.close();" |
| 2649 | (if delete (format "; import os; os.remove('''%s''')" | 2646 | (when (and delete temp-file-name) |
| 2650 | (or temp-file-name file-name)) | 2647 | (format "os.remove('''%s''');" temp-file-name)) |
| 2651 | "")) | 2648 | "exec(compile(__code, '''%s''', 'exec'));") |
| 2649 | (or temp-file-name file-name) encoding encoding file-name) | ||
| 2652 | process))) | 2650 | process))) |
| 2653 | 2651 | ||
| 2654 | (defun python-shell-switch-to-shell () | 2652 | (defun python-shell-switch-to-shell () |