aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2013-11-23 11:39:50 -0800
committerGlenn Morris2013-11-23 11:39:50 -0800
commit3cfb6af3af535146d22ef103f8472a08edd8c215 (patch)
tree42c656cf15d1d900ce9453096d4fcacd6d9d5a66
parentf6083c67c54ba1a4951ecf7b3b242d097de8bff2 (diff)
downloademacs-3cfb6af3af535146d22ef103f8472a08edd8c215.tar.gz
emacs-3cfb6af3af535146d22ef103f8472a08edd8c215.zip
* python.el (python-shell-send-file): Add option to delete file when done.
(python-shell-send-string, python-shell-send-region): Use it. Fixes: debbugs:15647
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/progmodes/python.el16
2 files changed, 16 insertions, 6 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ede723e6d6b..8b67c3ede81 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12013-11-23 Glenn Morris <rgm@gnu.org>
2
3 * progmodes/python.el (python-shell-send-file):
4 Add option to delete file when done. (Bug#15647)
5 (python-shell-send-string, python-shell-send-region): Use it.
6
12013-11-23 Ivan Shmakov <ivan@siamics.net> (tiny change) 72013-11-23 Ivan Shmakov <ivan@siamics.net> (tiny change)
2 8
3 * vc/diff-mode.el (diff-mode): Only allow diff-default-read-only 9 * vc/diff-mode.el (diff-mode): Only allow diff-default-read-only
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 7a90f0bb5ee..8dc345ca1c1 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -2056,7 +2056,7 @@ When MSG is non-nil messages the first line of STRING."
2056 (let ((process (or process (python-shell-get-or-create-process)))) 2056 (let ((process (or process (python-shell-get-or-create-process))))
2057 (if (string-match ".\n+." string) ;Multiline. 2057 (if (string-match ".\n+." string) ;Multiline.
2058 (let* ((temp-file-name (python-shell--save-temp-file string))) 2058 (let* ((temp-file-name (python-shell--save-temp-file string)))
2059 (python-shell-send-file temp-file-name process temp-file-name)) 2059 (python-shell-send-file temp-file-name process temp-file-name t))
2060 (comint-send-string process string) 2060 (comint-send-string process string)
2061 (when (or (not (string-match "\n\\'" string)) 2061 (when (or (not (string-match "\n\\'" string))
2062 (string-match "\n[ \t].*\n?\\'" string)) 2062 (string-match "\n[ \t].*\n?\\'" string))
@@ -2212,7 +2212,7 @@ the python shell:
2212 (message "Sent: %s..." (match-string 1 string)) 2212 (message "Sent: %s..." (match-string 1 string))
2213 (let* ((temp-file-name (python-shell--save-temp-file string)) 2213 (let* ((temp-file-name (python-shell--save-temp-file string))
2214 (file-name (or (buffer-file-name) temp-file-name))) 2214 (file-name (or (buffer-file-name) temp-file-name)))
2215 (python-shell-send-file file-name process temp-file-name) 2215 (python-shell-send-file file-name process temp-file-name t)
2216 (unless python--use-fake-loc 2216 (unless python--use-fake-loc
2217 (with-current-buffer (process-buffer process) 2217 (with-current-buffer (process-buffer process)
2218 (compilation-fake-loc (copy-marker start) temp-file-name 2218 (compilation-fake-loc (copy-marker start) temp-file-name
@@ -2249,11 +2249,12 @@ When argument ARG is non-nil do not include decorators."
2249 (end-of-line 1)) 2249 (end-of-line 1))
2250 (point-marker))))) 2250 (point-marker)))))
2251 2251
2252(defun python-shell-send-file (file-name &optional process temp-file-name) 2252(defun python-shell-send-file (file-name &optional process temp-file-name
2253 delete)
2253 "Send FILE-NAME to inferior Python PROCESS. 2254 "Send FILE-NAME to inferior Python PROCESS.
2254If TEMP-FILE-NAME is passed then that file is used for processing 2255If TEMP-FILE-NAME is passed then that file is used for processing
2255instead, while internally the shell will continue to use 2256instead, while internally the shell will continue to use
2256FILE-NAME." 2257FILE-NAME. If DELETE is non-nil, delete the file afterwards."
2257 (interactive "fFile to send: ") 2258 (interactive "fFile to send: ")
2258 (let* ((process (or process (python-shell-get-or-create-process))) 2259 (let* ((process (or process (python-shell-get-or-create-process)))
2259 (temp-file-name (when temp-file-name 2260 (temp-file-name (when temp-file-name
@@ -2271,8 +2272,11 @@ FILE-NAME."
2271 (format 2272 (format
2272 (concat "__pyfile = open('''%s''');" 2273 (concat "__pyfile = open('''%s''');"
2273 "exec(compile(__pyfile.read(), '''%s''', 'exec'));" 2274 "exec(compile(__pyfile.read(), '''%s''', 'exec'));"
2274 "__pyfile.close()") 2275 "__pyfile.close()%s")
2275 (or temp-file-name file-name) file-name) 2276 (or temp-file-name file-name) file-name
2277 (if delete (format "; import os; os.remove('''%s''')"
2278 (or temp-file-name file-name))
2279 ""))
2276 process))) 2280 process)))
2277 2281
2278(defun python-shell-switch-to-shell () 2282(defun python-shell-switch-to-shell ()